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