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" |
11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/extensions/extension_system.h" | 16 #include "chrome/browser/extensions/extension_system.h" |
17 #include "chrome/browser/managed_mode/managed_user_service.h" | |
18 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | |
19 #include "chrome/browser/managed_mode/managed_user_theme.h" | 17 #include "chrome/browser/managed_mode/managed_user_theme.h" |
20 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/themes/browser_theme_pack.h" | 19 #include "chrome/browser/themes/browser_theme_pack.h" |
22 #include "chrome/browser/themes/custom_theme_supplier.h" | 20 #include "chrome/browser/themes/custom_theme_supplier.h" |
23 #include "chrome/browser/themes/theme_properties.h" | 21 #include "chrome/browser/themes/theme_properties.h" |
24 #include "chrome/browser/themes/theme_syncable_service.h" | 22 #include "chrome/browser/themes/theme_syncable_service.h" |
25 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
26 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
27 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
28 #include "content/public/browser/user_metrics.h" | 26 #include "content/public/browser/user_metrics.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 89 } |
92 | 90 |
93 ThemeService::~ThemeService() { | 91 ThemeService::~ThemeService() { |
94 FreePlatformCaches(); | 92 FreePlatformCaches(); |
95 } | 93 } |
96 | 94 |
97 void ThemeService::Init(Profile* profile) { | 95 void ThemeService::Init(Profile* profile) { |
98 DCHECK(CalledOnValidThread()); | 96 DCHECK(CalledOnValidThread()); |
99 profile_ = profile; | 97 profile_ = profile; |
100 | 98 |
101 ManagedUserServiceFactory::GetForProfile(profile)->AddInitCallback(base::Bind( | |
102 &ThemeService::OnManagedUserInitialized, weak_ptr_factory_.GetWeakPtr())); | |
103 | |
104 LoadThemePrefs(); | 99 LoadThemePrefs(); |
105 | 100 |
106 registrar_.Add(this, | 101 registrar_.Add(this, |
107 chrome::NOTIFICATION_EXTENSIONS_READY, | 102 chrome::NOTIFICATION_EXTENSIONS_READY, |
108 content::Source<Profile>(profile_)); | 103 content::Source<Profile>(profile_)); |
109 | 104 |
110 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); | 105 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); |
111 } | 106 } |
112 | 107 |
113 gfx::Image ThemeService::GetImageNamed(int id) const { | 108 gfx::Image ThemeService::GetImageNamed(int id) const { |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 } | 566 } |
572 | 567 |
573 bool ThemeService::IsManagedUser() const { | 568 bool ThemeService::IsManagedUser() const { |
574 return profile_->IsManaged(); | 569 return profile_->IsManaged(); |
575 } | 570 } |
576 | 571 |
577 void ThemeService::SetManagedUserTheme() { | 572 void ThemeService::SetManagedUserTheme() { |
578 SetCustomDefaultTheme(new ManagedUserTheme); | 573 SetCustomDefaultTheme(new ManagedUserTheme); |
579 } | 574 } |
580 | 575 |
581 void ThemeService::OnManagedUserInitialized() { | |
582 // Currently when creating a supervised user, the ThemeService is initialized | |
583 // before the boolean flag indicating the profile belongs to a supervised | |
584 // user gets set. In order to get the custom managed user theme, we get a | |
585 // callback when ManagedUserService is initialized, which happens some time | |
586 // after the boolean flag has been set in | |
587 // ProfileManager::InitProfileUserPrefs() and after the | |
588 // NOTIFICATION_EXTENSIONS_READY notification is sent. | |
589 if ((theme_supplier_.get() && | |
590 (theme_supplier_->get_theme_type() == CustomThemeSupplier::EXTENSION || | |
591 theme_supplier_->get_theme_type() == | |
592 CustomThemeSupplier::MANAGED_USER_THEME)) || | |
593 !IsManagedUser()) { | |
594 return; | |
595 } | |
596 | |
597 SetManagedUserTheme(); | |
598 } | |
599 | |
600 void ThemeService::OnInfobarDisplayed() { | 576 void ThemeService::OnInfobarDisplayed() { |
601 number_of_infobars_++; | 577 number_of_infobars_++; |
602 } | 578 } |
603 | 579 |
604 void ThemeService::OnInfobarDestroyed() { | 580 void ThemeService::OnInfobarDestroyed() { |
605 number_of_infobars_--; | 581 number_of_infobars_--; |
606 | 582 |
607 if (number_of_infobars_ == 0) | 583 if (number_of_infobars_ == 0) |
608 RemoveUnusedThemes(false); | 584 RemoveUnusedThemes(false); |
609 } | 585 } |
610 | 586 |
611 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { | 587 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { |
612 return theme_syncable_service_.get(); | 588 return theme_syncable_service_.get(); |
613 } | 589 } |
OLD | NEW |