Kill Extension::RuntimeData and move its guts to ExtensionsService.

ImageCache remains on Extension, on the expectation that it will eventually be
loaded at startup.

BUG=56558
TEST=no functional change

Review URL: http://codereview.chromium.org/4132005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64973 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 734bdef..ea025fb 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -150,6 +150,15 @@
       enable_incognito_on_install(false),
       install_source(Extension::INVALID) {}
 
+
+ExtensionsService::ExtensionRuntimeData::ExtensionRuntimeData()
+    : background_page_ready(false),
+      being_upgraded(false) {
+}
+
+ExtensionsService::ExtensionRuntimeData::~ExtensionRuntimeData() {
+}
+
 // ExtensionsService.
 
 const char* ExtensionsService::kInstallDirectoryName = "Extensions";
@@ -1386,6 +1395,9 @@
   // Clean up if the extension is meant to be enabled after a reload.
   disabled_extension_paths_.erase(extension->id());
 
+  // Clean up runtime data.
+  extension_runtime_data_.erase(extension_id);
+
   ExtensionDOMUI::UnregisterChromeURLOverrides(profile_,
       extension->GetChromeURLOverrides());
 
@@ -1413,6 +1425,7 @@
 void ExtensionsService::UnloadAllExtensions() {
   extensions_.clear();
   disabled_extensions_.clear();
+  extension_runtime_data_.clear();
 
   // TODO(erikkay) should there be a notification for this?  We can't use
   // EXTENSION_UNLOADED since that implies that the extension has been disabled
@@ -1485,8 +1498,8 @@
       // Extensions get upgraded if silent upgrades are allowed, otherwise
       // they get disabled.
       if (allow_silent_upgrade) {
-        old->set_being_upgraded(true);
-        extension->set_being_upgraded(true);
+        SetBeingUpgraded(old, true);
+        SetBeingUpgraded(extension, true);
       }
 
       // To upgrade an extension in place, unload the old one and
@@ -1524,7 +1537,7 @@
     }
   }
 
-  extension->set_being_upgraded(false);
+  SetBeingUpgraded(extension, false);
 
   UpdateActiveExtensionsInCrashReporter();
 
@@ -1904,3 +1917,26 @@
 
   return result;
 }
+
+bool ExtensionsService::IsBackgroundPageReady(const Extension* extension) {
+  return (extension->background_url().is_empty() ||
+          extension_runtime_data_[extension->id()].background_page_ready);
+}
+
+void ExtensionsService::SetBackgroundPageReady(const Extension* extension) {
+  DCHECK(!extension->background_url().is_empty());
+  extension_runtime_data_[extension->id()].background_page_ready = true;
+  NotificationService::current()->Notify(
+      NotificationType::EXTENSION_BACKGROUND_PAGE_READY,
+      Source<const Extension>(extension),
+      NotificationService::NoDetails());
+}
+
+bool ExtensionsService::IsBeingUpgraded(const Extension* extension) {
+  return extension_runtime_data_[extension->id()].being_upgraded;
+}
+
+void ExtensionsService::SetBeingUpgraded(const Extension* extension,
+                                         bool value) {
+  extension_runtime_data_[extension->id()].being_upgraded = value;
+}