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

Side by Side Diff: chrome/browser/supervised_user/supervised_user_service.cc

Issue 428143002: Sync: Add a SyncTypePreferenceProvider interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/supervised_user/supervised_user_service.h" 5 #include "chrome/browser/supervised_user/supervised_user_service.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 SupervisedUserService::SupervisedUserService(Profile* profile) 134 SupervisedUserService::SupervisedUserService(Profile* profile)
135 : profile_(profile), 135 : profile_(profile),
136 active_(false), 136 active_(false),
137 delegate_(NULL), 137 delegate_(NULL),
138 #if defined(ENABLE_EXTENSIONS) 138 #if defined(ENABLE_EXTENSIONS)
139 extension_registry_observer_(this), 139 extension_registry_observer_(this),
140 #endif 140 #endif
141 waiting_for_sync_initialization_(false), 141 waiting_for_sync_initialization_(false),
142 is_profile_active_(false), 142 is_profile_active_(false),
143 elevated_for_testing_(false), 143 elevated_for_testing_(false),
144 did_init_(false),
144 did_shutdown_(false), 145 did_shutdown_(false),
145 waiting_for_permissions_(false), 146 waiting_for_permissions_(false),
146 weak_ptr_factory_(this) { 147 weak_ptr_factory_(this) {
147 } 148 }
148 149
149 SupervisedUserService::~SupervisedUserService() { 150 SupervisedUserService::~SupervisedUserService() {
150 DCHECK(did_shutdown_); 151 DCHECK(!did_init_ || did_shutdown_);
151 } 152 }
152 153
153 void SupervisedUserService::Shutdown() { 154 void SupervisedUserService::Shutdown() {
155 if (!did_init_ || did_shutdown_)
Bernhard Bauer 2014/08/11 08:48:21 When would we call Shutdown() more than once?
Marc Treib 2014/08/11 08:57:09 Ah, that was unclear - actually I'm not sure if we
Bernhard Bauer 2014/08/11 09:07:13 I'm not sure what you mean by that -- right now yo
Marc Treib 2014/08/11 09:35:44 Done.
156 return;
154 did_shutdown_ = true; 157 did_shutdown_ = true;
155 if (ProfileIsSupervised()) { 158 if (ProfileIsSupervised()) {
156 content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser")); 159 content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser"));
157 } 160 }
158 SetActive(false); 161 SetActive(false);
162
163 ProfileSyncServiceFactory::GetForProfile(profile_)->RemovePreferenceProvider(
164 this);
159 } 165 }
160 166
161 bool SupervisedUserService::ProfileIsSupervised() const { 167 bool SupervisedUserService::ProfileIsSupervised() const {
162 return profile_->IsSupervised(); 168 return profile_->IsSupervised();
163 } 169 }
164 170
165 // static 171 // static
166 void SupervisedUserService::RegisterProfilePrefs( 172 void SupervisedUserService::RegisterProfilePrefs(
167 user_prefs::PrefRegistrySyncable* registry) { 173 user_prefs::PrefRegistrySyncable* registry) {
168 registry->RegisterDictionaryPref( 174 registry->RegisterDictionaryPref(
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 content::BrowserContext* browser_context, 334 content::BrowserContext* browser_context,
329 const extensions::Extension* extension, 335 const extensions::Extension* extension,
330 extensions::UnloadedExtensionInfo::Reason reason) { 336 extensions::UnloadedExtensionInfo::Reason reason) {
331 if (!extensions::SupervisedUserInfo::GetContentPackSiteList(extension) 337 if (!extensions::SupervisedUserInfo::GetContentPackSiteList(extension)
332 .empty()) { 338 .empty()) {
333 UpdateSiteLists(); 339 UpdateSiteLists();
334 } 340 }
335 } 341 }
336 #endif // defined(ENABLE_EXTENSIONS) 342 #endif // defined(ENABLE_EXTENSIONS)
337 343
344 syncer::ModelTypeSet SupervisedUserService::GetPreferredDataTypes() {
345 if (!ProfileIsSupervised())
346 return syncer::ModelTypeSet();
347
348 syncer::ModelTypeSet result;
349 result.Put(syncer::SESSIONS);
350 result.Put(syncer::EXTENSIONS);
351 result.Put(syncer::EXTENSION_SETTINGS);
352 result.Put(syncer::APPS);
353 result.Put(syncer::APP_SETTINGS);
354 result.Put(syncer::APP_NOTIFICATIONS);
355 result.Put(syncer::APP_LIST);
356 return result;
357 }
358
338 void SupervisedUserService::OnStateChanged() { 359 void SupervisedUserService::OnStateChanged() {
339 ProfileSyncService* service = 360 ProfileSyncService* service =
340 ProfileSyncServiceFactory::GetForProfile(profile_); 361 ProfileSyncServiceFactory::GetForProfile(profile_);
341 if (waiting_for_sync_initialization_ && service->sync_initialized()) { 362 if (waiting_for_sync_initialization_ && service->sync_initialized()) {
342 waiting_for_sync_initialization_ = false; 363 waiting_for_sync_initialization_ = false;
343 service->RemoveObserver(this); 364 service->RemoveObserver(this);
344 FinishSetupSync(); 365 FinishSetupSync();
345 return; 366 return;
346 } 367 }
347 368
(...skipping 27 matching lines...) Expand all
375 service->AddObserver(this); 396 service->AddObserver(this);
376 waiting_for_sync_initialization_ = true; 397 waiting_for_sync_initialization_ = true;
377 } 398 }
378 } 399 }
379 400
380 void SupervisedUserService::FinishSetupSync() { 401 void SupervisedUserService::FinishSetupSync() {
381 ProfileSyncService* service = 402 ProfileSyncService* service =
382 ProfileSyncServiceFactory::GetForProfile(profile_); 403 ProfileSyncServiceFactory::GetForProfile(profile_);
383 DCHECK(service->sync_initialized()); 404 DCHECK(service->sync_initialized());
384 405
406 // Sync nothing (except types which are set via GetPreferredDataTypes).
385 bool sync_everything = false; 407 bool sync_everything = false;
386 syncer::ModelTypeSet synced_datatypes; 408 syncer::ModelTypeSet synced_datatypes;
387 synced_datatypes.Put(syncer::SESSIONS);
388 synced_datatypes.Put(syncer::APPS);
389 synced_datatypes.Put(syncer::EXTENSIONS);
390 service->OnUserChoseDatatypes(sync_everything, synced_datatypes); 409 service->OnUserChoseDatatypes(sync_everything, synced_datatypes);
391 410
392 // Notify ProfileSyncService that we are done with configuration. 411 // Notify ProfileSyncService that we are done with configuration.
393 service->SetSetupInProgress(false); 412 service->SetSetupInProgress(false);
394 service->SetSyncSetupCompleted(); 413 service->SetSyncSetupCompleted();
395 } 414 }
396 415
397 #if defined(ENABLE_EXTENSIONS) 416 #if defined(ENABLE_EXTENSIONS)
398 bool SupervisedUserService::ExtensionManagementPolicyImpl( 417 bool SupervisedUserService::ExtensionManagementPolicyImpl(
399 const extensions::Extension* extension, 418 const extensions::Extension* extension,
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 579
561 ProfileOAuth2TokenService* token_service = 580 ProfileOAuth2TokenService* token_service =
562 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 581 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
563 token_service->UpdateCredentials(supervised_users::kSupervisedUserPseudoEmail, 582 token_service->UpdateCredentials(supervised_users::kSupervisedUserPseudoEmail,
564 refresh_token); 583 refresh_token);
565 584
566 FinishSetupSyncWhenReady(); 585 FinishSetupSyncWhenReady();
567 } 586 }
568 587
569 void SupervisedUserService::Init() { 588 void SupervisedUserService::Init() {
589 DCHECK(!did_init_);
590 did_init_ = true;
570 DCHECK(GetSettingsService()->IsReady()); 591 DCHECK(GetSettingsService()->IsReady());
571 592
572 pref_change_registrar_.Init(profile_->GetPrefs()); 593 pref_change_registrar_.Init(profile_->GetPrefs());
573 pref_change_registrar_.Add( 594 pref_change_registrar_.Add(
574 prefs::kSupervisedUserId, 595 prefs::kSupervisedUserId,
575 base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged, 596 base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged,
576 base::Unretained(this))); 597 base::Unretained(this)));
577 598
599 ProfileSyncServiceFactory::GetForProfile(profile_)->AddPreferenceProvider(
600 this);
601
578 SetActive(ProfileIsSupervised()); 602 SetActive(ProfileIsSupervised());
579 } 603 }
580 604
581 void SupervisedUserService::SetActive(bool active) { 605 void SupervisedUserService::SetActive(bool active) {
582 if (active_ == active) 606 if (active_ == active)
583 return; 607 return;
584 active_ = active; 608 active_ = active;
585 609
586 if (!delegate_ || !delegate_->SetActive(active_)) { 610 if (!delegate_ || !delegate_->SetActive(active_)) {
587 if (active_) { 611 if (active_) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 BrowserList::AddObserver(this); 683 BrowserList::AddObserver(this);
660 #endif 684 #endif
661 } else { 685 } else {
662 permissions_creator_.reset(); 686 permissions_creator_.reset();
663 687
664 pref_change_registrar_.Remove( 688 pref_change_registrar_.Remove(
665 prefs::kDefaultSupervisedUserFilteringBehavior); 689 prefs::kDefaultSupervisedUserFilteringBehavior);
666 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); 690 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts);
667 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); 691 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs);
668 692
669 if (waiting_for_sync_initialization_) { 693 if (waiting_for_sync_initialization_)
670 ProfileSyncService* sync_service = 694 ProfileSyncServiceFactory::GetForProfile(profile_)->RemoveObserver(this);
671 ProfileSyncServiceFactory::GetForProfile(profile_);
672 sync_service->RemoveObserver(this);
673 }
674 695
675 #if !defined(OS_ANDROID) 696 #if !defined(OS_ANDROID)
676 // TODO(bauerb): Get rid of the platform-specific #ifdef here. 697 // TODO(bauerb): Get rid of the platform-specific #ifdef here.
677 // http://crbug.com/313377 698 // http://crbug.com/313377
678 BrowserList::RemoveObserver(this); 699 BrowserList::RemoveObserver(this);
679 #endif 700 #endif
680 } 701 }
681 } 702 }
682 703
683 void SupervisedUserService::RegisterAndInitSync( 704 void SupervisedUserService::RegisterAndInitSync(
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 // The active user can be NULL in unit tests. 803 // The active user can be NULL in unit tests.
783 if (chromeos::UserManager::Get()->GetActiveUser()) { 804 if (chromeos::UserManager::Get()->GetActiveUser()) {
784 return UTF16ToUTF8(chromeos::UserManager::Get()->GetUserDisplayName( 805 return UTF16ToUTF8(chromeos::UserManager::Get()->GetUserDisplayName(
785 chromeos::UserManager::Get()->GetActiveUser()->GetUserID())); 806 chromeos::UserManager::Get()->GetActiveUser()->GetUserID()));
786 } 807 }
787 return std::string(); 808 return std::string();
788 #else 809 #else
789 return profile_->GetPrefs()->GetString(prefs::kProfileName); 810 return profile_->GetPrefs()->GetString(prefs::kProfileName);
790 #endif 811 #endif
791 } 812 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698