Add a disable button to the Extension management UI.

TEST=Try installing and/or loading some extensions, and toggling between enable and disable in the management UI (chrome://extensions).
BUG=12122

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25659 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 46bce98..d7cb2064 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -220,8 +220,11 @@
     return;
   }
 
+  // Remember that we enabled it, unless it's temporary.
+  if (extension->location() != Extension::LOAD)
+    extension_prefs_->SetExtensionState(extension, Extension::ENABLED);
+
   // Move it over to the enabled list.
-  extension_prefs_->SetExtensionState(extension, Extension::ENABLED);
   extensions_.push_back(extension);
   ExtensionList::iterator iter = std::find(disabled_extensions_.begin(),
                                            disabled_extensions_.end(),
@@ -237,6 +240,33 @@
       Details<Extension>(extension));
 }
 
+void ExtensionsService::DisableExtension(const std::string& extension_id) {
+  Extension* extension = GetExtensionByIdInternal(extension_id, true, false);
+  if (!extension) {
+    NOTREACHED() << "Trying to disable an extension that isn't enabled.";
+    return;
+  }
+
+  // Remember that we disabled it, unless it's temporary.
+  if (extension->location() != Extension::LOAD)
+    extension_prefs_->SetExtensionState(extension, Extension::DISABLED);
+
+  // Move it over to the disabled list.
+  disabled_extensions_.push_back(extension);
+  ExtensionList::iterator iter = std::find(extensions_.begin(),
+                                           extensions_.end(),
+                                           extension);
+  extensions_.erase(iter);
+
+  ExtensionDOMUI::UnregisterChromeURLOverrides(profile_,
+      extension->GetChromeURLOverrides());
+
+  NotificationService::current()->Notify(
+      NotificationType::EXTENSION_UNLOADED,
+      Source<ExtensionsService>(this),
+      Details<Extension>(extension));
+}
+
 void ExtensionsService::LoadExtension(const FilePath& extension_path) {
   backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(),
       &ExtensionsServiceBackend::LoadSingleExtension,