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