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

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 build errors Created 6 years, 2 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
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ref_counted_memory.h" 8 #include "base/memory/ref_counted_memory.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 ThemeService::~ThemeService() { 92 ThemeService::~ThemeService() {
93 FreePlatformCaches(); 93 FreePlatformCaches();
94 } 94 }
95 95
96 void ThemeService::Init(Profile* profile) { 96 void ThemeService::Init(Profile* profile) {
97 DCHECK(CalledOnValidThread()); 97 DCHECK(CalledOnValidThread());
98 profile_ = profile; 98 profile_ = profile;
99 99
100 LoadThemePrefs(); 100 LoadThemePrefs();
101 101
102 extension_registry_ = extensions::ExtensionRegistry::Get(profile_);
103
102 registrar_.Add(this, 104 registrar_.Add(this,
103 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, 105 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
104 content::Source<Profile>(profile_)); 106 content::Source<Profile>(profile_));
105 107
106 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); 108 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this));
107 } 109 }
108 110
109 gfx::Image ThemeService::GetImageNamed(int id) const { 111 gfx::Image ThemeService::GetImageNamed(int id) const {
110 DCHECK(CalledOnValidThread()); 112 DCHECK(CalledOnValidThread());
111 113
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 const content::NotificationSource& source, 247 const content::NotificationSource& source,
246 const content::NotificationDetails& details) { 248 const content::NotificationDetails& details) {
247 using content::Details; 249 using content::Details;
248 switch (type) { 250 switch (type) {
249 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: 251 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED:
250 registrar_.Remove(this, 252 registrar_.Remove(this,
251 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, 253 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
252 content::Source<Profile>(profile_)); 254 content::Source<Profile>(profile_));
253 OnExtensionServiceReady(); 255 OnExtensionServiceReady();
254 break; 256 break;
255 case extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED: {
256 // The theme may be initially disabled. Wait till it is loaded (if ever).
257 Details<const extensions::InstalledExtensionInfo> installed_details(
258 details);
259 if (installed_details->extension->is_theme())
260 installed_pending_load_id_ = installed_details->extension->id();
261 break;
262 }
263 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
264 const Extension* extension = Details<const Extension>(details).ptr();
265 if (extension->is_theme() &&
266 installed_pending_load_id_ != kDefaultThemeID &&
267 installed_pending_load_id_ == extension->id()) {
268 SetTheme(extension);
269 }
270 installed_pending_load_id_ = kDefaultThemeID;
271 break;
272 }
273 case extensions::NOTIFICATION_EXTENSION_ENABLED: { 257 case extensions::NOTIFICATION_EXTENSION_ENABLED: {
274 const Extension* extension = Details<const Extension>(details).ptr(); 258 const Extension* extension = Details<const Extension>(details).ptr();
275 if (extension->is_theme()) 259 if (extension->is_theme())
276 SetTheme(extension); 260 SetTheme(extension);
277 break; 261 break;
278 } 262 }
279 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
280 Details<const UnloadedExtensionInfo> unloaded_details(details);
281 if (unloaded_details->reason != UnloadedExtensionInfo::REASON_UPDATE &&
282 unloaded_details->extension->is_theme() &&
283 unloaded_details->extension->id() == GetThemeID()) {
284 UseDefaultTheme();
285 }
286 break;
287 }
288 } 263 }
289 } 264 }
290 265
266 void ThemeService::OnExtensionLoaded(content::BrowserContext* browser_context,
267 const extensions::Extension* extension) {
268 if (extension->is_theme() && installed_pending_load_id_ != kDefaultThemeID &&
269 installed_pending_load_id_ == extension->id()) {
270 SetTheme(extension);
271 }
272 installed_pending_load_id_ = kDefaultThemeID;
273 }
274
275 void ThemeService::OnExtensionUnloaded(
276 content::BrowserContext* browser_context,
277 const extensions::Extension* extension,
278 extensions::UnloadedExtensionInfo::Reason reason) {
279 if (reason != UnloadedExtensionInfo::REASON_UPDATE && extension->is_theme() &&
280 extension->id() == GetThemeID()) {
281 UseDefaultTheme();
282 }
283 }
284
285 void ThemeService::OnExtensionWillBeInstalled(
286 content::BrowserContext* browser_context,
287 const extensions::Extension* extension,
288 bool is_update,
289 bool from_ephemeral,
290 const std::string& old_name) {
291 // The theme may be initially disabled. Wait till it is loaded (if ever).
292 if (extension->is_theme())
293 installed_pending_load_id_ = extension->id();
294 }
295
296 void ThemeService::Shutdown() {
297 extension_registry_->RemoveObserver(this);
298 }
299
291 void ThemeService::SetTheme(const Extension* extension) { 300 void ThemeService::SetTheme(const Extension* extension) {
292 DCHECK(extension->is_theme()); 301 DCHECK(extension->is_theme());
293 ExtensionService* service = 302 ExtensionService* service =
294 extensions::ExtensionSystem::Get(profile_)->extension_service(); 303 extensions::ExtensionSystem::Get(profile_)->extension_service();
295 if (!service->IsExtensionEnabled(extension->id())) { 304 if (!service->IsExtensionEnabled(extension->id())) {
296 // |extension| is disabled when reverting to the previous theme via an 305 // |extension| is disabled when reverting to the previous theme via an
297 // infobar. 306 // infobar.
298 service->EnableExtension(extension->id()); 307 service->EnableExtension(extension->id());
299 // Enabling the extension will call back to SetTheme(). 308 // Enabling the extension will call back to SetTheme().
300 return; 309 return;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 // If the ThemeService is not ready yet, the custom theme data pack needs to 507 // If the ThemeService is not ready yet, the custom theme data pack needs to
499 // be recreated from the extension. 508 // be recreated from the extension.
500 MigrateTheme(); 509 MigrateTheme();
501 set_ready(); 510 set_ready();
502 511
503 // Send notification in case anyone requested data and cached it when the 512 // Send notification in case anyone requested data and cached it when the
504 // theme service was not ready yet. 513 // theme service was not ready yet.
505 NotifyThemeChanged(); 514 NotifyThemeChanged();
506 } 515 }
507 516
508 registrar_.Add( 517 extension_registry_->AddObserver(this);
509 this,
510 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
511 content::Source<Profile>(profile_));
512 registrar_.Add(this,
513 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
514 content::Source<Profile>(profile_));
515 registrar_.Add(this, 518 registrar_.Add(this,
516 extensions::NOTIFICATION_EXTENSION_ENABLED, 519 extensions::NOTIFICATION_EXTENSION_ENABLED,
517 content::Source<Profile>(profile_)); 520 content::Source<Profile>(profile_));
518 registrar_.Add(this,
519 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
520 content::Source<Profile>(profile_));
521 521
522 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, 522 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
523 base::Bind(&ThemeService::RemoveUnusedThemes, 523 base::Bind(&ThemeService::RemoveUnusedThemes,
524 weak_ptr_factory_.GetWeakPtr(), 524 weak_ptr_factory_.GetWeakPtr(),
525 false), 525 false),
526 base::TimeDelta::FromSeconds(kRemoveUnusedThemesStartupDelay)); 526 base::TimeDelta::FromSeconds(kRemoveUnusedThemesStartupDelay));
527 } 527 }
528 528
529 void ThemeService::MigrateTheme() { 529 void ThemeService::MigrateTheme() {
530 // TODO(erg): We need to pop up a dialog informing the user that their 530 // TODO(erg): We need to pop up a dialog informing the user that their
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 void ThemeService::OnInfobarDestroyed() { 603 void ThemeService::OnInfobarDestroyed() {
604 number_of_infobars_--; 604 number_of_infobars_--;
605 605
606 if (number_of_infobars_ == 0) 606 if (number_of_infobars_ == 0)
607 RemoveUnusedThemes(false); 607 RemoveUnusedThemes(false);
608 } 608 }
609 609
610 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { 610 ThemeSyncableService* ThemeService::GetThemeSyncableService() const {
611 return theme_syncable_service_.get(); 611 return theme_syncable_service_.get();
612 } 612 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698