Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Side by Side Diff: chrome/browser/extensions/extension_toolbar_model.cc

Issue 5968009: Change extension unload notification to indicate updates.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_toolbar_model.h" 5 #include "chrome/browser/extensions/extension_toolbar_model.h"
6 6
7 #include "chrome/browser/extensions/extension_prefs.h" 7 #include "chrome/browser/extensions/extension_prefs.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/prefs/pref_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/extensions/extension.h" 11 #include "chrome/common/extensions/extension.h"
12 #include "chrome/common/notification_service.h" 12 #include "chrome/common/notification_service.h"
13 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
14 14
15 ExtensionToolbarModel::ExtensionToolbarModel(ExtensionService* service) 15 ExtensionToolbarModel::ExtensionToolbarModel(ExtensionService* service)
16 : service_(service), 16 : service_(service),
17 prefs_(service->profile()->GetPrefs()), 17 prefs_(service->profile()->GetPrefs()),
18 extensions_initialized_(false) { 18 extensions_initialized_(false) {
19 DCHECK(service_); 19 DCHECK(service_);
20 20
21 registrar_.Add(this, NotificationType::EXTENSION_LOADED, 21 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
22 Source<Profile>(service_->profile())); 22 Source<Profile>(service_->profile()));
23 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, 23 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
24 Source<Profile>(service_->profile())); 24 Source<Profile>(service_->profile()));
25 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
26 Source<Profile>(service_->profile()));
27 registrar_.Add(this, NotificationType::EXTENSIONS_READY, 25 registrar_.Add(this, NotificationType::EXTENSIONS_READY,
28 Source<Profile>(service_->profile())); 26 Source<Profile>(service_->profile()));
29 registrar_.Add(this, 27 registrar_.Add(this,
30 NotificationType::EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, 28 NotificationType::EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED,
31 NotificationService::AllSources()); 29 NotificationService::AllSources());
32 30
33 visible_icon_count_ = prefs_->GetInteger(prefs::kExtensionToolbarSize); 31 visible_icon_count_ = prefs_->GetInteger(prefs::kExtensionToolbarSize);
34 } 32 }
35 33
36 ExtensionToolbarModel::~ExtensionToolbarModel() { 34 ExtensionToolbarModel::~ExtensionToolbarModel() {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 const NotificationSource& source, 87 const NotificationSource& source,
90 const NotificationDetails& details) { 88 const NotificationDetails& details) {
91 if (type == NotificationType::EXTENSIONS_READY) { 89 if (type == NotificationType::EXTENSIONS_READY) {
92 InitializeExtensionList(); 90 InitializeExtensionList();
93 return; 91 return;
94 } 92 }
95 93
96 if (!service_->is_ready()) 94 if (!service_->is_ready())
97 return; 95 return;
98 96
99 const Extension* extension = Details<const Extension>(details).ptr(); 97 const Extension* extension = NULL;
98 if (type == NotificationType::EXTENSION_UNLOADED) {
99 extension = Details<UnloadedExtensionInfo>(details)->extension;
100 } else {
101 extension = Details<const Extension>(details).ptr();
102 }
100 if (type == NotificationType::EXTENSION_LOADED) { 103 if (type == NotificationType::EXTENSION_LOADED) {
101 // We don't want to add the same extension twice. It may have already been 104 // We don't want to add the same extension twice. It may have already been
102 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user 105 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user
103 // hides the browser action and then disables and enables the extension. 106 // hides the browser action and then disables and enables the extension.
104 for (size_t i = 0; i < toolitems_.size(); i++) { 107 for (size_t i = 0; i < toolitems_.size(); i++) {
105 if (toolitems_[i].get() == extension) 108 if (toolitems_[i].get() == extension)
106 return; // Already exists. 109 return; // Already exists.
107 } 110 }
108 if (service_->GetBrowserActionVisibility(extension)) 111 if (service_->GetBrowserActionVisibility(extension))
109 AddExtension(extension); 112 AddExtension(extension);
110 } else if (type == NotificationType::EXTENSION_UNLOADED || 113 } else if (type == NotificationType::EXTENSION_UNLOADED) {
111 type == NotificationType::EXTENSION_UNLOADED_DISABLED) {
112 RemoveExtension(extension); 114 RemoveExtension(extension);
113 } else if (type == 115 } else if (type ==
114 NotificationType::EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) { 116 NotificationType::EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) {
115 if (service_->GetBrowserActionVisibility(extension)) 117 if (service_->GetBrowserActionVisibility(extension))
116 AddExtension(extension); 118 AddExtension(extension);
117 else 119 else
118 RemoveExtension(extension); 120 RemoveExtension(extension);
119 } else { 121 } else {
120 NOTREACHED() << "Received unexpected notification"; 122 NOTREACHED() << "Received unexpected notification";
121 } 123 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 int incognito_index = 0, i = 0; 251 int incognito_index = 0, i = 0;
250 for (ExtensionList::iterator iter = begin(); iter != end(); 252 for (ExtensionList::iterator iter = begin(); iter != end();
251 ++iter, ++i) { 253 ++iter, ++i) {
252 if (original_index == i) 254 if (original_index == i)
253 break; 255 break;
254 if (service_->IsIncognitoEnabled(*iter)) 256 if (service_->IsIncognitoEnabled(*iter))
255 ++incognito_index; 257 ++incognito_index;
256 } 258 }
257 return incognito_index; 259 return incognito_index;
258 } 260 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698