OLD | NEW |
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/background/background_application_list_model.h" | 5 #include "chrome/browser/background/background_application_list_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
13 #include "chrome/browser/background/background_mode_manager.h" | 13 #include "chrome/browser/background/background_mode_manager.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/extensions/extension_prefs.h" | 15 #include "chrome/browser/extensions/extension_prefs.h" |
16 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
17 #include "chrome/browser/extensions/image_loading_tracker.h" | 17 #include "chrome/browser/extensions/image_loading_tracker.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/common/chrome_notification_types.h" |
19 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
20 #include "chrome/common/extensions/extension_resource.h" | 21 #include "chrome/common/extensions/extension_resource.h" |
21 #include "content/common/notification_details.h" | 22 #include "content/common/notification_details.h" |
22 #include "content/common/notification_source.h" | 23 #include "content/common/notification_source.h" |
23 #include "ui/base/l10n/l10n_util_collator.h" | 24 #include "ui/base/l10n/l10n_util_collator.h" |
24 | 25 |
25 class ExtensionNameComparator { | 26 class ExtensionNameComparator { |
26 public: | 27 public: |
27 explicit ExtensionNameComparator(icu::Collator* collator); | 28 explicit ExtensionNameComparator(icu::Collator* collator); |
28 bool operator()(const Extension* x, const Extension* y); | 29 bool operator()(const Extension* x, const Extension* y); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 147 |
147 BackgroundApplicationListModel::~BackgroundApplicationListModel() { | 148 BackgroundApplicationListModel::~BackgroundApplicationListModel() { |
148 STLDeleteContainerPairSecondPointers(applications_.begin(), | 149 STLDeleteContainerPairSecondPointers(applications_.begin(), |
149 applications_.end()); | 150 applications_.end()); |
150 } | 151 } |
151 | 152 |
152 BackgroundApplicationListModel::BackgroundApplicationListModel(Profile* profile) | 153 BackgroundApplicationListModel::BackgroundApplicationListModel(Profile* profile) |
153 : profile_(profile) { | 154 : profile_(profile) { |
154 DCHECK(profile_); | 155 DCHECK(profile_); |
155 registrar_.Add(this, | 156 registrar_.Add(this, |
156 NotificationType::EXTENSION_LOADED, | 157 chrome::NOTIFICATION_EXTENSION_LOADED, |
157 Source<Profile>(profile)); | 158 Source<Profile>(profile)); |
158 registrar_.Add(this, | 159 registrar_.Add(this, |
159 NotificationType::EXTENSION_UNLOADED, | 160 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
160 Source<Profile>(profile)); | 161 Source<Profile>(profile)); |
161 registrar_.Add(this, | 162 registrar_.Add(this, |
162 NotificationType::EXTENSIONS_READY, | 163 chrome::NOTIFICATION_EXTENSIONS_READY, |
163 Source<Profile>(profile)); | 164 Source<Profile>(profile)); |
164 ExtensionService* service = profile->GetExtensionService(); | 165 ExtensionService* service = profile->GetExtensionService(); |
165 if (service && service->is_ready()) | 166 if (service && service->is_ready()) |
166 Update(); | 167 Update(); |
167 } | 168 } |
168 | 169 |
169 void BackgroundApplicationListModel::AddObserver(Observer* observer) { | 170 void BackgroundApplicationListModel::AddObserver(Observer* observer) { |
170 observers_.AddObserver(observer); | 171 observers_.AddObserver(observer); |
171 } | 172 } |
172 | 173 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 return -1; | 243 return -1; |
243 } | 244 } |
244 | 245 |
245 // static | 246 // static |
246 bool BackgroundApplicationListModel::IsBackgroundApp( | 247 bool BackgroundApplicationListModel::IsBackgroundApp( |
247 const Extension& extension) { | 248 const Extension& extension) { |
248 return extension.HasAPIPermission(ExtensionAPIPermission::kBackground); | 249 return extension.HasAPIPermission(ExtensionAPIPermission::kBackground); |
249 } | 250 } |
250 | 251 |
251 void BackgroundApplicationListModel::Observe( | 252 void BackgroundApplicationListModel::Observe( |
252 NotificationType type, | 253 int type, |
253 const NotificationSource& source, | 254 const NotificationSource& source, |
254 const NotificationDetails& details) { | 255 const NotificationDetails& details) { |
255 if (type == NotificationType::EXTENSIONS_READY) { | 256 if (type == chrome::NOTIFICATION_EXTENSIONS_READY) { |
256 Update(); | 257 Update(); |
257 return; | 258 return; |
258 } | 259 } |
259 ExtensionService* service = profile_->GetExtensionService(); | 260 ExtensionService* service = profile_->GetExtensionService(); |
260 if (!service || !service->is_ready()) | 261 if (!service || !service->is_ready()) |
261 return; | 262 return; |
262 | 263 |
263 switch (type.value) { | 264 switch (type) { |
264 case NotificationType::EXTENSION_LOADED: | 265 case chrome::NOTIFICATION_EXTENSION_LOADED: |
265 OnExtensionLoaded(Details<Extension>(details).ptr()); | 266 OnExtensionLoaded(Details<Extension>(details).ptr()); |
266 break; | 267 break; |
267 case NotificationType::EXTENSION_UNLOADED: | 268 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
268 OnExtensionUnloaded(Details<UnloadedExtensionInfo>(details)->extension); | 269 OnExtensionUnloaded(Details<UnloadedExtensionInfo>(details)->extension); |
269 break; | 270 break; |
270 default: | 271 default: |
271 NOTREACHED() << "Received unexpected notification"; | 272 NOTREACHED() << "Received unexpected notification"; |
272 } | 273 } |
273 } | 274 } |
274 | 275 |
275 void BackgroundApplicationListModel::SendApplicationDataChangedNotifications( | 276 void BackgroundApplicationListModel::SendApplicationDataChangedNotifications( |
276 const Extension* extension) { | 277 const Extension* extension) { |
277 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationDataChanged(extension, | 278 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationDataChanged(extension, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 (*old_cursor)->name() == (*new_cursor)->name() && | 316 (*old_cursor)->name() == (*new_cursor)->name() && |
316 (*old_cursor)->id() == (*new_cursor)->id()) { | 317 (*old_cursor)->id() == (*new_cursor)->id()) { |
317 ++old_cursor; | 318 ++old_cursor; |
318 ++new_cursor; | 319 ++new_cursor; |
319 } | 320 } |
320 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { | 321 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { |
321 extensions_ = extensions; | 322 extensions_ = extensions; |
322 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_)); | 323 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_)); |
323 } | 324 } |
324 } | 325 } |
OLD | NEW |