OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
41 UTF8ToUTF16(x->name()), | 41 UTF8ToUTF16(x->name()), |
42 UTF8ToUTF16(y->name())); | 42 UTF8ToUTF16(y->name())); |
43 } | 43 } |
44 | 44 |
45 // Background application representation, private to the | 45 // Background application representation, private to the |
46 // BackgroundApplicationListModel class. | 46 // BackgroundApplicationListModel class. |
47 class BackgroundApplicationListModel::Application | 47 class BackgroundApplicationListModel::Application |
48 : public ImageLoadingTracker::Observer { | 48 : public ImageLoadingTracker::Observer { |
49 public: | 49 public: |
50 Application(BackgroundApplicationListModel* model, | 50 Application(BackgroundApplicationListModel* model, |
51 const Extension* an_extension); | 51 const Extension* an_extension, |
52 Profile* profile_); | |
52 | 53 |
53 virtual ~Application(); | 54 virtual ~Application(); |
54 | 55 |
55 // Invoked when a request icon is available. | 56 // Invoked when a request icon is available. |
56 virtual void OnImageLoaded(SkBitmap* image, | 57 virtual void OnImageLoaded(SkBitmap* image, |
57 const ExtensionResource& resource, | 58 const ExtensionResource& resource, |
58 int index); | 59 int index); |
59 | 60 |
60 // Uses the FILE thread to request this extension's icon, sized | 61 // Uses the FILE thread to request this extension's icon, sized |
61 // appropriately. | 62 // appropriately. |
62 void RequestIcon(Extension::Icons size); | 63 void RequestIcon(Extension::Icons size); |
63 | 64 |
64 const Extension* extension_; | 65 const Extension* extension_; |
65 scoped_ptr<SkBitmap> icon_; | 66 scoped_ptr<SkBitmap> icon_; |
66 BackgroundApplicationListModel* model_; | 67 BackgroundApplicationListModel* model_; |
67 ImageLoadingTracker tracker_; | 68 ImageLoadingTracker tracker_; |
69 Profile* profile_; | |
Andrew T Wilson (Slow)
2011/05/20 00:22:09
See my previous comment - do we really need to tra
rpetterson
2011/05/20 05:53:17
It doesn't pass back just to the BackgroundApplica
Andrew T Wilson (Slow)
2011/05/20 16:52:45
But BackgroundApplicationListModel::Application ne
| |
68 }; | 70 }; |
69 | 71 |
70 namespace { | 72 namespace { |
71 void GetServiceApplications(ExtensionService* service, | 73 void GetServiceApplications(ExtensionService* service, |
72 ExtensionList* applications_result) { | 74 ExtensionList* applications_result) { |
73 const ExtensionList* extensions = service->extensions(); | 75 const ExtensionList* extensions = service->extensions(); |
74 | 76 |
75 for (ExtensionList::const_iterator cursor = extensions->begin(); | 77 for (ExtensionList::const_iterator cursor = extensions->begin(); |
76 cursor != extensions->end(); | 78 cursor != extensions->end(); |
77 ++cursor) { | 79 ++cursor) { |
(...skipping 11 matching lines...) Expand all Loading... | |
89 | 91 |
90 bool HasBackgroundAppPermission( | 92 bool HasBackgroundAppPermission( |
91 const std::set<std::string>& api_permissions) { | 93 const std::set<std::string>& api_permissions) { |
92 return Extension::HasApiPermission( | 94 return Extension::HasApiPermission( |
93 api_permissions, Extension::kBackgroundPermission); | 95 api_permissions, Extension::kBackgroundPermission); |
94 } | 96 } |
95 } // namespace | 97 } // namespace |
96 | 98 |
97 void | 99 void |
98 BackgroundApplicationListModel::Observer::OnApplicationDataChanged( | 100 BackgroundApplicationListModel::Observer::OnApplicationDataChanged( |
99 const Extension* extension) { | 101 const Extension* extension, Profile* profile) { |
100 } | 102 } |
101 | 103 |
102 void | 104 void |
103 BackgroundApplicationListModel::Observer::OnApplicationListChanged() { | 105 BackgroundApplicationListModel::Observer::OnApplicationListChanged( |
106 Profile* profile) { | |
104 } | 107 } |
105 | 108 |
106 BackgroundApplicationListModel::Observer::~Observer() { | 109 BackgroundApplicationListModel::Observer::~Observer() { |
107 } | 110 } |
108 | 111 |
109 BackgroundApplicationListModel::Application::~Application() { | 112 BackgroundApplicationListModel::Application::~Application() { |
110 } | 113 } |
111 | 114 |
112 BackgroundApplicationListModel::Application::Application( | 115 BackgroundApplicationListModel::Application::Application( |
113 BackgroundApplicationListModel* model, | 116 BackgroundApplicationListModel* model, |
114 const Extension* extension) | 117 const Extension* extension, |
118 Profile* profile) | |
115 : extension_(extension), | 119 : extension_(extension), |
116 icon_(NULL), | 120 icon_(NULL), |
117 model_(model), | 121 model_(model), |
122 profile_(profile), | |
118 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { | 123 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { |
119 } | 124 } |
120 | 125 |
121 void BackgroundApplicationListModel::Application::OnImageLoaded( | 126 void BackgroundApplicationListModel::Application::OnImageLoaded( |
122 SkBitmap* image, | 127 SkBitmap* image, |
123 const ExtensionResource& resource, | 128 const ExtensionResource& resource, |
124 int index) { | 129 int index) { |
125 if (!image) | 130 if (!image) |
126 return; | 131 return; |
127 icon_.reset(new SkBitmap(*image)); | 132 icon_.reset(new SkBitmap(*image)); |
128 model_->OnApplicationDataChanged(extension_); | 133 model_->OnApplicationDataChanged(extension_, profile_); |
129 } | 134 } |
130 | 135 |
131 void BackgroundApplicationListModel::Application::RequestIcon( | 136 void BackgroundApplicationListModel::Application::RequestIcon( |
132 Extension::Icons size) { | 137 Extension::Icons size) { |
133 ExtensionResource resource = extension_->GetIconResource( | 138 ExtensionResource resource = extension_->GetIconResource( |
134 size, ExtensionIconSet::MATCH_BIGGER); | 139 size, ExtensionIconSet::MATCH_BIGGER); |
135 tracker_.LoadImage(extension_, resource, gfx::Size(size, size), | 140 tracker_.LoadImage(extension_, resource, gfx::Size(size, size), |
136 ImageLoadingTracker::CACHE); | 141 ImageLoadingTracker::CACHE); |
137 } | 142 } |
138 | 143 |
(...skipping 28 matching lines...) Expand all Loading... | |
167 DCHECK(IsBackgroundApp(*extension)); | 172 DCHECK(IsBackgroundApp(*extension)); |
168 Application* application = FindApplication(extension); | 173 Application* application = FindApplication(extension); |
169 if (!application) { | 174 if (!application) { |
170 // App position is used as a dynamic command and so must be less than any | 175 // App position is used as a dynamic command and so must be less than any |
171 // predefined command id. | 176 // predefined command id. |
172 if (applications_.size() >= IDC_MinimumLabelValue) { | 177 if (applications_.size() >= IDC_MinimumLabelValue) { |
173 LOG(ERROR) << "Background application limit of " << IDC_MinimumLabelValue | 178 LOG(ERROR) << "Background application limit of " << IDC_MinimumLabelValue |
174 << " exceeded. Ignoring."; | 179 << " exceeded. Ignoring."; |
175 return; | 180 return; |
176 } | 181 } |
177 application = new Application(this, extension); | 182 application = new Application(this, extension, profile_); |
178 applications_[extension->id()] = application; | 183 applications_[extension->id()] = application; |
179 application->RequestIcon(Extension::EXTENSION_ICON_BITTY); | 184 application->RequestIcon(Extension::EXTENSION_ICON_BITTY); |
180 } | 185 } |
181 } | 186 } |
182 | 187 |
183 void BackgroundApplicationListModel::DissociateApplicationData( | 188 void BackgroundApplicationListModel::DissociateApplicationData( |
184 const Extension* extension) { | 189 const Extension* extension) { |
185 ApplicationMap::iterator found = applications_.find(extension->id()); | 190 ApplicationMap::iterator found = applications_.find(extension->id()); |
186 if (found != applications_.end()) { | 191 if (found != applications_.end()) { |
187 delete found->second; | 192 delete found->second; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 break; | 262 break; |
258 case NotificationType::EXTENSION_UNLOADED: | 263 case NotificationType::EXTENSION_UNLOADED: |
259 OnExtensionUnloaded(Details<UnloadedExtensionInfo>(details)->extension); | 264 OnExtensionUnloaded(Details<UnloadedExtensionInfo>(details)->extension); |
260 break; | 265 break; |
261 default: | 266 default: |
262 NOTREACHED() << "Received unexpected notification"; | 267 NOTREACHED() << "Received unexpected notification"; |
263 } | 268 } |
264 } | 269 } |
265 | 270 |
266 void BackgroundApplicationListModel::OnApplicationDataChanged( | 271 void BackgroundApplicationListModel::OnApplicationDataChanged( |
267 const Extension* extension) { | 272 const Extension* extension, Profile* profile) { |
268 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationDataChanged(extension)); | 273 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationDataChanged(extension, |
274 profile)); | |
269 } | 275 } |
270 | 276 |
271 void BackgroundApplicationListModel::OnExtensionLoaded(Extension* extension) { | 277 void BackgroundApplicationListModel::OnExtensionLoaded(Extension* extension) { |
272 // We only care about extensions that are background applications | 278 // We only care about extensions that are background applications |
273 if (!IsBackgroundApp(*extension)) | 279 if (!IsBackgroundApp(*extension)) |
274 return; | 280 return; |
275 AssociateApplicationData(extension); | 281 AssociateApplicationData(extension); |
276 Update(); | 282 Update(); |
277 } | 283 } |
278 | 284 |
(...skipping 24 matching lines...) Expand all Loading... | |
303 ExtensionList::const_iterator new_cursor = extensions.begin(); | 309 ExtensionList::const_iterator new_cursor = extensions.begin(); |
304 while (old_cursor != extensions_.end() && | 310 while (old_cursor != extensions_.end() && |
305 new_cursor != extensions.end() && | 311 new_cursor != extensions.end() && |
306 (*old_cursor)->name() == (*new_cursor)->name() && | 312 (*old_cursor)->name() == (*new_cursor)->name() && |
307 (*old_cursor)->id() == (*new_cursor)->id()) { | 313 (*old_cursor)->id() == (*new_cursor)->id()) { |
308 ++old_cursor; | 314 ++old_cursor; |
309 ++new_cursor; | 315 ++new_cursor; |
310 } | 316 } |
311 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { | 317 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { |
312 extensions_ = extensions; | 318 extensions_ = extensions; |
313 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged()); | 319 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_)); |
314 } | 320 } |
315 } | 321 } |
OLD | NEW |