Change the way lazy background pages shutdown.

The browser process now keeps a generic count of activity from the lazy background page. This will be used for all types of activity, such as outstanding events, resource requests, and API calls.

BUG=81752
TEST=no

Review URL: https://chromiumcodereview.appspot.com/9447042

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123821 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc
index e16c810fe..9191e2d 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.cc
+++ b/chrome/browser/extensions/extension_function_dispatcher.cc
@@ -728,6 +728,19 @@
     function->OnQuotaExceeded();
     LogFailure(extension, params.name, kQuotaExceeded);
   }
+
+  // We only adjust the keepalive count for UIThreadExtensionFunction for
+  // now, largely for simplicity's sake. This is OK because currently, only
+  // the webRequest API uses IOThreadExtensionFunction, and that API is not
+  // compatible with lazy background pages.
+  profile()->GetExtensionProcessManager()->IncrementLazyKeepaliveCount(
+      extension);
+}
+
+void ExtensionFunctionDispatcher::OnExtensionFunctionCompleted(
+    const Extension* extension) {
+  profile()->GetExtensionProcessManager()->DecrementLazyKeepaliveCount(
+      extension);
 }
 
 // static