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

Side by Side Diff: chrome/browser/themes/theme_service.cc

Issue 566573004: Remove deprecated extension notification from themeservice. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unittest failed Created 5 years, 10 months 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
« no previous file with comments | « chrome/browser/themes/theme_service.h ('k') | chrome/browser/themes/theme_service_factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/themes/theme_service.h" 5 #include "chrome/browser/themes/theme_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 95 }
96 96
97 } // namespace 97 } // namespace
98 98
99 ThemeService::ThemeService() 99 ThemeService::ThemeService()
100 : ready_(false), 100 : ready_(false),
101 rb_(ResourceBundle::GetSharedInstance()), 101 rb_(ResourceBundle::GetSharedInstance()),
102 profile_(NULL), 102 profile_(NULL),
103 installed_pending_load_id_(kDefaultThemeID), 103 installed_pending_load_id_(kDefaultThemeID),
104 number_of_infobars_(0), 104 number_of_infobars_(0),
105 extension_registry_(NULL),
105 weak_ptr_factory_(this) { 106 weak_ptr_factory_(this) {
106 } 107 }
107 108
108 ThemeService::~ThemeService() { 109 ThemeService::~ThemeService() {
109 FreePlatformCaches(); 110 FreePlatformCaches();
110 } 111 }
111 112
112 void ThemeService::Init(Profile* profile) { 113 void ThemeService::Init(Profile* profile) {
113 DCHECK(CalledOnValidThread()); 114 DCHECK(CalledOnValidThread());
114 profile_ = profile; 115 profile_ = profile;
115 116
116 LoadThemePrefs(); 117 LoadThemePrefs();
117 118
119 extension_registry_ = extensions::ExtensionRegistry::Get(profile_);
120
118 registrar_.Add(this, 121 registrar_.Add(this,
119 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, 122 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
120 content::Source<Profile>(profile_)); 123 content::Source<Profile>(profile_));
121 124
122 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); 125 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this));
123 } 126 }
124 127
125 gfx::Image ThemeService::GetImageNamed(int id) const { 128 gfx::Image ThemeService::GetImageNamed(int id) const {
126 DCHECK(CalledOnValidThread()); 129 DCHECK(CalledOnValidThread());
127 130
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 const content::NotificationSource& source, 264 const content::NotificationSource& source,
262 const content::NotificationDetails& details) { 265 const content::NotificationDetails& details) {
263 using content::Details; 266 using content::Details;
264 switch (type) { 267 switch (type) {
265 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: 268 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED:
266 registrar_.Remove(this, 269 registrar_.Remove(this,
267 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, 270 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
268 content::Source<Profile>(profile_)); 271 content::Source<Profile>(profile_));
269 OnExtensionServiceReady(); 272 OnExtensionServiceReady();
270 break; 273 break;
271 case extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED: {
272 // The theme may be initially disabled. Wait till it is loaded (if ever).
273 Details<const extensions::InstalledExtensionInfo> installed_details(
274 details);
275 if (installed_details->extension->is_theme())
276 installed_pending_load_id_ = installed_details->extension->id();
277 break;
278 }
279 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
280 const Extension* extension = Details<const Extension>(details).ptr();
281 if (extension->is_theme() &&
282 installed_pending_load_id_ != kDefaultThemeID &&
283 installed_pending_load_id_ == extension->id()) {
284 SetTheme(extension);
285 }
286 installed_pending_load_id_ = kDefaultThemeID;
287 break;
288 }
289 case extensions::NOTIFICATION_EXTENSION_ENABLED: { 274 case extensions::NOTIFICATION_EXTENSION_ENABLED: {
290 const Extension* extension = Details<const Extension>(details).ptr(); 275 const Extension* extension = Details<const Extension>(details).ptr();
291 if (extension->is_theme()) 276 if (extension->is_theme())
292 SetTheme(extension); 277 SetTheme(extension);
293 break; 278 break;
294 } 279 }
295 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
296 Details<const UnloadedExtensionInfo> unloaded_details(details);
297 if (unloaded_details->reason != UnloadedExtensionInfo::REASON_UPDATE &&
298 unloaded_details->reason != UnloadedExtensionInfo::REASON_LOCK_ALL &&
299 unloaded_details->extension->is_theme() &&
300 unloaded_details->extension->id() == GetThemeID()) {
301 UseDefaultTheme();
302 }
303 break;
304 }
305 } 280 }
306 } 281 }
307 282
283 void ThemeService::OnExtensionLoaded(content::BrowserContext* browser_context,
284 const extensions::Extension* extension) {
285 if (extension->is_theme() && installed_pending_load_id_ != kDefaultThemeID &&
286 installed_pending_load_id_ == extension->id()) {
287 SetTheme(extension);
288 }
289 installed_pending_load_id_ = kDefaultThemeID;
290 }
291
292 void ThemeService::OnExtensionUnloaded(
293 content::BrowserContext* browser_context,
294 const extensions::Extension* extension,
295 extensions::UnloadedExtensionInfo::Reason reason) {
296 if (reason != UnloadedExtensionInfo::REASON_UPDATE && extension->is_theme() &&
297 extension->id() == GetThemeID()) {
298 UseDefaultTheme();
299 }
300 }
301
302 void ThemeService::OnExtensionWillBeInstalled(
303 content::BrowserContext* browser_context,
304 const extensions::Extension* extension,
305 bool is_update,
306 bool from_ephemeral,
307 const std::string& old_name) {
308 // The theme may be initially disabled. Wait till it is loaded (if ever).
309 if (extension->is_theme())
310 installed_pending_load_id_ = extension->id();
311 }
312
313 void ThemeService::Shutdown() {
314 extension_registry_->RemoveObserver(this);
315 }
316
308 void ThemeService::SetTheme(const Extension* extension) { 317 void ThemeService::SetTheme(const Extension* extension) {
309 DCHECK(extension->is_theme()); 318 DCHECK(extension->is_theme());
310 ExtensionService* service = 319 ExtensionService* service =
311 extensions::ExtensionSystem::Get(profile_)->extension_service(); 320 extensions::ExtensionSystem::Get(profile_)->extension_service();
312 if (!service->IsExtensionEnabled(extension->id())) { 321 if (!service->IsExtensionEnabled(extension->id())) {
313 // |extension| is disabled when reverting to the previous theme via an 322 // |extension| is disabled when reverting to the previous theme via an
314 // infobar. 323 // infobar.
315 service->EnableExtension(extension->id()); 324 service->EnableExtension(extension->id());
316 // Enabling the extension will call back to SetTheme(). 325 // Enabling the extension will call back to SetTheme().
317 return; 326 return;
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 // If the ThemeService is not ready yet, the custom theme data pack needs to 531 // If the ThemeService is not ready yet, the custom theme data pack needs to
523 // be recreated from the extension. 532 // be recreated from the extension.
524 MigrateTheme(); 533 MigrateTheme();
525 set_ready(); 534 set_ready();
526 535
527 // Send notification in case anyone requested data and cached it when the 536 // Send notification in case anyone requested data and cached it when the
528 // theme service was not ready yet. 537 // theme service was not ready yet.
529 NotifyThemeChanged(); 538 NotifyThemeChanged();
530 } 539 }
531 540
532 registrar_.Add( 541 extension_registry_->AddObserver(this);
533 this,
534 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
535 content::Source<Profile>(profile_));
536 registrar_.Add(this,
537 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
538 content::Source<Profile>(profile_));
539 registrar_.Add(this, 542 registrar_.Add(this,
540 extensions::NOTIFICATION_EXTENSION_ENABLED, 543 extensions::NOTIFICATION_EXTENSION_ENABLED,
541 content::Source<Profile>(profile_)); 544 content::Source<Profile>(profile_));
542 registrar_.Add(this,
543 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
544 content::Source<Profile>(profile_));
545 545
546 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, 546 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
547 base::Bind(&ThemeService::RemoveUnusedThemes, 547 base::Bind(&ThemeService::RemoveUnusedThemes,
548 weak_ptr_factory_.GetWeakPtr(), 548 weak_ptr_factory_.GetWeakPtr(),
549 false), 549 false),
550 base::TimeDelta::FromSeconds(kRemoveUnusedThemesStartupDelay)); 550 base::TimeDelta::FromSeconds(kRemoveUnusedThemesStartupDelay));
551 } 551 }
552 552
553 void ThemeService::MigrateTheme() { 553 void ThemeService::MigrateTheme() {
554 // TODO(erg): We need to pop up a dialog informing the user that their 554 // TODO(erg): We need to pop up a dialog informing the user that their
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 void ThemeService::OnInfobarDestroyed() { 629 void ThemeService::OnInfobarDestroyed() {
630 number_of_infobars_--; 630 number_of_infobars_--;
631 631
632 if (number_of_infobars_ == 0) 632 if (number_of_infobars_ == 0)
633 RemoveUnusedThemes(false); 633 RemoveUnusedThemes(false);
634 } 634 }
635 635
636 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { 636 ThemeSyncableService* ThemeService::GetThemeSyncableService() const {
637 return theme_syncable_service_.get(); 637 return theme_syncable_service_.get();
638 } 638 }
OLDNEW
« no previous file with comments | « chrome/browser/themes/theme_service.h ('k') | chrome/browser/themes/theme_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698