Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: chrome/browser/background/background_application_list_model.cc

Issue 11365181: Remove GetExtensionService from Profile. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: replace missing extension_system include Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/extension_system.h"
19 #include "chrome/browser/extensions/image_loader.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"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 content::Source<Profile>(profile)); 175 content::Source<Profile>(profile));
175 registrar_.Add(this, 176 registrar_.Add(this,
176 chrome::NOTIFICATION_EXTENSIONS_READY, 177 chrome::NOTIFICATION_EXTENSIONS_READY,
177 content::Source<Profile>(profile)); 178 content::Source<Profile>(profile));
178 registrar_.Add(this, 179 registrar_.Add(this,
179 chrome::NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED, 180 chrome::NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED,
180 content::Source<Profile>(profile)); 181 content::Source<Profile>(profile));
181 registrar_.Add(this, 182 registrar_.Add(this,
182 chrome::NOTIFICATION_BACKGROUND_CONTENTS_SERVICE_CHANGED, 183 chrome::NOTIFICATION_BACKGROUND_CONTENTS_SERVICE_CHANGED,
183 content::Source<Profile>(profile)); 184 content::Source<Profile>(profile));
184 ExtensionService* service = profile->GetExtensionService(); 185 ExtensionService* service = extensions::ExtensionSystem::Get(profile)->
186 extension_service();
185 if (service && service->is_ready()) 187 if (service && service->is_ready())
186 Update(); 188 Update();
187 } 189 }
188 190
189 void BackgroundApplicationListModel::AddObserver(Observer* observer) { 191 void BackgroundApplicationListModel::AddObserver(Observer* observer) {
190 observers_.AddObserver(observer); 192 observers_.AddObserver(observer);
191 } 193 }
192 194
193 void BackgroundApplicationListModel::AssociateApplicationData( 195 void BackgroundApplicationListModel::AssociateApplicationData(
194 const Extension* extension) { 196 const Extension* extension) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 } 307 }
306 308
307 void BackgroundApplicationListModel::Observe( 309 void BackgroundApplicationListModel::Observe(
308 int type, 310 int type,
309 const content::NotificationSource& source, 311 const content::NotificationSource& source,
310 const content::NotificationDetails& details) { 312 const content::NotificationDetails& details) {
311 if (type == chrome::NOTIFICATION_EXTENSIONS_READY) { 313 if (type == chrome::NOTIFICATION_EXTENSIONS_READY) {
312 Update(); 314 Update();
313 return; 315 return;
314 } 316 }
315 ExtensionService* service = profile_->GetExtensionService(); 317 ExtensionService* service = extensions::ExtensionSystem::Get(profile_)->
318 extension_service();
316 if (!service || !service->is_ready()) 319 if (!service || !service->is_ready())
317 return; 320 return;
318 321
319 switch (type) { 322 switch (type) {
320 case chrome::NOTIFICATION_EXTENSION_LOADED: 323 case chrome::NOTIFICATION_EXTENSION_LOADED:
321 OnExtensionLoaded(content::Details<Extension>(details).ptr()); 324 OnExtensionLoaded(content::Details<Extension>(details).ptr());
322 break; 325 break;
323 case chrome::NOTIFICATION_EXTENSION_UNLOADED: 326 case chrome::NOTIFICATION_EXTENSION_UNLOADED:
324 OnExtensionUnloaded( 327 OnExtensionUnloaded(
325 content::Details<UnloadedExtensionInfo>(details)->extension); 328 content::Details<UnloadedExtensionInfo>(details)->extension);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 387
385 void BackgroundApplicationListModel::RemoveObserver(Observer* observer) { 388 void BackgroundApplicationListModel::RemoveObserver(Observer* observer) {
386 observers_.RemoveObserver(observer); 389 observers_.RemoveObserver(observer);
387 } 390 }
388 391
389 // Update queries the extensions service of the profile with which the model was 392 // Update queries the extensions service of the profile with which the model was
390 // initialized to determine the current set of background applications. If that 393 // initialized to determine the current set of background applications. If that
391 // differs from the old list, it generates OnApplicationListChanged events for 394 // differs from the old list, it generates OnApplicationListChanged events for
392 // each observer. 395 // each observer.
393 void BackgroundApplicationListModel::Update() { 396 void BackgroundApplicationListModel::Update() {
394 ExtensionService* service = profile_->GetExtensionService(); 397 ExtensionService* service = extensions::ExtensionSystem::Get(profile_)->
398 extension_service();
395 399
396 // Discover current background applications, compare with previous list, which 400 // Discover current background applications, compare with previous list, which
397 // is consistently sorted, and notify observers if they differ. 401 // is consistently sorted, and notify observers if they differ.
398 ExtensionList extensions; 402 ExtensionList extensions;
399 GetServiceApplications(service, &extensions); 403 GetServiceApplications(service, &extensions);
400 ExtensionList::const_iterator old_cursor = extensions_.begin(); 404 ExtensionList::const_iterator old_cursor = extensions_.begin();
401 ExtensionList::const_iterator new_cursor = extensions.begin(); 405 ExtensionList::const_iterator new_cursor = extensions.begin();
402 while (old_cursor != extensions_.end() && 406 while (old_cursor != extensions_.end() &&
403 new_cursor != extensions.end() && 407 new_cursor != extensions.end() &&
404 (*old_cursor)->name() == (*new_cursor)->name() && 408 (*old_cursor)->name() == (*new_cursor)->name() &&
405 (*old_cursor)->id() == (*new_cursor)->id()) { 409 (*old_cursor)->id() == (*new_cursor)->id()) {
406 ++old_cursor; 410 ++old_cursor;
407 ++new_cursor; 411 ++new_cursor;
408 } 412 }
409 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { 413 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) {
410 extensions_ = extensions; 414 extensions_ = extensions;
411 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_)); 415 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_));
412 } 416 }
413 } 417 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698