AGN-controlled cooling in elliptical galaxies