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

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

Issue 22677002: Notify ThemeService via callback when supervised user is ready. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to ToT and address nits. Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/themes/theme_service.h ('k') | chrome/browser/themes/theme_service_unittest.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 "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/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/sequenced_task_runner.h" 10 #include "base/sequenced_task_runner.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/extensions/extension_system.h" 15 #include "chrome/browser/extensions/extension_system.h"
16 #include "chrome/browser/managed_mode/managed_user_service.h"
17 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
16 #include "chrome/browser/managed_mode/managed_user_theme.h" 18 #include "chrome/browser/managed_mode/managed_user_theme.h"
17 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/themes/browser_theme_pack.h" 20 #include "chrome/browser/themes/browser_theme_pack.h"
19 #include "chrome/browser/themes/custom_theme_supplier.h" 21 #include "chrome/browser/themes/custom_theme_supplier.h"
20 #include "chrome/browser/themes/theme_properties.h" 22 #include "chrome/browser/themes/theme_properties.h"
21 #include "chrome/browser/themes/theme_syncable_service.h" 23 #include "chrome/browser/themes/theme_syncable_service.h"
22 #include "chrome/common/chrome_constants.h" 24 #include "chrome/common/chrome_constants.h"
23 #include "chrome/common/extensions/extension_manifest_constants.h" 25 #include "chrome/common/extensions/extension_manifest_constants.h"
24 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
25 #include "content/public/browser/notification_service.h" 27 #include "content/public/browser/notification_service.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 if (!pack->WriteToDisk(path)) 72 if (!pack->WriteToDisk(path))
71 NOTREACHED() << "Could not write theme pack to disk"; 73 NOTREACHED() << "Could not write theme pack to disk";
72 } 74 }
73 75
74 } // namespace 76 } // namespace
75 77
76 ThemeService::ThemeService() 78 ThemeService::ThemeService()
77 : ready_(false), 79 : ready_(false),
78 rb_(ResourceBundle::GetSharedInstance()), 80 rb_(ResourceBundle::GetSharedInstance()),
79 profile_(NULL), 81 profile_(NULL),
80 number_of_infobars_(0) { 82 number_of_infobars_(0),
83 weak_ptr_factory_(this) {
81 } 84 }
82 85
83 ThemeService::~ThemeService() { 86 ThemeService::~ThemeService() {
84 FreePlatformCaches(); 87 FreePlatformCaches();
85 } 88 }
86 89
87 void ThemeService::Init(Profile* profile) { 90 void ThemeService::Init(Profile* profile) {
88 DCHECK(CalledOnValidThread()); 91 DCHECK(CalledOnValidThread());
89 profile_ = profile; 92 profile_ = profile;
90 93
94 ManagedUserServiceFactory::GetForProfile(profile)->AddInitCallback(base::Bind(
95 &ThemeService::OnManagedUserInitialized, weak_ptr_factory_.GetWeakPtr()));
96
91 LoadThemePrefs(); 97 LoadThemePrefs();
92 98
93 if (!ready_) { 99 if (!ready_) {
94 registrar_.Add(this, 100 registrar_.Add(this,
95 chrome::NOTIFICATION_EXTENSIONS_READY, 101 chrome::NOTIFICATION_EXTENSIONS_READY,
96 content::Source<Profile>(profile_)); 102 content::Source<Profile>(profile_));
97 } 103 }
98 104
99 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); 105 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this));
100 } 106 }
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 } 459 }
454 460
455 bool ThemeService::IsManagedUser() const { 461 bool ThemeService::IsManagedUser() const {
456 return profile_->IsManaged(); 462 return profile_->IsManaged();
457 } 463 }
458 464
459 void ThemeService::SetManagedUserTheme() { 465 void ThemeService::SetManagedUserTheme() {
460 SetCustomDefaultTheme(new ManagedUserTheme); 466 SetCustomDefaultTheme(new ManagedUserTheme);
461 } 467 }
462 468
469 void ThemeService::OnManagedUserInitialized() {
470 // Currently when creating a supervised user, the ThemeService is initialized
471 // before the boolean flag indicating the profile belongs to a supervised
472 // user gets set. In order to get the custom managed user theme, we get a
473 // callback when ManagedUserService is initialized, which happens some time
474 // after the boolean flag has been set in
475 // ProfileManager::InitProfileUserPrefs() and after the
476 // NOTIFICATION_EXTENSIONS_READY notification is sent.
477 if (theme_supplier_.get() || !IsManagedUser())
478 return;
479
480 SetManagedUserTheme();
481 }
482
463 void ThemeService::OnInfobarDisplayed() { 483 void ThemeService::OnInfobarDisplayed() {
464 number_of_infobars_++; 484 number_of_infobars_++;
465 } 485 }
466 486
467 void ThemeService::OnInfobarDestroyed() { 487 void ThemeService::OnInfobarDestroyed() {
468 number_of_infobars_--; 488 number_of_infobars_--;
469 489
470 if (number_of_infobars_ == 0) 490 if (number_of_infobars_ == 0)
471 RemoveUnusedThemes(); 491 RemoveUnusedThemes();
472 } 492 }
473 493
474 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { 494 ThemeSyncableService* ThemeService::GetThemeSyncableService() const {
475 return theme_syncable_service_.get(); 495 return theme_syncable_service_.get();
476 } 496 }
OLDNEW
« no previous file with comments | « chrome/browser/themes/theme_service.h ('k') | chrome/browser/themes/theme_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698