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( | 99 if (!(theme_supplier_ && |
pkotwicz
2013/10/17 16:49:09
I do not think that this block is needed.
LoadThem
Bernhard Bauer
2013/10/17 16:55:03
Cool! Done.
| |
102 &ThemeService::OnManagedUserInitialized, weak_ptr_factory_.GetWeakPtr())); | 100 (theme_supplier_->get_theme_type() == CustomThemeSupplier::EXTENSION || |
101 theme_supplier_->get_theme_type() == | |
102 CustomThemeSupplier::MANAGED_USER_THEME)) && | |
103 IsManagedUser()) { | |
104 SetManagedUserTheme(); | |
105 } | |
103 | 106 |
104 LoadThemePrefs(); | 107 LoadThemePrefs(); |
105 | 108 |
106 registrar_.Add(this, | 109 registrar_.Add(this, |
107 chrome::NOTIFICATION_EXTENSIONS_READY, | 110 chrome::NOTIFICATION_EXTENSIONS_READY, |
108 content::Source<Profile>(profile_)); | 111 content::Source<Profile>(profile_)); |
109 | 112 |
110 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); | 113 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); |
111 } | 114 } |
112 | 115 |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 } | 574 } |
572 | 575 |
573 bool ThemeService::IsManagedUser() const { | 576 bool ThemeService::IsManagedUser() const { |
574 return profile_->IsManaged(); | 577 return profile_->IsManaged(); |
575 } | 578 } |
576 | 579 |
577 void ThemeService::SetManagedUserTheme() { | 580 void ThemeService::SetManagedUserTheme() { |
578 SetCustomDefaultTheme(new ManagedUserTheme); | 581 SetCustomDefaultTheme(new ManagedUserTheme); |
579 } | 582 } |
580 | 583 |
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() { | 584 void ThemeService::OnInfobarDisplayed() { |
601 number_of_infobars_++; | 585 number_of_infobars_++; |
602 } | 586 } |
603 | 587 |
604 void ThemeService::OnInfobarDestroyed() { | 588 void ThemeService::OnInfobarDestroyed() { |
605 number_of_infobars_--; | 589 number_of_infobars_--; |
606 | 590 |
607 if (number_of_infobars_ == 0) | 591 if (number_of_infobars_ == 0) |
608 RemoveUnusedThemes(false); | 592 RemoveUnusedThemes(false); |
609 } | 593 } |
610 | 594 |
611 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { | 595 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { |
612 return theme_syncable_service_.get(); | 596 return theme_syncable_service_.get(); |
613 } | 597 } |
OLD | NEW |