Only send extension unloaded/loaded notifications when changing the incognito enabled flag.

BUG=75267
TEST=ExtensionToolbarModelTest.*

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77457 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index 159785ba..702fc868 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -1132,13 +1132,18 @@
 
 void ExtensionService::SetIsIncognitoEnabled(const Extension* extension,
                                               bool enabled) {
+  // 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());
+  if (enabled == old_enabled)
+    return;
+
   extension_prefs_->SetIsIncognitoEnabled(extension->id(), enabled);
 
-  // Broadcast unloaded and loaded events to update browser state. Only bother
-  // if the extension is actually enabled, since there is no UI otherwise.
-  bool is_enabled = std::find(extensions_.begin(), extensions_.end(),
-                              extension) != extensions_.end();
-  if (is_enabled) {
+  bool extension_is_enabled = std::find(extensions_.begin(), extensions_.end(),
+                                        extension) != extensions_.end();
+  if (extension_is_enabled) {
     NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::DISABLE);
     NotifyExtensionLoaded(extension);
   }