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

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

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/chrome_notification_types.h"
11 #include "chrome/common/extensions/extension.h" 12 #include "chrome/common/extensions/extension.h"
12 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
13 #include "content/common/notification_service.h" 14 #include "content/common/notification_service.h"
14 15
15 ExtensionToolbarModel::ExtensionToolbarModel(ExtensionService* service) 16 ExtensionToolbarModel::ExtensionToolbarModel(ExtensionService* service)
16 : service_(service), 17 : service_(service),
17 prefs_(service->profile()->GetPrefs()), 18 prefs_(service->profile()->GetPrefs()),
18 extensions_initialized_(false) { 19 extensions_initialized_(false) {
19 DCHECK(service_); 20 DCHECK(service_);
20 21
21 registrar_.Add(this, NotificationType::EXTENSION_LOADED, 22 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
22 Source<Profile>(service_->profile())); 23 Source<Profile>(service_->profile()));
23 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, 24 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
24 Source<Profile>(service_->profile())); 25 Source<Profile>(service_->profile()));
25 registrar_.Add(this, NotificationType::EXTENSIONS_READY, 26 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
26 Source<Profile>(service_->profile())); 27 Source<Profile>(service_->profile()));
27 registrar_.Add(this, 28 registrar_.Add(
28 NotificationType::EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, 29 this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED,
29 NotificationService::AllSources()); 30 NotificationService::AllSources());
30 31
31 visible_icon_count_ = prefs_->GetInteger(prefs::kExtensionToolbarSize); 32 visible_icon_count_ = prefs_->GetInteger(prefs::kExtensionToolbarSize);
32 } 33 }
33 34
34 ExtensionToolbarModel::~ExtensionToolbarModel() { 35 ExtensionToolbarModel::~ExtensionToolbarModel() {
35 } 36 }
36 37
37 void ExtensionToolbarModel::AddObserver(Observer* observer) { 38 void ExtensionToolbarModel::AddObserver(Observer* observer) {
38 observers_.AddObserver(observer); 39 observers_.AddObserver(observer);
39 } 40 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 73
73 UpdatePrefs(); 74 UpdatePrefs();
74 } 75 }
75 76
76 void ExtensionToolbarModel::SetVisibleIconCount(int count) { 77 void ExtensionToolbarModel::SetVisibleIconCount(int count) {
77 visible_icon_count_ = count == static_cast<int>(size()) ? -1 : count; 78 visible_icon_count_ = count == static_cast<int>(size()) ? -1 : count;
78 prefs_->SetInteger(prefs::kExtensionToolbarSize, visible_icon_count_); 79 prefs_->SetInteger(prefs::kExtensionToolbarSize, visible_icon_count_);
79 prefs_->ScheduleSavePersistentPrefs(); 80 prefs_->ScheduleSavePersistentPrefs();
80 } 81 }
81 82
82 void ExtensionToolbarModel::Observe(NotificationType type, 83 void ExtensionToolbarModel::Observe(int type,
83 const NotificationSource& source, 84 const NotificationSource& source,
84 const NotificationDetails& details) { 85 const NotificationDetails& details) {
85 if (type == NotificationType::EXTENSIONS_READY) { 86 if (type == chrome::NOTIFICATION_EXTENSIONS_READY) {
86 InitializeExtensionList(); 87 InitializeExtensionList();
87 return; 88 return;
88 } 89 }
89 90
90 if (!service_->is_ready()) 91 if (!service_->is_ready())
91 return; 92 return;
92 93
93 const Extension* extension = NULL; 94 const Extension* extension = NULL;
94 if (type == NotificationType::EXTENSION_UNLOADED) { 95 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
95 extension = Details<UnloadedExtensionInfo>(details)->extension; 96 extension = Details<UnloadedExtensionInfo>(details)->extension;
96 } else { 97 } else {
97 extension = Details<const Extension>(details).ptr(); 98 extension = Details<const Extension>(details).ptr();
98 } 99 }
99 if (type == NotificationType::EXTENSION_LOADED) { 100 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) {
100 // We don't want to add the same extension twice. It may have already been 101 // We don't want to add the same extension twice. It may have already been
101 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user 102 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user
102 // hides the browser action and then disables and enables the extension. 103 // hides the browser action and then disables and enables the extension.
103 for (size_t i = 0; i < toolitems_.size(); i++) { 104 for (size_t i = 0; i < toolitems_.size(); i++) {
104 if (toolitems_[i].get() == extension) 105 if (toolitems_[i].get() == extension)
105 return; // Already exists. 106 return; // Already exists.
106 } 107 }
107 if (service_->GetBrowserActionVisibility(extension)) 108 if (service_->GetBrowserActionVisibility(extension))
108 AddExtension(extension); 109 AddExtension(extension);
109 } else if (type == NotificationType::EXTENSION_UNLOADED) { 110 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
110 RemoveExtension(extension); 111 RemoveExtension(extension);
111 } else if (type == 112 } else if (
112 NotificationType::EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) { 113 type ==
114 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) {
113 if (service_->GetBrowserActionVisibility(extension)) 115 if (service_->GetBrowserActionVisibility(extension))
114 AddExtension(extension); 116 AddExtension(extension);
115 else 117 else
116 RemoveExtension(extension); 118 RemoveExtension(extension);
117 } else { 119 } else {
118 NOTREACHED() << "Received unexpected notification"; 120 NOTREACHED() << "Received unexpected notification";
119 } 121 }
120 } 122 }
121 123
122 void ExtensionToolbarModel::AddExtension(const Extension* extension) { 124 void ExtensionToolbarModel::AddExtension(const Extension* extension) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 int incognito_index = 0, i = 0; 249 int incognito_index = 0, i = 0;
248 for (ExtensionList::iterator iter = begin(); iter != end(); 250 for (ExtensionList::iterator iter = begin(); iter != end();
249 ++iter, ++i) { 251 ++iter, ++i) {
250 if (original_index == i) 252 if (original_index == i)
251 break; 253 break;
252 if (service_->IsIncognitoEnabled((*iter)->id())) 254 if (service_->IsIncognitoEnabled((*iter)->id()))
253 ++incognito_index; 255 ++incognito_index;
254 } 256 }
255 return incognito_index; 257 return incognito_index;
256 } 258 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_toolbar_model.h ('k') | chrome/browser/extensions/extension_updater.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698