You are taking an AC signal from the wall and then as you say, the transformer, recitifier and capacitors are bringing it down to a lower DC voltage. From there, most charging circuits are either linear regulator type chargers or switch mode power supply type regulators (both of those are advanced type links, but just there to see they both exist). They are basically normal DC/DC power converters with some kind of monitoring circuit inside. These two components fulfill the needs you list in number 1 and 2. To learn more about how they work, I'd check out Dave's explanation of linear and switch mode power supplies.
If you're looking to build your own eventually, you'll need to figure out how to do the monitoring with a micro or otherwise and then control some kind of DC/DC power converter. Good luck!
I believe the answer can only be empirical, not definitive.
To examine some of the figures mentioned:
there is a 20% inefficiency (which I do not know if it is true for most portable charger)
A portable charger that is itself charged from USB (5 Volts) would need a boost converter to be able to supply 5 volts at its output. Boost converters commonly mention efficiency of 65 to 85%. TI's TPS61030, TPS61031 and TPS61032 state 96%, and Maxim's MAX8815A states 97% efficiency.
These figures do not account for possible efficiency loss due to external components (ESR of capacitors for instance) or temperature variation. Thus, treat that "20%" number as indicative at best.
your phone needs power for stand-by, so in my experience, you'll have just 65% capacity.
That would depend on whether the phone is kept powered on while charging, what power intensive tasks (e.g. WiFi, social media polling software) are running on the phone, and even the current draw of the phone in the nominal "powered off" state - Some smartphones do not actually power off completely unless the battery is pulled out.
Thus, that 65% number is also indicative at best, though varying it somewhat is within the user's control.
by industrial standards for batteries is +/- 20% tolerance admitted with capacity.
That number would be defined in the datasheet of the specific battery in question. It would also vary widely by age / charge cycle history of the battery, temperature, contact oxidation and possibly several other factors.
So, while the number is a reasonable guesstimate, it is not definitive.
Note that this last figure is applicable to both, the cellphone battery and the portable charger battery.
So, can one use the magical value 45% as a gauge for portable battery charger?
Clearly not. The only numbers that can be used, even as a rule of thumb, are those empirically measured for your particular situation and use pattern. Even so, the percentage will change widely over charge cycles, season and time of day (temperature factors).
Best Answer
There's a charger controller IC inside the phone/laptop/whatever that regulates the charge current or voltage to ensure safe charging according to the battery's specs.
There are typically voltage and current control loops in the charger, and the mode is selected based on the state of charge of the battery, the temperature, etc. They can be linear or switch mode power control schemes.
For example: bq24195 Charger IC
Here's a link to some information on how it all works: Charging and gauging