  We construct an analytic model for the rate of gas accretion onto a planet
embedded in a protoplanetary disk as a function of planetary mass, disk
viscosity, disk scale height, and unperturbed surface density in order to study
the long-term accretion and final masses of gas giant planets. We first derive
an analytical formula for surface density profile near the planetary orbit from
considerations of the balance of force and the dynamical stability. Using it in
the empirical formula linking surface density with gas accretion rate that is
derived based on hydrodynamic simulations of Tanigawa and Watanabe (2002, ApJ
586, 506), we then simulate the mass evolution of gas giant planets in
viscously-evolving disks. We finally determine the final mass as a function of
semi-major axis of the planet. We find that the disk can be divided into three
regions characterized by different processes by which the final mass is
determined. In the inner region, the planet grows quickly and forms a deep gap
to suppress the growth by itself before disk dissipation. The final mass of the
planet in this region is found to increase with the semi-major axis in a
similar way to the mass given by the viscous condition for gap opening, but the
former is larger by a factor of approximately 10 than the latter. In the
intermediate region, viscous diffusion of the disk gas limits the gas accretion
before the planet form a deep gap. The final mass can be up to the disk mass,
when disk viscous evolution occurs faster than disk evaporation. In the outer
region, planets capture only tiny amounts of gas within the lifetime of the
disk to form Neptune-like planets. We derive analytic formulae for the final
masses in the different regions and the locations of the boundaries, which are
helpful to gain a systematic understanding of the masses of gas giant planets.
