  We consider a simple gravitational-heating mechanism for the long-term
quenching of cooling flows and star formation in massive dark-matter haloes
hosting ellipticals and clusters. The virial shock heating in haloes >10^12 Mo
triggers quenching in 10^12-13 Mo haloes (Birnboim, Dekel & Neistein 2007). We
show that the long-term quenching in haloes >Mmin~7x10^12 Mo could be due to
the gravitational energy of cosmological accretion delivered to the inner-halo
hot gas by cold flows via ram-pressure drag and local shocks. Mmin is obtained
by comparing the gravitational power of infall into the potential well with the
overall radiative cooling rate. The heating wins if the gas inner density cusp
is not steeper than r^-0.5 and if the masses in the cold and hot phases are
comparable. The effect is stronger at higher redshifts, making the maintenance
easier also at later times. Clumps >10^5 Mo penetrate to the inner halo with
sufficient kinetic energy before they disintegrate, but they have to be <10^8
Mo for the drag to do enough work in a Hubble time. Pressure confined ~10^4K
clumps are stable against their own gravity and remain gaseous once below the
Bonnor-Ebert mass ~10^8 Mo. They are also immune to tidal disruption. Clumps in
the desired mass range could emerge by thermal instability in the outer halo if
the conductivity is not too high. Alternatively, such clumps may be embedded in
dark-matter subhaloes if the ionizing flux is ineffective, but they separate
from their subhaloes by ram pressure before entering the inner halo. Heating by
dynamical friction becomes dominant for massive satellites, which can
contribute up to one third of the total gravitational heating. We conclude that
gravitational heating by cosmological accretion is a viable alternative to AGN
feedback as a long-term quenching mechanism.
