TTL systems in DSLRs use a preflash just before the mirror begins to move out of the way to measure the reflectivity of the subject and calculate the amount of flash needed for a proper exposure. Some systems even use distance data from the lens to determine what will be exposed properly based on the distance to the in-focus subject.
How much flash the camera applies is influenced by several variables. Which mode you are shooting in (Auto, P, Tv, Av, M, etc), the overall EV and dynamic range of the scene, and which metering and focus modes you have selected can all factor into the calculation. If you are shooting in Av mode with a Canon in low light environments, for example, the camera will assume you want to use slow sync to allow proper exposure of the background and will power the flash to provide fill light based on the distance and reflectivity of your subject. The maximum (longest) shutter speed allowed can be modified using the camera's custom function menu.
In most film and digital SLRs, the light sensor(s) for exposure metering are incorporated into the pentaprism or pentamirror, the mechanism by which a SLR allows the viewfinder to see directly through the lens. As the mirror is flipped up, no light can reach there during exposure, therefore, these light sensors can be used for ambient light TTL metering only. In newer SLRs as well as in almost all DSLRs, they can also be utilized for preflash TTL metering, where the metering is carried out before the mirror flips up using a preflash and the necessary amount of flash light is precalculated and then applied during the exposure without any real-time feedback.
Some film bodies that were TTL capable metered using light reflected off of the film in real time during the exposure, but this proved to be unreliable with the different reflectivity of digital sensors. Some even earlier "automatic" strobes had sensors built into the flash itself to measure the amount of light, but the variables of lens shape and size, filters over the lens but not the flash, as well as angle of view, made this less accurate than the more current TTL systems.
When used with first curtain sync, the time between the preflash and the main flash during exposure is so short that most people don't even notice that the flash has fired more than once. Consider that the fastest camera bodies are capable of focusing, metering, moving the mirror, stopping down the aperture, opening and closing the shutter, moving the mirror back down, and opening the aperture back up at 10+ frames per second.
Here is a diagram of how the preflash system works with Canon's E-TTL when using multiple off camera flashes.