| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 10 #include "base/stl_util.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_contents_service.h" | 13 #include "chrome/browser/background/background_contents_service.h" |
| 14 #include "chrome/browser/background/background_contents_service_factory.h" | 14 #include "chrome/browser/background/background_contents_service_factory.h" |
| 15 #include "chrome/browser/background/background_mode_manager.h" | 15 #include "chrome/browser/background/background_mode_manager.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/extensions/extension_prefs.h" | 17 #include "chrome/browser/extensions/extension_prefs.h" |
| 18 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/extensions/image_loading_tracker.h" | 19 #include "chrome/browser/extensions/extension_system.h" |
| 20 #include "chrome/browser/extensions/image_loader.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
| 22 #include "chrome/common/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
| 23 #include "chrome/common/extensions/extension_constants.h" | 24 #include "chrome/common/extensions/extension_constants.h" |
| 24 #include "chrome/common/extensions/extension_icon_set.h" | 25 #include "chrome/common/extensions/extension_icon_set.h" |
| 25 #include "chrome/common/extensions/extension_resource.h" | 26 #include "chrome/common/extensions/extension_resource.h" |
| 26 #include "chrome/common/extensions/permissions/permission_set.h" | 27 #include "chrome/common/extensions/permissions/permission_set.h" |
| 27 #include "content/public/browser/notification_details.h" | 28 #include "content/public/browser/notification_details.h" |
| 28 #include "content/public/browser/notification_source.h" | 29 #include "content/public/browser/notification_source.h" |
| 29 #include "ui/base/l10n/l10n_util_collator.h" | 30 #include "ui/base/l10n/l10n_util_collator.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 53 bool ExtensionNameComparator::operator()(const Extension* x, | 54 bool ExtensionNameComparator::operator()(const Extension* x, |
| 54 const Extension* y) { | 55 const Extension* y) { |
| 55 return l10n_util::StringComparator<string16>(collator_)( | 56 return l10n_util::StringComparator<string16>(collator_)( |
| 56 UTF8ToUTF16(x->name()), | 57 UTF8ToUTF16(x->name()), |
| 57 UTF8ToUTF16(y->name())); | 58 UTF8ToUTF16(y->name())); |
| 58 } | 59 } |
| 59 | 60 |
| 60 // Background application representation, private to the | 61 // Background application representation, private to the |
| 61 // BackgroundApplicationListModel class. | 62 // BackgroundApplicationListModel class. |
| 62 class BackgroundApplicationListModel::Application | 63 class BackgroundApplicationListModel::Application |
| 63 : public ImageLoadingTracker::Observer { | 64 : public base::SupportsWeakPtr<Application> { |
| 64 public: | 65 public: |
| 65 Application(BackgroundApplicationListModel* model, | 66 Application(BackgroundApplicationListModel* model, |
| 66 const Extension* an_extension); | 67 const Extension* an_extension); |
| 67 | 68 |
| 68 virtual ~Application(); | 69 virtual ~Application(); |
| 69 | 70 |
| 70 // Invoked when a request icon is available. | 71 // Invoked when a request icon is available. |
| 71 virtual void OnImageLoaded(const gfx::Image& image, | 72 void OnImageLoaded(const gfx::Image& image); |
| 72 const std::string& extension_id, | |
| 73 int index) OVERRIDE; | |
| 74 | 73 |
| 75 // Uses the FILE thread to request this extension's icon, sized | 74 // Uses the FILE thread to request this extension's icon, sized |
| 76 // appropriately. | 75 // appropriately. |
| 77 void RequestIcon(extension_misc::ExtensionIcons size); | 76 void RequestIcon(extension_misc::ExtensionIcons size); |
| 78 | 77 |
| 79 const Extension* extension_; | 78 const Extension* extension_; |
| 80 scoped_ptr<gfx::ImageSkia> icon_; | 79 scoped_ptr<gfx::ImageSkia> icon_; |
| 81 BackgroundApplicationListModel* model_; | 80 BackgroundApplicationListModel* model_; |
| 82 ImageLoadingTracker tracker_; | |
| 83 }; | 81 }; |
| 84 | 82 |
| 85 namespace { | 83 namespace { |
| 86 void GetServiceApplications(ExtensionService* service, | 84 void GetServiceApplications(ExtensionService* service, |
| 87 ExtensionList* applications_result) { | 85 ExtensionList* applications_result) { |
| 88 const ExtensionSet* extensions = service->extensions(); | 86 const ExtensionSet* extensions = service->extensions(); |
| 89 | 87 |
| 90 for (ExtensionSet::const_iterator cursor = extensions->begin(); | 88 for (ExtensionSet::const_iterator cursor = extensions->begin(); |
| 91 cursor != extensions->end(); | 89 cursor != extensions->end(); |
| 92 ++cursor) { | 90 ++cursor) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } | 132 } |
| 135 | 133 |
| 136 BackgroundApplicationListModel::Application::~Application() { | 134 BackgroundApplicationListModel::Application::~Application() { |
| 137 } | 135 } |
| 138 | 136 |
| 139 BackgroundApplicationListModel::Application::Application( | 137 BackgroundApplicationListModel::Application::Application( |
| 140 BackgroundApplicationListModel* model, | 138 BackgroundApplicationListModel* model, |
| 141 const Extension* extension) | 139 const Extension* extension) |
| 142 : extension_(extension), | 140 : extension_(extension), |
| 143 icon_(NULL), | 141 icon_(NULL), |
| 144 model_(model), | 142 model_(model) { |
| 145 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { | |
| 146 } | 143 } |
| 147 | 144 |
| 148 void BackgroundApplicationListModel::Application::OnImageLoaded( | 145 void BackgroundApplicationListModel::Application::OnImageLoaded( |
| 149 const gfx::Image& image, | 146 const gfx::Image& image) { |
| 150 const std::string& extension_id, | |
| 151 int index) { | |
| 152 if (image.IsEmpty()) | 147 if (image.IsEmpty()) |
| 153 return; | 148 return; |
| 154 icon_.reset(image.CopyImageSkia()); | 149 icon_.reset(image.CopyImageSkia()); |
| 155 model_->SendApplicationDataChangedNotifications(extension_); | 150 model_->SendApplicationDataChangedNotifications(extension_); |
| 156 } | 151 } |
| 157 | 152 |
| 158 void BackgroundApplicationListModel::Application::RequestIcon( | 153 void BackgroundApplicationListModel::Application::RequestIcon( |
| 159 extension_misc::ExtensionIcons size) { | 154 extension_misc::ExtensionIcons size) { |
| 160 ExtensionResource resource = extension_->GetIconResource( | 155 ExtensionResource resource = extension_->GetIconResource( |
| 161 size, ExtensionIconSet::MATCH_BIGGER); | 156 size, ExtensionIconSet::MATCH_BIGGER); |
| 162 tracker_.LoadImage(extension_, resource, gfx::Size(size, size), | 157 extensions::ExtensionSystem::Get(model_->profile_)-> |
| 163 ImageLoadingTracker::CACHE); | 158 image_loader()->LoadImageAsync( |
| 159 extension_, resource, gfx::Size(size, size), |
| 160 base::Bind(&Application::OnImageLoaded, AsWeakPtr())); |
| 164 } | 161 } |
| 165 | 162 |
| 166 BackgroundApplicationListModel::~BackgroundApplicationListModel() { | 163 BackgroundApplicationListModel::~BackgroundApplicationListModel() { |
| 167 STLDeleteContainerPairSecondPointers(applications_.begin(), | 164 STLDeleteContainerPairSecondPointers(applications_.begin(), |
| 168 applications_.end()); | 165 applications_.end()); |
| 169 } | 166 } |
| 170 | 167 |
| 171 BackgroundApplicationListModel::BackgroundApplicationListModel(Profile* profile) | 168 BackgroundApplicationListModel::BackgroundApplicationListModel(Profile* profile) |
| 172 : profile_(profile) { | 169 : profile_(profile) { |
| 173 DCHECK(profile_); | 170 DCHECK(profile_); |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 (*old_cursor)->name() == (*new_cursor)->name() && | 406 (*old_cursor)->name() == (*new_cursor)->name() && |
| 410 (*old_cursor)->id() == (*new_cursor)->id()) { | 407 (*old_cursor)->id() == (*new_cursor)->id()) { |
| 411 ++old_cursor; | 408 ++old_cursor; |
| 412 ++new_cursor; | 409 ++new_cursor; |
| 413 } | 410 } |
| 414 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { | 411 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { |
| 415 extensions_ = extensions; | 412 extensions_ = extensions; |
| 416 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_)); | 413 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_)); |
| 417 } | 414 } |
| 418 } | 415 } |
| OLD | NEW |