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