From c3cfb01fb895eb5a6063193456e51c2bb71a1e29 Mon Sep 17 00:00:00 2001
From: "akalin@chromium.org"
 <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Wed, 6 Apr 2011 22:07:35 +0000
Subject: Refactor ExtensionService/ExtensionServiceInterface to be more
 testable

In particular:
- Add various status accessors to ExtensionServiceInterface (e.g.,
  IsExtensionEnabled())
- Convert IsIncognitoEnabled() to take an ID instead of an Extension*.
- Add CheckForUpdates() to ExtensionServiceInterface.
- Remove various unneeded accessors from ExtensionServiceInterface.

Rewrite some sync utility functions to take advantage of the new
interface (although it will be rewritten more in a future CL).

BUG=77995
TEST=

Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=80539

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80705 0039d316-1c4b-4281-b951-d872f2087c98
---
 .../autocomplete/autocomplete_popup_model.cc       |   3 +-
 chrome/browser/autocomplete/keyword_provider.cc    |   5 +-
 chrome/browser/automation/automation_provider.cc   |   2 +-
 chrome/browser/extensions/extension_browsertest.cc |   2 +-
 .../browser/extensions/extension_event_router.cc   |   5 +-
 chrome/browser/extensions/extension_module.cc      |   4 +-
 .../extensions/extension_process_manager.cc        |   2 +-
 chrome/browser/extensions/extension_service.cc     | 103 +++++++++++++--------
 chrome/browser/extensions/extension_service.h      |  35 ++++---
 .../extensions/extension_service_unittest.cc       |  10 +-
 .../browser/extensions/extension_toolbar_model.cc  |   4 +-
 chrome/browser/extensions/extension_updater.cc     |  50 +++++-----
 chrome/browser/extensions/extension_updater.h      |  12 ++-
 .../extensions/extension_updater_unittest.cc       | 100 +++++++++++++-------
 chrome/browser/extensions/extension_web_ui.cc      |   2 +-
 chrome/browser/extensions/extensions_ui.cc         |   5 +-
 .../extensions/pending_extension_manager.cc        |   2 +-
 chrome/browser/extensions/user_script_master.cc    |   4 +-
 chrome/browser/sync/glue/extension_sync.cc         |  28 ++----
 chrome/browser/sync/glue/extension_util.cc         |  21 ++---
 chrome/browser/sync/glue/extension_util.h          |   2 +-
 chrome/browser/sync/glue/theme_util.cc             |  19 +---
 .../cocoa/extensions/browser_actions_controller.mm |   5 +-
 .../browser/ui/gtk/browser_actions_toolbar_gtk.cc  |   2 +-
 .../browser/ui/views/browser_actions_container.cc  |   5 +-
 25 files changed, 237 insertions(+), 195 deletions(-)

(limited to 'chrome')

diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc
index a48aae60a..baa8928 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_model.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc
@@ -166,7 +166,8 @@ bool AutocompletePopupModel::GetKeywordForText(const string16& text,
         GetExtensionById(template_url->GetExtensionId(), false);
     if (!extension ||
         (profile_->IsOffTheRecord() &&
-         !profile_->GetExtensionService()->IsIncognitoEnabled(extension)))
+         !profile_->GetExtensionService()->
+             IsIncognitoEnabled(extension->id())))
       return false;
   }
 
diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc
index 99ea49c..fab254f 100644
--- a/chrome/browser/autocomplete/keyword_provider.cc
+++ b/chrome/browser/autocomplete/keyword_provider.cc
@@ -190,8 +190,9 @@ void KeywordProvider::Start(const AutocompleteInput& input,
       ExtensionService* service = profile_->GetExtensionService();
       const Extension* extension = service->GetExtensionById(
           template_url->GetExtensionId(), false);
-      bool enabled = extension && (!profile_->IsOffTheRecord() ||
-                                   service->IsIncognitoEnabled(extension));
+      bool enabled =
+          extension && (!profile_->IsOffTheRecord() ||
+                        service->IsIncognitoEnabled(extension->id()));
       if (!enabled) {
         i = keyword_matches.erase(i);
         continue;
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 182d308..72448f0 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -936,7 +936,7 @@ void AutomationProvider::GetExtensionProperty(
             // Skip this extension if we are in incognito mode
             // and it is not incognito-enabled.
             if (profile_->IsOffTheRecord() &&
-                !service->IsIncognitoEnabled(*iter))
+                !service->IsIncognitoEnabled((*iter)->id()))
               continue;
             if (*iter == extension) {
               found_index = index;
diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc
index bbadbfa4..670789a 100644
--- a/chrome/browser/extensions/extension_browsertest.cc
+++ b/chrome/browser/extensions/extension_browsertest.cc
@@ -88,7 +88,7 @@ bool ExtensionBrowserTest::LoadExtensionImpl(const FilePath& path,
   // are set up with the defaults.
   service->extension_prefs()->OnExtensionInstalled(
       extension, Extension::ENABLED, false);
-  service->SetIsIncognitoEnabled(extension, incognito_enabled);
+  service->SetIsIncognitoEnabled(extension->id(), incognito_enabled);
   service->SetAllowFileAccess(extension, fileaccess_enabled);
 
   return WaitForExtensionHostsToLoad();
diff --git a/chrome/browser/extensions/extension_event_router.cc b/chrome/browser/extensions/extension_event_router.cc
index 257a7f2..a86bf1c 100644
--- a/chrome/browser/extensions/extension_event_router.cc
+++ b/chrome/browser/extensions/extension_event_router.cc
@@ -75,8 +75,9 @@ bool ExtensionEventRouter::CanCrossIncognito(Profile* profile,
   // We allow the extension to see events and data from another profile iff it
   // uses "spanning" behavior and it has incognito access. "split" mode
   // extensions only see events for a matching profile.
-  return (profile->GetExtensionService()->IsIncognitoEnabled(extension) &&
-          !extension->incognito_split_mode());
+  return
+      (profile->GetExtensionService()->IsIncognitoEnabled(extension->id()) &&
+       !extension->incognito_split_mode());
 }
 
 ExtensionEventRouter::ExtensionEventRouter(Profile* profile)
diff --git a/chrome/browser/extensions/extension_module.cc b/chrome/browser/extensions/extension_module.cc
index bb13067..a1c884b 100644
--- a/chrome/browser/extensions/extension_module.cc
+++ b/chrome/browser/extensions/extension_module.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -27,7 +27,7 @@ bool IsAllowedIncognitoAccessFunction::RunImpl() {
   const Extension* extension = GetExtension();
 
   result_.reset(Value::CreateBooleanValue(
-        ext_service->IsIncognitoEnabled(extension)));
+      ext_service->IsIncognitoEnabled(extension->id())));
   return true;
 }
 
diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc
index 8ff58e6f..a9a7e81 100644
--- a/chrome/browser/extensions/extension_process_manager.cc
+++ b/chrome/browser/extensions/extension_process_manager.cc
@@ -439,7 +439,7 @@ bool IncognitoExtensionProcessManager::IsIncognitoEnabled(
     const Extension* extension) {
   ExtensionService* service =
       browsing_instance_->profile()->GetExtensionService();
-  return service && service->IsIncognitoEnabled(extension);
+  return service && service->IsIncognitoEnabled(extension->id());
 }
 
 void IncognitoExtensionProcessManager::Observe(
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index a45e2bb..361e165 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -428,7 +428,9 @@ ExtensionService::ExtensionService(Profile* profile,
           &update_frequency);
     }
     updater_ = new ExtensionUpdater(this,
+                                    extension_prefs,
                                     profile->GetPrefs(),
+                                    profile,
                                     update_frequency);
   }
 
@@ -673,6 +675,21 @@ void ExtensionService::ClearExtensionData(const GURL& extension_url) {
   deleter->StartDeleting();
 }
 
+bool ExtensionService::IsExtensionEnabled(
+    const std::string& extension_id) const {
+  // TODO(akalin): GetExtensionState() isn't very safe as it returns
+  // Extension::ENABLED by default; either change it to return
+  // something else by default or create a separate function that does
+  // so.
+  return
+      extension_prefs_->GetExtensionState(extension_id) == Extension::ENABLED;
+}
+
+bool ExtensionService::IsExternalExtensionUninstalled(
+    const std::string& extension_id) const {
+  return extension_prefs_->IsExternalExtensionUninstalled(extension_id);
+}
+
 void ExtensionService::EnableExtension(const std::string& extension_id) {
   CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 
@@ -1089,10 +1106,6 @@ ExtensionPrefs* ExtensionService::extension_prefs() {
   return extension_prefs_;
 }
 
-const ExtensionPrefs& ExtensionService::const_extension_prefs() const {
-  return *extension_prefs_;
-}
-
 ExtensionUpdater* ExtensionService::updater() {
   return updater_.get();
 }
@@ -1113,30 +1126,44 @@ void ExtensionService::CheckAdminBlacklist() {
     UnloadExtension(to_be_removed[i], UnloadedExtensionInfo::DISABLE);
 }
 
-bool ExtensionService::IsIncognitoEnabled(const Extension* extension) {
-  // If this is a component extension we always allow it to work in incognito
-  // mode.
-  if (extension->location() == Extension::COMPONENT)
+void ExtensionService::CheckForUpdates() {
+  if (updater()) {
+    updater()->CheckNow();
+  } else {
+    LOG(WARNING) << "CheckForUpdates() called with auto-update turned off";
+  }
+}
+
+bool ExtensionService::IsIncognitoEnabled(
+    const std::string& extension_id) const {
+  // If this is an existing component extension we always allow it to
+  // work in incognito mode.
+  const Extension* extension = GetExtensionById(extension_id, true);
+  if (extension && extension->location() == Extension::COMPONENT)
     return true;
 
   // Check the prefs.
-  return extension_prefs_->IsIncognitoEnabled(extension->id());
+  return extension_prefs_->IsIncognitoEnabled(extension_id);
 }
 
-void ExtensionService::SetIsIncognitoEnabled(const Extension* extension,
-                                              bool enabled) {
+void ExtensionService::SetIsIncognitoEnabled(
+    const std::string& extension_id, bool enabled) {
+  const Extension* extension = GetExtensionById(extension_id, false);
+  if (extension && extension->location() == Extension::COMPONENT) {
+    // This shouldn't be called for component extensions.
+    NOTREACHED();
+    return;
+  }
+
   // Broadcast unloaded and loaded events to update browser state. Only bother
   // if the value changed and the extension is actually enabled, since there is
   // no UI otherwise.
-  bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension->id());
+  bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id);
   if (enabled == old_enabled)
     return;
 
-  extension_prefs_->SetIsIncognitoEnabled(extension->id(), enabled);
-
-  bool extension_is_enabled = std::find(extensions_.begin(), extensions_.end(),
-                                        extension) != extensions_.end();
-  if (extension_is_enabled) {
+  extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled);
+  if (extension) {
     NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::DISABLE);
     NotifyExtensionLoaded(extension);
   }
@@ -1146,7 +1173,8 @@ bool ExtensionService::CanCrossIncognito(const Extension* extension) {
   // We allow the extension to see events and data from another profile iff it
   // uses "spanning" behavior and it has incognito access. "split" mode
   // extensions only see events for a matching profile.
-  return IsIncognitoEnabled(extension) && !extension->incognito_split_mode();
+  return IsIncognitoEnabled(extension->id()) &&
+      !extension->incognito_split_mode();
 }
 
 bool ExtensionService::AllowFileAccess(const Extension* extension) {
@@ -1516,18 +1544,18 @@ void ExtensionService::OnExtensionInstalled(const Extension* extension) {
 
   // Ensure extension is deleted unless we transfer ownership.
   scoped_refptr<const Extension> scoped_extension(extension);
-  Extension::State initial_state = Extension::DISABLED;
+  const std::string& id = extension->id();
+  bool initial_enable = false;
   bool initial_enable_incognito = false;
 
   PendingExtensionInfo pending_extension_info;
-  if (pending_extension_manager()->GetById(extension->id(),
-                                           &pending_extension_info)) {
-    pending_extension_manager()->Remove(extension->id());
+  if (pending_extension_manager()->GetById(id, &pending_extension_info)) {
+    pending_extension_manager()->Remove(id);
 
     if (!pending_extension_info.ShouldAllowInstall(*extension)) {
       LOG(WARNING)
           << "ShouldAllowInstall() returned false for "
-          << extension->id() << " of type " << extension->GetType()
+          << id << " of type " << extension->GetType()
           << " and update URL " << extension->update_url().spec()
           << "; not installing";
 
@@ -1547,38 +1575,35 @@ void ExtensionService::OnExtensionInstalled(const Extension* extension) {
 
     if (extension->is_theme()) {
       DCHECK(pending_extension_info.enable_on_install());
-      initial_state = Extension::ENABLED;
+      initial_enable = true;
       DCHECK(!pending_extension_info.enable_incognito_on_install());
       initial_enable_incognito = false;
     } else {
-      initial_state =
-          pending_extension_info.enable_on_install() ?
-          Extension::ENABLED : Extension::DISABLED;
+      initial_enable = pending_extension_info.enable_on_install();
       initial_enable_incognito =
           pending_extension_info.enable_incognito_on_install();
     }
   } else {
-    // Make sure we preserve enabled/disabled states.
-    Extension::State existing_state =
-        extension_prefs_->GetExtensionState(extension->id());
-    initial_state =
-        (existing_state == Extension::DISABLED) ?
-        Extension::DISABLED : Extension::ENABLED;
-    initial_enable_incognito =
-        extension_prefs_->IsIncognitoEnabled(extension->id());
+    // We explicitly want to re-enable an uninstalled external
+    // extension; if we're here, that means the user is manually
+    // installing the extension.
+    initial_enable =
+        IsExtensionEnabled(id) || IsExternalExtensionUninstalled(id);
+    initial_enable_incognito = IsIncognitoEnabled(id);
   }
 
   UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
                             extension->GetType(), 100);
   ShownSectionsHandler::OnExtensionInstalled(profile_->GetPrefs(), extension);
   extension_prefs_->OnExtensionInstalled(
-      extension, initial_state, initial_enable_incognito);
+      extension, initial_enable ? Extension::ENABLED : Extension::DISABLED,
+      initial_enable_incognito);
 
   // Unpacked extensions default to allowing file access, but if that has been
   // overridden, don't reset the value.
   if (Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD) &&
-      !extension_prefs_->HasAllowFileAccessSetting(extension->id())) {
-    extension_prefs_->SetAllowFileAccess(extension->id(), true);
+      !extension_prefs_->HasAllowFileAccessSetting(id)) {
+    extension_prefs_->SetAllowFileAccess(id, true);
   }
 
   // If the extension is a theme, tell the profile (and therefore ThemeProvider)
@@ -1597,7 +1622,7 @@ void ExtensionService::OnExtensionInstalled(const Extension* extension) {
 
   if (extension->is_app()) {
     ExtensionIdSet installed_ids = GetAppIds();
-    installed_ids.insert(extension->id());
+    installed_ids.insert(id);
     default_apps_.DidInstallApp(installed_ids);
   }
 
diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h
index a8f55ee..54f70d6 100644
--- a/chrome/browser/extensions/extension_service.h
+++ b/chrome/browser/extensions/extension_service.h
@@ -63,6 +63,9 @@ class ExtensionServiceInterface {
   virtual void UninstallExtension(const std::string& extension_id,
                                   bool external_uninstall) = 0;
 
+  virtual bool IsExtensionEnabled(const std::string& extension_id) const = 0;
+  virtual bool IsExternalExtensionUninstalled(
+      const std::string& extension_id) const = 0;
   virtual void EnableExtension(const std::string& extension_id) = 0;
   virtual void DisableExtension(const std::string& extension_id) = 0;
 
@@ -71,17 +74,11 @@ class ExtensionServiceInterface {
   virtual void CheckAdminBlacklist() = 0;
   virtual bool HasInstalledExtensions() = 0;
 
-  virtual void SetIsIncognitoEnabled(const Extension* extension,
+  virtual bool IsIncognitoEnabled(const std::string& extension_id) const = 0;
+  virtual void SetIsIncognitoEnabled(const std::string& extension_id,
                                      bool enabled) = 0;
 
-  // TODO(skerner): Change to const ExtensionPrefs& extension_prefs() const,
-  // ExtensionPrefs* mutable_extension_prefs().
-  virtual ExtensionPrefs* extension_prefs() = 0;
-  virtual const ExtensionPrefs& const_extension_prefs() const = 0;
-
-  virtual ExtensionUpdater* updater() = 0;
-
-  virtual Profile* profile() = 0;
+  virtual void CheckForUpdates() = 0;
 };
 
 // Manages installed and running Chromium extensions.
@@ -168,8 +165,9 @@ class ExtensionService
   DefaultApps* default_apps() { return &default_apps_; }
 
   // Whether this extension can run in an incognito window.
-  bool IsIncognitoEnabled(const Extension* extension);
-  virtual void SetIsIncognitoEnabled(const Extension* extension, bool enabled);
+  virtual bool IsIncognitoEnabled(const std::string& extension_id) const;
+  virtual void SetIsIncognitoEnabled(const std::string& extension_id,
+                                     bool enabled);
 
   // Returns true if the given extension can see events and data from another
   // sub-profile (incognito to original profile, or vice versa).
@@ -233,6 +231,10 @@ class ExtensionService
   virtual void UninstallExtension(const std::string& extension_id,
                                   bool external_uninstall);
 
+  virtual bool IsExtensionEnabled(const std::string& extension_id) const;
+  virtual bool IsExternalExtensionUninstalled(
+      const std::string& extension_id) const;
+
   // Enable or disable an extension. No action if the extension is already
   // enabled/disabled.
   virtual void EnableExtension(const std::string& extension_id);
@@ -335,6 +337,8 @@ class ExtensionService
   // set of extensions.
   virtual void CheckAdminBlacklist();
 
+  virtual void CheckForUpdates();
+
   void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; }
   bool extensions_enabled() { return extensions_enabled_; }
 
@@ -346,21 +350,22 @@ class ExtensionService
     return show_extensions_prompts_;
   }
 
-  virtual Profile* profile();
+  Profile* profile();
 
   // Profile calls this when it is being destroyed so that we know not to call
   // it.
   void DestroyingProfile();
 
-  virtual ExtensionPrefs* extension_prefs();
-  virtual const ExtensionPrefs& const_extension_prefs() const;
+  // TODO(skerner): Change to const ExtensionPrefs& extension_prefs() const,
+  // ExtensionPrefs* mutable_extension_prefs().
+  ExtensionPrefs* extension_prefs();
 
   // Whether the extension service is ready.
   // TODO(skerner): Get rid of this method.  crbug.com/63756
   bool is_ready() { return ready_; }
 
   // Note that this may return NULL if autoupdate is not turned on.
-  virtual ExtensionUpdater* updater();
+  ExtensionUpdater* updater();
 
   ExtensionToolbarModel* toolbar_model() { return &toolbar_model_; }
 
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index aa64f1e..cae8b1b 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -2024,14 +2024,14 @@ TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) {
   // Disable it and allow it to run in incognito. These settings should carry
   // over to the updated version.
   service_->DisableExtension(good->id());
-  service_->SetIsIncognitoEnabled(good, true);
+  service_->SetIsIncognitoEnabled(good->id(), true);
 
   path = extensions_path.AppendASCII("good2.crx");
   UpdateExtension(good_crx, path, INSTALLED);
   ASSERT_EQ(1u, service_->disabled_extensions()->size());
   const Extension* good2 = service_->disabled_extensions()->at(0);
   ASSERT_EQ("1.0.0.1", good2->version()->GetString());
-  EXPECT_TRUE(service_->IsIncognitoEnabled(good2));
+  EXPECT_TRUE(service_->IsIncognitoEnabled(good2->id()));
 }
 
 // Tests that updating preserves extension location.
@@ -2168,7 +2168,7 @@ TEST_F(ExtensionServiceTest, UpdatePendingExtension) {
   EXPECT_EQ(kGoodInitialState,
             service_->extension_prefs()->GetExtensionState(extension->id()));
   EXPECT_EQ(kGoodInitialIncognitoEnabled,
-            service_->IsIncognitoEnabled(extension));
+            service_->IsIncognitoEnabled(extension->id()));
 }
 
 namespace {
@@ -2200,7 +2200,7 @@ TEST_F(ExtensionServiceTest, UpdatePendingTheme) {
 
   EXPECT_EQ(Extension::ENABLED,
             service_->extension_prefs()->GetExtensionState(extension->id()));
-  EXPECT_FALSE(service_->IsIncognitoEnabled(extension));
+  EXPECT_FALSE(service_->IsIncognitoEnabled(extension->id()));
 }
 
 // Test updating a pending CRX as if the source is an external extension
@@ -2226,7 +2226,7 @@ TEST_F(ExtensionServiceTest, UpdatePendingExternalCrx) {
 
   EXPECT_EQ(Extension::ENABLED,
             service_->extension_prefs()->GetExtensionState(extension->id()));
-  EXPECT_FALSE(service_->IsIncognitoEnabled(extension));
+  EXPECT_FALSE(service_->IsIncognitoEnabled(extension->id()));
 }
 
 // Test updating a pending CRX as if the source is an external extension
diff --git a/chrome/browser/extensions/extension_toolbar_model.cc b/chrome/browser/extensions/extension_toolbar_model.cc
index 11bfeb7..1c3a403 100644
--- a/chrome/browser/extensions/extension_toolbar_model.cc
+++ b/chrome/browser/extensions/extension_toolbar_model.cc
@@ -238,7 +238,7 @@ int ExtensionToolbarModel::IncognitoIndexToOriginal(int incognito_index) {
   int original_index = 0, i = 0;
   for (ExtensionList::iterator iter = begin(); iter != end();
        ++iter, ++original_index) {
-    if (service_->IsIncognitoEnabled(*iter)) {
+    if (service_->IsIncognitoEnabled((*iter)->id())) {
       if (incognito_index == i)
         break;
       ++i;
@@ -253,7 +253,7 @@ int ExtensionToolbarModel::OriginalIndexToIncognito(int original_index) {
        ++iter, ++i) {
     if (original_index == i)
       break;
-    if (service_->IsIncognitoEnabled(*iter))
+    if (service_->IsIncognitoEnabled((*iter)->id()))
       ++incognito_index;
   }
   return incognito_index;
diff --git a/chrome/browser/extensions/extension_updater.cc b/chrome/browser/extensions/extension_updater.cc
index 22af3a1..e14ba2a 100644
--- a/chrome/browser/extensions/extension_updater.cc
+++ b/chrome/browser/extensions/extension_updater.cc
@@ -205,8 +205,11 @@ static int CalculateActivePingDays(const Time& last_active_ping_day,
 }  // namespace
 
 ManifestFetchesBuilder::ManifestFetchesBuilder(
-    ExtensionServiceInterface* service) : service_(service) {
+    ExtensionServiceInterface* service,
+    ExtensionPrefs* prefs)
+    : service_(service), prefs_(prefs) {
   DCHECK(service_);
+  DCHECK(prefs_);
 }
 
 ManifestFetchesBuilder::~ManifestFetchesBuilder() {}
@@ -224,8 +227,7 @@ void ManifestFetchesBuilder::AddExtension(const Extension& extension) {
   // communicate to the the gallery update servers.
   std::string update_url_data;
   if (!extension.UpdatesFromGallery())
-    update_url_data = service_->extension_prefs()->
-        GetUpdateUrlData(extension.id());
+    update_url_data = prefs_->GetUpdateUrlData(extension.id());
 
   AddExtensionData(extension.location(),
                    extension.id(),
@@ -339,11 +341,11 @@ void ManifestFetchesBuilder::AddExtensionData(
       fetches_.find(update_url);
 
   // Find or create a ManifestFetchData to add this extension to.
-  ExtensionPrefs* prefs = service_->extension_prefs();
   ManifestFetchData::PingData ping_data;
-  ping_data.rollcall_days = CalculatePingDays(prefs->LastPingDay(id));
-  ping_data.active_days = CalculateActivePingDays(prefs->LastActivePingDay(id),
-                                                  prefs->GetActiveBit(id));
+  ping_data.rollcall_days = CalculatePingDays(prefs_->LastPingDay(id));
+  ping_data.active_days =
+      CalculateActivePingDays(prefs_->LastActivePingDay(id),
+                              prefs_->GetActiveBit(id));
   while (existing_iter != fetches_.end()) {
     if (existing_iter->second->AddExtension(id, version.GetString(),
                                             ping_data, update_url_data)) {
@@ -423,10 +425,13 @@ ExtensionUpdater::ExtensionFetch::ExtensionFetch(const std::string& i,
 ExtensionUpdater::ExtensionFetch::~ExtensionFetch() {}
 
 ExtensionUpdater::ExtensionUpdater(ExtensionServiceInterface* service,
+                                   ExtensionPrefs* extension_prefs,
                                    PrefService* prefs,
+                                   Profile* profile,
                                    int frequency_seconds)
     : alive_(false), service_(service), frequency_seconds_(frequency_seconds),
-      prefs_(prefs), file_handler_(new ExtensionUpdaterFileHandler()),
+      extension_prefs_(extension_prefs), prefs_(prefs), profile_(profile),
+      file_handler_(new ExtensionUpdaterFileHandler()),
       blacklist_checks_enabled_(true) {
   Init();
 }
@@ -506,7 +511,9 @@ void ExtensionUpdater::Start() {
   // If these are NULL, then that means we've been called after Stop()
   // has been called.
   DCHECK(service_);
+  DCHECK(extension_prefs_);
   DCHECK(prefs_);
+  DCHECK(profile_);
   alive_ = true;
   // Make sure our prefs are registered, then schedule the first check.
   EnsureInt64PrefRegistered(prefs_, kLastExtensionsUpdateCheck);
@@ -518,7 +525,9 @@ void ExtensionUpdater::Start() {
 void ExtensionUpdater::Stop() {
   alive_ = false;
   service_ = NULL;
+  extension_prefs_ = NULL;
   prefs_ = NULL;
+  profile_ = NULL;
   timer_.Stop();
   manifest_fetcher_.reset();
   extension_fetcher_.reset();
@@ -689,18 +698,17 @@ void ExtensionUpdater::HandleManifestResults(
 
     const std::set<std::string>& extension_ids = fetch_data.extension_ids();
     std::set<std::string>::const_iterator i;
-    ExtensionPrefs* prefs = service_->extension_prefs();
     for (i = extension_ids.begin(); i != extension_ids.end(); i++) {
       if (fetch_data.DidPing(*i, ManifestFetchData::ROLLCALL)) {
         if (*i == kBlacklistAppID) {
-          prefs->SetBlacklistLastPingDay(daystart);
+          extension_prefs_->SetBlacklistLastPingDay(daystart);
         } else if (service_->GetExtensionById(*i, true) != NULL) {
-          prefs->SetLastPingDay(*i, daystart);
+          extension_prefs_->SetLastPingDay(*i, daystart);
         }
       }
-      if (prefs->GetActiveBit(*i)) {
-        prefs->SetActiveBit(*i, false);
-        prefs->SetLastActivePingDay(*i, daystart);
+      if (extension_prefs_->GetActiveBit(*i)) {
+        extension_prefs_->SetActiveBit(*i, false);
+        extension_prefs_->SetLastActivePingDay(*i, daystart);
       }
     }
   }
@@ -839,7 +847,7 @@ void ExtensionUpdater::TimerFired() {
 void ExtensionUpdater::CheckNow() {
   DCHECK(alive_);
   NotifyStarted();
-  ManifestFetchesBuilder fetches_builder(service_);
+  ManifestFetchesBuilder fetches_builder(service_, extension_prefs_);
 
   const ExtensionList* extensions = service_->extensions();
   for (ExtensionList::const_iterator iter = extensions->begin();
@@ -875,7 +883,7 @@ void ExtensionUpdater::CheckNow() {
     std::string version = prefs_->GetString(kExtensionBlacklistUpdateVersion);
     ManifestFetchData::PingData ping_data;
     ping_data.rollcall_days =
-        CalculatePingDays(service_->extension_prefs()->BlacklistLastPingDay());
+        CalculatePingDays(extension_prefs_->BlacklistLastPingDay());
     blacklist_fetch->AddExtension(kBlacklistAppID, version, ping_data, "");
     StartUpdateCheck(blacklist_fetch);
   }
@@ -1003,7 +1011,7 @@ void ExtensionUpdater::StartUpdateCheck(ManifestFetchData* fetch_data) {
         URLFetcher::Create(kManifestFetcherId, fetch_data->full_url(),
                            URLFetcher::GET, this));
     manifest_fetcher_->set_request_context(
-        service_->profile()->GetRequestContext());
+        profile_->GetRequestContext());
     manifest_fetcher_->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES |
                                       net::LOAD_DO_NOT_SAVE_COOKIES |
                                       net::LOAD_DISABLE_CACHE);
@@ -1031,7 +1039,7 @@ void ExtensionUpdater::FetchUpdatedExtension(const std::string& id,
     extension_fetcher_.reset(
         URLFetcher::Create(kExtensionFetcherId, url, URLFetcher::GET, this));
     extension_fetcher_->set_request_context(
-        service_->profile()->GetRequestContext());
+        profile_->GetRequestContext());
     extension_fetcher_->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES |
                                        net::LOAD_DO_NOT_SAVE_COOKIES |
                                        net::LOAD_DISABLE_CACHE);
@@ -1043,14 +1051,14 @@ void ExtensionUpdater::FetchUpdatedExtension(const std::string& id,
 void ExtensionUpdater::NotifyStarted() {
   NotificationService::current()->Notify(
       NotificationType::EXTENSION_UPDATING_STARTED,
-      Source<Profile>(service_->profile()),
+      Source<Profile>(profile_),
       NotificationService::NoDetails());
 }
 
 void ExtensionUpdater::NotifyUpdateFound(const std::string& extension_id) {
   NotificationService::current()->Notify(
       NotificationType::EXTENSION_UPDATE_FOUND,
-      Source<Profile>(service_->profile()),
+      Source<Profile>(profile_),
       Details<const std::string>(&extension_id));
 }
 
@@ -1058,7 +1066,7 @@ void ExtensionUpdater::NotifyIfFinished() {
   if (in_progress_ids_.empty()) {
     NotificationService::current()->Notify(
         NotificationType::EXTENSION_UPDATING_FINISHED,
-        Source<Profile>(service_->profile()),
+        Source<Profile>(profile_),
         NotificationService::NoDetails());
     VLOG(1) << "Sending EXTENSION_UPDATING_FINISHED";
   }
diff --git a/chrome/browser/extensions/extension_updater.h b/chrome/browser/extensions/extension_updater.h
index 328762b..e5be521 100644
--- a/chrome/browser/extensions/extension_updater.h
+++ b/chrome/browser/extensions/extension_updater.h
@@ -25,9 +25,11 @@
 #include "googleurl/src/gurl.h"
 
 class Extension;
+class ExtensionPrefs;
 class ExtensionUpdaterTest;
 class ExtensionUpdaterFileHandler;
 class PrefService;
+class Profile;
 
 // To save on server resources we can request updates for multiple extensions
 // in one manifest check. This class helps us keep track of the id's for a
@@ -102,7 +104,8 @@ class ManifestFetchData {
 // extensions and pending extensions.
 class ManifestFetchesBuilder {
  public:
-  explicit ManifestFetchesBuilder(ExtensionServiceInterface* service);
+  ManifestFetchesBuilder(ExtensionServiceInterface* service,
+                         ExtensionPrefs* prefs);
   ~ManifestFetchesBuilder();
 
   void AddExtension(const Extension& extension);
@@ -138,7 +141,8 @@ class ManifestFetchesBuilder {
                         Extension::Type extension_type,
                         GURL update_url,
                         const std::string& update_url_data);
-  ExtensionServiceInterface* service_;
+  ExtensionServiceInterface* const service_;
+  ExtensionPrefs* const prefs_;
 
   // List of data on fetches we're going to do. We limit the number of
   // extensions grouped together in one batch to avoid running into the limits
@@ -167,7 +171,9 @@ class ExtensionUpdater
   // extensions and installing updated ones. The |frequency_seconds| parameter
   // controls how often update checks are scheduled.
   ExtensionUpdater(ExtensionServiceInterface* service,
+                   ExtensionPrefs* extension_prefs,
                    PrefService* prefs,
+                   Profile* profile,
                    int frequency_seconds);
 
   // Starts the updater running.  Should be called at most once.
@@ -322,7 +328,9 @@ class ExtensionUpdater
   base::OneShotTimer<ExtensionUpdater> timer_;
   int frequency_seconds_;
 
+  ExtensionPrefs* extension_prefs_;
   PrefService* prefs_;
+  Profile* profile_;
 
   scoped_refptr<ExtensionUpdaterFileHandler> file_handler_;
   bool blacklist_checks_enabled_;
diff --git a/chrome/browser/extensions/extension_updater_unittest.cc b/chrome/browser/extensions/extension_updater_unittest.cc
index 5c93424..16de5b4 100644
--- a/chrome/browser/extensions/extension_updater_unittest.cc
+++ b/chrome/browser/extensions/extension_updater_unittest.cc
@@ -64,12 +64,6 @@ class MockService : public ExtensionServiceInterface {
     return NULL;
   }
 
-  virtual PendingExtensionManager* pending_extension_manager() {
-    ADD_FAILURE() << "Subclass should override this if it will "
-                  << "be accessed by a test.";
-    return &pending_extension_manager_;
-  }
-
   virtual void UpdateExtension(const std::string& id,
                                const FilePath& path,
                                const GURL& download_url) {
@@ -87,6 +81,17 @@ class MockService : public ExtensionServiceInterface {
     FAIL();
   }
 
+  virtual bool IsExtensionEnabled(const std::string& extension_id) const {
+    ADD_FAILURE();
+    return false;
+  }
+
+  virtual bool IsExternalExtensionUninstalled(
+      const std::string& extension_id) const {
+    ADD_FAILURE();
+    return false;
+  }
+
   virtual void EnableExtension(const std::string& extension_id) {
     FAIL();
   }
@@ -110,22 +115,29 @@ class MockService : public ExtensionServiceInterface {
     return false;
   }
 
-  virtual void SetIsIncognitoEnabled(const Extension* extension,
+  virtual bool IsIncognitoEnabled(const std::string& id) const {
+    ADD_FAILURE();
+    return false;
+  }
+
+  virtual void SetIsIncognitoEnabled(const std::string& id,
                                      bool enabled) {
     FAIL();
   }
 
-  virtual ExtensionPrefs* extension_prefs() { return prefs_.prefs(); }
-  virtual const ExtensionPrefs& const_extension_prefs() const {
-    return prefs_.const_prefs();
+  virtual void CheckForUpdates() {
+    FAIL();
   }
 
-  virtual ExtensionUpdater* updater() {
-    ADD_FAILURE();
-    return NULL;
+  virtual PendingExtensionManager* pending_extension_manager() {
+    ADD_FAILURE() << "Subclass should override this if it will "
+                  << "be accessed by a test.";
+    return &pending_extension_manager_;
   }
 
-  virtual Profile* profile() { return &profile_; }
+  Profile* profile() { return &profile_; }
+
+  ExtensionPrefs* extension_prefs() { return prefs_.prefs(); }
 
   PrefService* pref_service() { return prefs_.pref_service(); }
 
@@ -375,7 +387,9 @@ class ExtensionUpdaterTest : public testing::Test {
     TestURLFetcherFactory factory;
     URLFetcher::set_factory(&factory);
     scoped_refptr<ExtensionUpdater> updater(
-        new ExtensionUpdater(&service, service.pref_service(), 60*60*24));
+        new ExtensionUpdater(
+            &service, service.extension_prefs(), service.pref_service(),
+            service.profile(), 60*60*24));
     updater->Start();
 
     // Tell the update that it's time to do update checks.
@@ -423,7 +437,9 @@ class ExtensionUpdaterTest : public testing::Test {
     TestURLFetcherFactory factory;
     URLFetcher::set_factory(&factory);
     scoped_refptr<ExtensionUpdater> updater(
-        new ExtensionUpdater(&service, service.pref_service(), 60*60*24));
+        new ExtensionUpdater(
+            &service, service.extension_prefs(), service.pref_service(),
+            service.profile(), 60*60*24));
     updater->Start();
 
     // Tell the updater that it's time to do update checks.
@@ -510,7 +526,7 @@ class ExtensionUpdaterTest : public testing::Test {
 
   static void TestUpdateUrlDataFromGallery(const std::string& gallery_url) {
     MockService service;
-    ManifestFetchesBuilder builder(&service);
+    ManifestFetchesBuilder builder(&service, service.extension_prefs());
     ExtensionList extensions;
     std::string url(gallery_url);
 
@@ -541,8 +557,9 @@ class ExtensionUpdaterTest : public testing::Test {
     service.set_extensions(tmp);
 
     scoped_refptr<ExtensionUpdater> updater(
-        new ExtensionUpdater(&service, service.pref_service(),
-                             kUpdateFrequencySecs));
+        new ExtensionUpdater(
+            &service, service.extension_prefs(), service.pref_service(),
+            service.profile(), kUpdateFrequencySecs));
     updater->Start();
 
     // Check passing an empty list of parse results to DetermineUpdates
@@ -581,8 +598,9 @@ class ExtensionUpdaterTest : public testing::Test {
 
     MessageLoop message_loop;
     scoped_refptr<ExtensionUpdater> updater(
-        new ExtensionUpdater(&service, service.pref_service(),
-                             kUpdateFrequencySecs));
+        new ExtensionUpdater(
+            &service, service.extension_prefs(), service.pref_service(),
+            service.profile(), kUpdateFrequencySecs));
     updater->Start();
 
     ManifestFetchData fetch_data(GURL("http://localhost/foo"));
@@ -618,7 +636,9 @@ class ExtensionUpdaterTest : public testing::Test {
     URLFetcher::set_factory(&factory);
     scoped_ptr<ServiceForDownloadTests> service(new ServiceForDownloadTests);
     scoped_refptr<ExtensionUpdater> updater(
-        new ExtensionUpdater(service.get(), service->pref_service(),
+        new ExtensionUpdater(service.get(), service->extension_prefs(),
+                             service->pref_service(),
+                             service->profile(),
                              kUpdateFrequencySecs));
     updater->Start();
 
@@ -690,7 +710,9 @@ class ExtensionUpdaterTest : public testing::Test {
     URLFetcher::set_factory(&factory);
     scoped_ptr<ServiceForDownloadTests> service(new ServiceForDownloadTests);
     scoped_refptr<ExtensionUpdater> updater(
-        new ExtensionUpdater(service.get(), service->pref_service(),
+        new ExtensionUpdater(service.get(), service->extension_prefs(),
+                             service->pref_service(),
+                             service->profile(),
                              kUpdateFrequencySecs));
     updater->Start();
 
@@ -759,8 +781,9 @@ class ExtensionUpdaterTest : public testing::Test {
     URLFetcher::set_factory(&factory);
     ServiceForBlacklistTests service;
     scoped_refptr<ExtensionUpdater> updater(
-        new ExtensionUpdater(&service, service.pref_service(),
-                             kUpdateFrequencySecs));
+        new ExtensionUpdater(
+            &service, service.extension_prefs(), service.pref_service(),
+            service.profile(), kUpdateFrequencySecs));
     updater->Start();
     GURL test_url("http://localhost/extension.crx");
 
@@ -805,8 +828,9 @@ class ExtensionUpdaterTest : public testing::Test {
     URLFetcher::set_factory(&factory);
     ServiceForDownloadTests service;
     scoped_refptr<ExtensionUpdater> updater(
-        new ExtensionUpdater(&service, service.pref_service(),
-                             kUpdateFrequencySecs));
+        new ExtensionUpdater(
+            &service, service.extension_prefs(), service.pref_service(),
+            service.profile(), kUpdateFrequencySecs));
     updater->Start();
 
     GURL url1("http://localhost/extension1.crx");
@@ -917,8 +941,9 @@ class ExtensionUpdaterTest : public testing::Test {
       prefs->SetActiveBit(id, true);
 
     scoped_refptr<ExtensionUpdater> updater(
-      new ExtensionUpdater(&service, service.pref_service(),
-                           kUpdateFrequencySecs));
+      new ExtensionUpdater(
+          &service, service.extension_prefs(), service.pref_service(),
+          service.profile(), kUpdateFrequencySecs));
     updater->Start();
     updater->set_blacklist_checks_enabled(false);
 
@@ -982,8 +1007,9 @@ class ExtensionUpdaterTest : public testing::Test {
     ServiceForManifestTests service;
     MessageLoop message_loop;
     scoped_refptr<ExtensionUpdater> updater(
-        new ExtensionUpdater(&service, service.pref_service(),
-                             kUpdateFrequencySecs));
+        new ExtensionUpdater(
+            &service, service.extension_prefs(), service.pref_service(),
+            service.profile(), kUpdateFrequencySecs));
     updater->Start();
 
     GURL update_url("http://www.google.com/manifest");
@@ -1106,7 +1132,7 @@ TEST(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) {
   BrowserThread file_thread(BrowserThread::FILE, &message_loop);
 
   MockService service;
-  ManifestFetchesBuilder builder(&service);
+  ManifestFetchesBuilder builder(&service, service.extension_prefs());
 
   // Non-internal non-external extensions should be rejected.
   {
@@ -1158,8 +1184,9 @@ TEST(ExtensionUpdaterTest, TestStartUpdateCheckMemory) {
     TestURLFetcherFactory factory;
     URLFetcher::set_factory(&factory);
     scoped_refptr<ExtensionUpdater> updater(
-        new ExtensionUpdater(&service, service.pref_service(),
-                             kUpdateFrequencySecs));
+        new ExtensionUpdater(
+            &service, service.extension_prefs(), service.pref_service(),
+            service.profile(), kUpdateFrequencySecs));
     updater->Start();
     updater->StartUpdateCheck(new ManifestFetchData(GURL()));
     // This should delete the newly-created ManifestFetchData.
@@ -1177,8 +1204,9 @@ TEST(ExtensionUpdaterTest, TestAfterStopBehavior) {
 
     ServiceForManifestTests service;
     scoped_refptr<ExtensionUpdater> updater(
-        new ExtensionUpdater(&service, service.pref_service(),
-                             kUpdateFrequencySecs));
+        new ExtensionUpdater(
+            &service, service.extension_prefs(), service.pref_service(),
+            service.profile(), kUpdateFrequencySecs));
     updater->Start();
     updater->Stop();
     // All the below functions should do nothing.
diff --git a/chrome/browser/extensions/extension_web_ui.cc b/chrome/browser/extensions/extension_web_ui.cc
index 6ec373d..b7a7caf 100644
--- a/chrome/browser/extensions/extension_web_ui.cc
+++ b/chrome/browser/extensions/extension_web_ui.cc
@@ -284,7 +284,7 @@ bool ExtensionWebUI::HandleChromeURLOverride(GURL* url, Profile* profile) {
     // extension uses split mode.
     bool incognito_override_allowed =
         extension->incognito_split_mode() &&
-        service->IsIncognitoEnabled(extension);
+        service->IsIncognitoEnabled(extension->id());
     if (profile->IsOffTheRecord() && !incognito_override_allowed) {
       ++i;
       continue;
diff --git a/chrome/browser/extensions/extensions_ui.cc b/chrome/browser/extensions/extensions_ui.cc
index e9adb7b..166c80c 100644
--- a/chrome/browser/extensions/extensions_ui.cc
+++ b/chrome/browser/extensions/extensions_ui.cc
@@ -411,7 +411,8 @@ void ExtensionsDOMHandler::HandleEnableIncognitoMessage(const ListValue* args) {
   //
   // Bug: http://crbug.com/41384
   ignore_notifications_ = true;
-  extensions_service_->SetIsIncognitoEnabled(extension, enable_str == "true");
+  extensions_service_->SetIsIncognitoEnabled(extension_id,
+                                             enable_str == "true");
   ignore_notifications_ = false;
 }
 
@@ -699,7 +700,7 @@ DictionaryValue* ExtensionsDOMHandler::CreateExtensionDetailValue(
   extension_data->SetBoolean("enabled", enabled);
   extension_data->SetBoolean("terminated", terminated);
   extension_data->SetBoolean("enabledIncognito",
-      service ? service->IsIncognitoEnabled(extension) : false);
+      service ? service->IsIncognitoEnabled(extension->id()) : false);
   extension_data->SetBoolean("wantsFileAccess", extension->wants_file_access());
   extension_data->SetBoolean("allowFileAccess",
       service ? service->AllowFileAccess(extension) : false);
diff --git a/chrome/browser/extensions/pending_extension_manager.cc b/chrome/browser/extensions/pending_extension_manager.cc
index 268df59..5b8e829 100644
--- a/chrome/browser/extensions/pending_extension_manager.cc
+++ b/chrome/browser/extensions/pending_extension_manager.cc
@@ -81,7 +81,7 @@ void PendingExtensionManager::AddFromExternalUpdateUrl(
   const bool kEnableOnInstall = true;
   const bool kEnableIncognitoOnInstall = false;
 
-  if (service_.const_extension_prefs().IsExternalExtensionUninstalled(id))
+  if (service_.IsExternalExtensionUninstalled(id))
     return;
 
   if (service_.GetExtensionById(id, true)) {
diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc
index f038ffc..88903d8 100644
--- a/chrome/browser/extensions/user_script_master.cc
+++ b/chrome/browser/extensions/user_script_master.cc
@@ -344,7 +344,7 @@ void UserScriptMaster::Observe(NotificationType type,
       // Add any content scripts inside the extension.
       const Extension* extension = Details<const Extension>(details).ptr();
       bool incognito_enabled = profile_->GetExtensionService()->
-          IsIncognitoEnabled(extension);
+          IsIncognitoEnabled(extension->id());
       const UserScriptList& scripts = extension->content_scripts();
       for (UserScriptList::const_iterator iter = scripts.begin();
            iter != scripts.end(); ++iter) {
@@ -377,7 +377,7 @@ void UserScriptMaster::Observe(NotificationType type,
       const Extension* extension = Details<const Extension>(details).ptr();
       UserScriptList new_lone_scripts;
       bool incognito_enabled = profile_->GetExtensionService()->
-          IsIncognitoEnabled(extension);
+          IsIncognitoEnabled(extension->id());
       for (UserScriptList::iterator iter = lone_scripts_.begin();
            iter != lone_scripts_.end(); ++iter) {
         if (iter->extension_id() == extension->id()) {
diff --git a/chrome/browser/sync/glue/extension_sync.cc b/chrome/browser/sync/glue/extension_sync.cc
index a5d2172..bef56cb 100644
--- a/chrome/browser/sync/glue/extension_sync.cc
+++ b/chrome/browser/sync/glue/extension_sync.cc
@@ -90,7 +90,7 @@ void ReadClientDataFromExtensionList(
     const Extension& extension = **it;
     if (is_valid_and_syncable(extension)) {
       sync_pb::ExtensionSpecifics client_specifics;
-      GetExtensionSpecifics(extension, extensions_service->extension_prefs(),
+      GetExtensionSpecifics(extension, extensions_service,
                             &client_specifics);
       DcheckIsExtensionSpecificsValid(client_specifics);
       const ExtensionData& extension_data =
@@ -277,7 +277,7 @@ void TryUpdateClient(
     SetExtensionProperties(specifics, extensions_service, extension);
     {
       sync_pb::ExtensionSpecifics extension_specifics;
-      GetExtensionSpecifics(*extension, extensions_service->extension_prefs(),
+      GetExtensionSpecifics(*extension, extensions_service,
                             &extension_specifics);
       DCHECK(AreExtensionSpecificsUserPropertiesEqual(
           specifics, extension_specifics))
@@ -302,22 +302,6 @@ void TryUpdateClient(
   DCHECK(!extension_data->NeedsUpdate(ExtensionData::SERVER));
 }
 
-// Kick off a run of the extension updater.
-//
-// TODO(akalin): Combine this with the similar function in
-// theme_util.cc.
-void NudgeExtensionUpdater(ExtensionServiceInterface* extensions_service) {
-  ExtensionUpdater* extension_updater = extensions_service->updater();
-  // Auto-updates should now be on always (see the construction of the
-  // ExtensionService in ProfileImpl::InitExtensions()).
-  if (extension_updater) {
-    extension_updater->CheckNow();
-  } else {
-    LOG(DFATAL) << "Extension updater unexpectedly NULL; "
-                << "auto-updates may be turned off";
-  }
-}
-
 }  // namespace
 
 bool FlushExtensionData(const ExtensionSyncTraits& traits,
@@ -358,7 +342,7 @@ bool FlushExtensionData(const ExtensionSyncTraits& traits,
   }
 
   if (should_nudge_extension_updater) {
-    NudgeExtensionUpdater(extensions_service);
+    extensions_service->CheckForUpdates();
   }
 
   return true;
@@ -380,7 +364,7 @@ bool UpdateServerData(const ExtensionSyncTraits& traits,
   ExtensionServiceInterface* extensions_service =
       GetExtensionServiceFromProfileSyncService(sync_service);
   sync_pb::ExtensionSpecifics client_data;
-  GetExtensionSpecifics(extension, extensions_service->extension_prefs(),
+  GetExtensionSpecifics(extension, extensions_service,
                         &client_data);
   DcheckIsExtensionSpecificsValid(client_data);
   ExtensionData extension_data =
@@ -449,7 +433,7 @@ void UpdateClient(const ExtensionSyncTraits& traits,
       return;
     }
     sync_pb::ExtensionSpecifics client_data;
-    GetExtensionSpecifics(*extension, extensions_service->extension_prefs(),
+    GetExtensionSpecifics(*extension, extensions_service,
                           &client_data);
     DcheckIsExtensionSpecificsValid(client_data);
     extension_data =
@@ -461,7 +445,7 @@ void UpdateClient(const ExtensionSyncTraits& traits,
     TryUpdateClient(traits.is_valid_and_syncable,
                     extensions_service, &extension_data);
     if (extension_data.NeedsUpdate(ExtensionData::CLIENT)) {
-      NudgeExtensionUpdater(extensions_service);
+      extensions_service->CheckForUpdates();
     }
   }
   DCHECK(!extension_data.NeedsUpdate(ExtensionData::SERVER));
diff --git a/chrome/browser/sync/glue/extension_util.cc b/chrome/browser/sync/glue/extension_util.cc
index e94ba11..67b5856 100644
--- a/chrome/browser/sync/glue/extension_util.cc
+++ b/chrome/browser/sync/glue/extension_util.cc
@@ -143,12 +143,11 @@ bool AreExtensionSpecificsNonUserPropertiesEqual(
 }
 
 void GetExtensionSpecifics(const Extension& extension,
-                           ExtensionPrefs* extension_prefs,
+                           ExtensionServiceInterface* extension_service,
                            sync_pb::ExtensionSpecifics* specifics) {
   const std::string& id = extension.id();
-  bool enabled =
-      extension_prefs->GetExtensionState(id) == Extension::ENABLED;
-  bool incognito_enabled = extension_prefs->IsIncognitoEnabled(id);
+  bool enabled = extension_service->IsExtensionEnabled(id);
+  bool incognito_enabled = extension_service->IsIncognitoEnabled(id);
   GetExtensionSpecificsHelper(extension, enabled, incognito_enabled,
                               specifics);
 }
@@ -195,18 +194,12 @@ void SetExtensionProperties(
                  << "has a different update URL than the extension: "
                  << update_url.spec() << " vs. " << extension->update_url();
   }
-  ExtensionPrefs* extension_prefs = extensions_service->extension_prefs();
-  bool enabled = extension_prefs->GetExtensionState(id) == Extension::ENABLED;
-  if (enabled && !specifics.enabled()) {
-    extensions_service->DisableExtension(id);
-  } else if (!enabled && specifics.enabled()) {
+  if (specifics.enabled()) {
     extensions_service->EnableExtension(id);
+  } else {
+    extensions_service->DisableExtension(id);
   }
-  bool incognito_enabled = extension_prefs->IsIncognitoEnabled(id);
-  if (incognito_enabled != specifics.incognito_enabled()) {
-    extensions_service->SetIsIncognitoEnabled(
-        extension, specifics.incognito_enabled());
-  }
+  extensions_service->SetIsIncognitoEnabled(id, specifics.incognito_enabled());
   if (specifics.name() != extension->name()) {
     LOG(WARNING) << "specifics for extension " << id
                  << "has a different name than the extension: "
diff --git a/chrome/browser/sync/glue/extension_util.h b/chrome/browser/sync/glue/extension_util.h
index a68a066..ddd6c1b 100644
--- a/chrome/browser/sync/glue/extension_util.h
+++ b/chrome/browser/sync/glue/extension_util.h
@@ -81,7 +81,7 @@ bool AreExtensionSpecificsNonUserPropertiesEqual(
 // must be a syncable extension.  |specifics| will be valid after this
 // function is called.
 void GetExtensionSpecifics(const Extension& extension,
-                           ExtensionPrefs* extension_prefs,
+                           ExtensionServiceInterface* extension_service,
                            sync_pb::ExtensionSpecifics* specifics);
 
 // Exposed only for testing.  Pre- and post-conditions are the same as
diff --git a/chrome/browser/sync/glue/theme_util.cc b/chrome/browser/sync/glue/theme_util.cc
index 3d700da..f4d0181 100644
--- a/chrome/browser/sync/glue/theme_util.cc
+++ b/chrome/browser/sync/glue/theme_util.cc
@@ -102,14 +102,7 @@ void SetCurrentThemeFromThemeSpecifics(
         VLOG(1) << "Extension " << id << " is not a theme; aborting";
         return;
       }
-      ExtensionPrefs* extension_prefs = extensions_service->extension_prefs();
-      CHECK(extension_prefs);
-      // TODO(akalin): GetExtensionState() isn't very safe as it
-      // returns Extension::ENABLED by default; either change it to
-      // return something else by default or create a separate
-      // function that does so.
-      if (extension_prefs->GetExtensionState(extension->id()) !=
-          Extension::ENABLED) {
+      if (!extensions_service->IsExtensionEnabled(id)) {
         VLOG(1) << "Theme " << id << " is not enabled; aborting";
         return;
       }
@@ -144,15 +137,7 @@ void SetCurrentThemeFromThemeSpecifics(
       extensions_service->pending_extension_manager()->AddFromSync(
           id, update_url, &IsTheme,
           kInstallSilently, kEnableOnInstall, kEnableIncognitoOnInstall);
-      ExtensionUpdater* extension_updater = extensions_service->updater();
-      // Auto-updates should now be on always (see the construction of
-      // the ExtensionService in ProfileImpl::InitExtensions()).
-      if (!extension_updater) {
-        LOG(DFATAL) << "Extension updater unexpectedly NULL; "
-                    << "auto-updates may be turned off";
-        return;
-      }
-      extension_updater->CheckNow();
+      extensions_service->CheckForUpdates();
     }
   } else if (theme_specifics.use_system_theme_by_default()) {
     ThemeServiceFactory::GetForProfile(profile)->SetNativeTheme();
diff --git a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
index 3871084..e8d899e 100644
--- a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
+++ b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
@@ -749,8 +749,9 @@ class ExtensionServiceObserverBridge : public NotificationObserver,
 
 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension {
   // Only display incognito-enabled extensions while in incognito mode.
-  return (!profile_->IsOffTheRecord() ||
-          profile_->GetExtensionService()->IsIncognitoEnabled(extension));
+  return
+      (!profile_->IsOffTheRecord() ||
+       profile_->GetExtensionService()->IsIncognitoEnabled(extension->id()));
 }
 
 - (void)showChevronIfNecessaryInFrame:(NSRect)frame animate:(BOOL)animate {
diff --git a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc
index 511dee1..c89f3c8 100644
--- a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc
+++ b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc
@@ -573,7 +573,7 @@ bool BrowserActionsToolbarGtk::ShouldDisplayBrowserAction(
     const Extension* extension) {
   // Only display incognito-enabled extensions while in incognito mode.
   return (!profile_->IsOffTheRecord() ||
-          profile_->GetExtensionService()->IsIncognitoEnabled(extension));
+          profile_->GetExtensionService()->IsIncognitoEnabled(extension->id()));
 }
 
 void BrowserActionsToolbarGtk::HidePopup() {
diff --git a/chrome/browser/ui/views/browser_actions_container.cc b/chrome/browser/ui/views/browser_actions_container.cc
index cc90cc1..26c40d1 100644
--- a/chrome/browser/ui/views/browser_actions_container.cc
+++ b/chrome/browser/ui/views/browser_actions_container.cc
@@ -1096,6 +1096,7 @@ void BrowserActionsContainer::SaveDesiredSizeAndAnimate(
 bool BrowserActionsContainer::ShouldDisplayBrowserAction(
     const Extension* extension) {
   // Only display incognito-enabled extensions while in incognito mode.
-  return (!profile_->IsOffTheRecord() ||
-          profile_->GetExtensionService()->IsIncognitoEnabled(extension));
+  return
+      (!profile_->IsOffTheRecord() ||
+       profile_->GetExtensionService()->IsIncognitoEnabled(extension->id()));
 }
-- 
cgit v1.1