Chromium Code Reviews| 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/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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 } | 79 } |
| 80 | 80 |
| 81 } // namespace | 81 } // namespace |
| 82 | 82 |
| 83 ThemeService::ThemeService() | 83 ThemeService::ThemeService() |
| 84 : ready_(false), | 84 : ready_(false), |
| 85 rb_(ResourceBundle::GetSharedInstance()), | 85 rb_(ResourceBundle::GetSharedInstance()), |
| 86 profile_(NULL), | 86 profile_(NULL), |
| 87 installed_pending_load_id_(kDefaultThemeID), | 87 installed_pending_load_id_(kDefaultThemeID), |
| 88 number_of_infobars_(0), | 88 number_of_infobars_(0), |
| 89 extension_registry_(NULL), | |
| 89 weak_ptr_factory_(this) { | 90 weak_ptr_factory_(this) { |
| 90 } | 91 } |
| 91 | 92 |
| 92 ThemeService::~ThemeService() { | 93 ThemeService::~ThemeService() { |
| 93 FreePlatformCaches(); | 94 FreePlatformCaches(); |
| 94 } | 95 } |
| 95 | 96 |
| 96 void ThemeService::Init(Profile* profile) { | 97 void ThemeService::Init(Profile* profile) { |
| 97 DCHECK(CalledOnValidThread()); | 98 DCHECK(CalledOnValidThread()); |
| 98 profile_ = profile; | 99 profile_ = profile; |
| 99 | 100 |
| 100 LoadThemePrefs(); | 101 LoadThemePrefs(); |
| 101 | 102 |
| 103 extension_registry_ = extensions::ExtensionRegistry::Get(profile_); | |
| 104 | |
| 102 registrar_.Add(this, | 105 registrar_.Add(this, |
| 103 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, | 106 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
| 104 content::Source<Profile>(profile_)); | 107 content::Source<Profile>(profile_)); |
| 105 | 108 |
| 106 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); | 109 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); |
| 107 } | 110 } |
| 108 | 111 |
| 109 gfx::Image ThemeService::GetImageNamed(int id) const { | 112 gfx::Image ThemeService::GetImageNamed(int id) const { |
| 110 DCHECK(CalledOnValidThread()); | 113 DCHECK(CalledOnValidThread()); |
| 111 | 114 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 const content::NotificationSource& source, | 248 const content::NotificationSource& source, |
| 246 const content::NotificationDetails& details) { | 249 const content::NotificationDetails& details) { |
| 247 using content::Details; | 250 using content::Details; |
| 248 switch (type) { | 251 switch (type) { |
| 249 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: | 252 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: |
| 250 registrar_.Remove(this, | 253 registrar_.Remove(this, |
| 251 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, | 254 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
| 252 content::Source<Profile>(profile_)); | 255 content::Source<Profile>(profile_)); |
| 253 OnExtensionServiceReady(); | 256 OnExtensionServiceReady(); |
| 254 break; | 257 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: { | 258 case extensions::NOTIFICATION_EXTENSION_ENABLED: { |
| 274 const Extension* extension = Details<const Extension>(details).ptr(); | 259 const Extension* extension = Details<const Extension>(details).ptr(); |
| 275 if (extension->is_theme()) | 260 if (extension->is_theme()) |
| 276 SetTheme(extension); | 261 SetTheme(extension); |
| 277 break; | 262 break; |
| 278 } | 263 } |
| 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 } | 264 } |
| 289 } | 265 } |
| 290 | 266 |
| 267 void ThemeService::OnExtensionLoaded(content::BrowserContext* browser_context, | |
| 268 const extensions::Extension* extension) { | |
| 269 if (extension->is_theme() && | |
| 270 installed_pending_load_id_ != kDefaultThemeID && | |
| 271 installed_pending_load_id_ == extension->id()) { | |
| 272 SetTheme(extension); | |
| 273 } | |
| 274 installed_pending_load_id_ = kDefaultThemeID; | |
| 275 } | |
| 276 | |
| 277 void ThemeService::OnExtensionUnloaded( | |
| 278 content::BrowserContext* browser_context, | |
| 279 const extensions::Extension* extension, | |
| 280 extensions::UnloadedExtensionInfo::Reason reason) { | |
| 281 if (reason != UnloadedExtensionInfo::REASON_UPDATE && extension->is_theme() && | |
|
Bernhard Bauer
2014/10/15 13:21:04
Also here please, and below. The original code in
Jitu( very slow this week)
2014/10/15 14:19:06
In original code in Observe(), it is casting the d
Bernhard Bauer
2014/10/15 14:23:27
I was referring to the formatting. The original co
| |
| 282 extension->id() == GetThemeID()) { | |
| 283 UseDefaultTheme(); | |
| 284 } | |
| 285 } | |
| 286 | |
| 287 void ThemeService::OnExtensionWillBeInstalled( | |
| 288 content::BrowserContext* browser_context, | |
| 289 const extensions::Extension* extension, | |
| 290 bool is_update, | |
| 291 bool from_ephemeral, | |
| 292 const std::string& old_name) { | |
| 293 // The theme may be initially disabled. Wait till it is loaded (if ever). | |
| 294 if (extension->is_theme()) | |
| 295 installed_pending_load_id_ = extension->id(); | |
| 296 } | |
| 297 | |
| 298 void ThemeService::Shutdown() { | |
| 299 if (extension_registry_) { | |
|
Jitu( very slow this week)
2014/10/15 14:19:06
Removed the check
| |
| 300 extension_registry_->RemoveObserver(this); | |
| 301 extension_registry_ = NULL; | |
| 302 } | |
| 303 } | |
| 304 | |
| 291 void ThemeService::SetTheme(const Extension* extension) { | 305 void ThemeService::SetTheme(const Extension* extension) { |
| 292 DCHECK(extension->is_theme()); | 306 DCHECK(extension->is_theme()); |
| 293 ExtensionService* service = | 307 ExtensionService* service = |
| 294 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 308 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 295 if (!service->IsExtensionEnabled(extension->id())) { | 309 if (!service->IsExtensionEnabled(extension->id())) { |
| 296 // |extension| is disabled when reverting to the previous theme via an | 310 // |extension| is disabled when reverting to the previous theme via an |
| 297 // infobar. | 311 // infobar. |
| 298 service->EnableExtension(extension->id()); | 312 service->EnableExtension(extension->id()); |
| 299 // Enabling the extension will call back to SetTheme(). | 313 // Enabling the extension will call back to SetTheme(). |
| 300 return; | 314 return; |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 // If the ThemeService is not ready yet, the custom theme data pack needs to | 512 // If the ThemeService is not ready yet, the custom theme data pack needs to |
| 499 // be recreated from the extension. | 513 // be recreated from the extension. |
| 500 MigrateTheme(); | 514 MigrateTheme(); |
| 501 set_ready(); | 515 set_ready(); |
| 502 | 516 |
| 503 // Send notification in case anyone requested data and cached it when the | 517 // Send notification in case anyone requested data and cached it when the |
| 504 // theme service was not ready yet. | 518 // theme service was not ready yet. |
| 505 NotifyThemeChanged(); | 519 NotifyThemeChanged(); |
| 506 } | 520 } |
| 507 | 521 |
| 508 registrar_.Add( | 522 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, | 523 registrar_.Add(this, |
| 516 extensions::NOTIFICATION_EXTENSION_ENABLED, | 524 extensions::NOTIFICATION_EXTENSION_ENABLED, |
| 517 content::Source<Profile>(profile_)); | 525 content::Source<Profile>(profile_)); |
| 518 registrar_.Add(this, | |
| 519 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | |
| 520 content::Source<Profile>(profile_)); | |
| 521 | 526 |
| 522 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | 527 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 523 base::Bind(&ThemeService::RemoveUnusedThemes, | 528 base::Bind(&ThemeService::RemoveUnusedThemes, |
| 524 weak_ptr_factory_.GetWeakPtr(), | 529 weak_ptr_factory_.GetWeakPtr(), |
| 525 false), | 530 false), |
| 526 base::TimeDelta::FromSeconds(kRemoveUnusedThemesStartupDelay)); | 531 base::TimeDelta::FromSeconds(kRemoveUnusedThemesStartupDelay)); |
| 527 } | 532 } |
| 528 | 533 |
| 529 void ThemeService::MigrateTheme() { | 534 void ThemeService::MigrateTheme() { |
| 530 // TODO(erg): We need to pop up a dialog informing the user that their | 535 // 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 Loading... | |
| 603 void ThemeService::OnInfobarDestroyed() { | 608 void ThemeService::OnInfobarDestroyed() { |
| 604 number_of_infobars_--; | 609 number_of_infobars_--; |
| 605 | 610 |
| 606 if (number_of_infobars_ == 0) | 611 if (number_of_infobars_ == 0) |
| 607 RemoveUnusedThemes(false); | 612 RemoveUnusedThemes(false); |
| 608 } | 613 } |
| 609 | 614 |
| 610 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { | 615 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { |
| 611 return theme_syncable_service_.get(); | 616 return theme_syncable_service_.get(); |
| 612 } | 617 } |
| OLD | NEW |