OLD | NEW |
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/background_application_list_model.h" | 5 #include "chrome/browser/background_application_list_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "app/l10n_util_collator.h" | 9 #include "app/l10n_util_collator.h" |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 NotificationType type, | 235 NotificationType type, |
236 const NotificationSource& source, | 236 const NotificationSource& source, |
237 const NotificationDetails& details) { | 237 const NotificationDetails& details) { |
238 if (type == NotificationType::EXTENSIONS_READY) { | 238 if (type == NotificationType::EXTENSIONS_READY) { |
239 Update(); | 239 Update(); |
240 return; | 240 return; |
241 } | 241 } |
242 ExtensionsService* service = profile_->GetExtensionsService(); | 242 ExtensionsService* service = profile_->GetExtensionsService(); |
243 if (!service || !service->is_ready()) | 243 if (!service || !service->is_ready()) |
244 return; | 244 return; |
| 245 |
245 switch (type.value) { | 246 switch (type.value) { |
246 case NotificationType::EXTENSION_LOADED: | 247 case NotificationType::EXTENSION_LOADED: |
247 OnExtensionLoaded(Details<Extension>(details).ptr()); | 248 OnExtensionLoaded(Details<Extension>(details).ptr()); |
248 break; | 249 break; |
249 case NotificationType::EXTENSION_UNLOADED: | 250 case NotificationType::EXTENSION_UNLOADED: |
250 // Handle extension unload uniformly, falling through to next case. | 251 // Handle extension unload uniformly, falling through to next case. |
251 case NotificationType::EXTENSION_UNLOADED_DISABLED: | 252 case NotificationType::EXTENSION_UNLOADED_DISABLED: |
252 OnExtensionUnloaded(Details<Extension>(details).ptr()); | 253 OnExtensionUnloaded(Details<Extension>(details).ptr()); |
253 break; | 254 break; |
254 default: | 255 default: |
(...skipping 24 matching lines...) Expand all Loading... |
279 void BackgroundApplicationListModel::RemoveObserver(Observer* observer) { | 280 void BackgroundApplicationListModel::RemoveObserver(Observer* observer) { |
280 observers_.RemoveObserver(observer); | 281 observers_.RemoveObserver(observer); |
281 } | 282 } |
282 | 283 |
283 // Update queries the extensions service of the profile with which the model was | 284 // Update queries the extensions service of the profile with which the model was |
284 // initialized to determine the current set of background applications. If that | 285 // initialized to determine the current set of background applications. If that |
285 // differs from the old list, it generates OnApplicationListChanged events for | 286 // differs from the old list, it generates OnApplicationListChanged events for |
286 // each observer. | 287 // each observer. |
287 void BackgroundApplicationListModel::Update() { | 288 void BackgroundApplicationListModel::Update() { |
288 ExtensionsService* service = profile_->GetExtensionsService(); | 289 ExtensionsService* service = profile_->GetExtensionsService(); |
289 DCHECK(service->is_ready()); | |
290 | 290 |
291 // Discover current background applications, compare with previous list, which | 291 // Discover current background applications, compare with previous list, which |
292 // is consistently sorted, and notify observers if they differ. | 292 // is consistently sorted, and notify observers if they differ. |
293 ExtensionList extensions; | 293 ExtensionList extensions; |
294 GetServiceApplications(service, &extensions); | 294 GetServiceApplications(service, &extensions); |
295 ExtensionList::const_iterator old_cursor = extensions_.begin(); | 295 ExtensionList::const_iterator old_cursor = extensions_.begin(); |
296 ExtensionList::const_iterator new_cursor = extensions.begin(); | 296 ExtensionList::const_iterator new_cursor = extensions.begin(); |
297 while (old_cursor != extensions_.end() && | 297 while (old_cursor != extensions_.end() && |
298 new_cursor != extensions.end() && | 298 new_cursor != extensions.end() && |
299 (*old_cursor)->name() == (*new_cursor)->name() && | 299 (*old_cursor)->name() == (*new_cursor)->name() && |
300 (*old_cursor)->id() == (*new_cursor)->id()) { | 300 (*old_cursor)->id() == (*new_cursor)->id()) { |
301 ++old_cursor; | 301 ++old_cursor; |
302 ++new_cursor; | 302 ++new_cursor; |
303 } | 303 } |
304 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { | 304 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { |
305 extensions_ = extensions; | 305 extensions_ = extensions; |
306 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged()); | 306 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged()); |
307 } | 307 } |
308 } | 308 } |
OLD | NEW |