Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 scoped_ptr<std::map<GURL, bool> > url_map) { | 125 scoped_ptr<std::map<GURL, bool> > url_map) { |
| 126 ui_url_filter_->SetManualURLs(url_map.get()); | 126 ui_url_filter_->SetManualURLs(url_map.get()); |
| 127 BrowserThread::PostTask( | 127 BrowserThread::PostTask( |
| 128 BrowserThread::IO, | 128 BrowserThread::IO, |
| 129 FROM_HERE, | 129 FROM_HERE, |
| 130 base::Bind(&SupervisedUserURLFilter::SetManualURLs, | 130 base::Bind(&SupervisedUserURLFilter::SetManualURLs, |
| 131 io_url_filter_, base::Owned(url_map.release()))); | 131 io_url_filter_, base::Owned(url_map.release()))); |
| 132 } | 132 } |
| 133 | 133 |
| 134 SupervisedUserService::SupervisedUserService(Profile* profile) | 134 SupervisedUserService::SupervisedUserService(Profile* profile) |
| 135 : profile_(profile), | 135 : includes_sync_sessions_(true), |
| 136 profile_(profile), | |
| 136 active_(false), | 137 active_(false), |
| 137 delegate_(NULL), | 138 delegate_(NULL), |
| 138 #if defined(ENABLE_EXTENSIONS) | 139 #if defined(ENABLE_EXTENSIONS) |
| 139 extension_registry_observer_(this), | 140 extension_registry_observer_(this), |
| 140 #endif | 141 #endif |
| 141 waiting_for_sync_initialization_(false), | 142 waiting_for_sync_initialization_(false), |
| 142 is_profile_active_(false), | 143 is_profile_active_(false), |
| 143 elevated_for_testing_(false), | 144 elevated_for_testing_(false), |
| 144 did_init_(false), | 145 did_init_(false), |
| 145 did_shutdown_(false), | 146 did_shutdown_(false), |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 UpdateSiteLists(); | 353 UpdateSiteLists(); |
| 353 } | 354 } |
| 354 } | 355 } |
| 355 #endif // defined(ENABLE_EXTENSIONS) | 356 #endif // defined(ENABLE_EXTENSIONS) |
| 356 | 357 |
| 357 syncer::ModelTypeSet SupervisedUserService::GetPreferredDataTypes() const { | 358 syncer::ModelTypeSet SupervisedUserService::GetPreferredDataTypes() const { |
| 358 if (!ProfileIsSupervised()) | 359 if (!ProfileIsSupervised()) |
| 359 return syncer::ModelTypeSet(); | 360 return syncer::ModelTypeSet(); |
| 360 | 361 |
| 361 syncer::ModelTypeSet result; | 362 syncer::ModelTypeSet result; |
| 362 result.Put(syncer::SESSIONS); | 363 if (IncludesSyncSessions()) |
| 364 result.Put(syncer::SESSIONS); | |
| 363 result.Put(syncer::EXTENSIONS); | 365 result.Put(syncer::EXTENSIONS); |
| 364 result.Put(syncer::EXTENSION_SETTINGS); | 366 result.Put(syncer::EXTENSION_SETTINGS); |
| 365 result.Put(syncer::APPS); | 367 result.Put(syncer::APPS); |
| 366 result.Put(syncer::APP_SETTINGS); | 368 result.Put(syncer::APP_SETTINGS); |
| 367 result.Put(syncer::APP_NOTIFICATIONS); | 369 result.Put(syncer::APP_NOTIFICATIONS); |
| 368 result.Put(syncer::APP_LIST); | 370 result.Put(syncer::APP_LIST); |
| 369 return result; | 371 return result; |
| 370 } | 372 } |
| 371 | 373 |
| 374 void SupervisedUserService::OnHistoryRecordingStateChanged() { | |
| 375 bool has_session_sync_state_changed = FetchNewSessionSyncState(); | |
| 376 if (has_session_sync_state_changed) | |
| 377 ProfileSyncServiceFactory::GetForProfile(profile_) | |
| 378 ->ReconfigureDatatypeManager(); | |
| 379 } | |
| 380 | |
| 381 bool SupervisedUserService::FetchNewSessionSyncState() { | |
|
Marc Treib
2014/08/20 14:14:26
This method doesn't seem necessary anymore, since
fhorschig
2014/08/20 14:48:03
Done.
| |
| 382 bool old_includes_session_sync = includes_sync_sessions_; | |
| 383 | |
| 384 includes_sync_sessions_ = | |
| 385 profile_->GetPrefs()->GetBoolean(prefs::kRecordHistory); | |
| 386 | |
| 387 return old_includes_session_sync != includes_sync_sessions_; | |
| 388 } | |
| 389 | |
| 390 bool SupervisedUserService::IncludesSyncSessions() const { | |
| 391 return includes_sync_sessions_; | |
| 392 } | |
| 393 | |
| 372 void SupervisedUserService::OnStateChanged() { | 394 void SupervisedUserService::OnStateChanged() { |
| 373 ProfileSyncService* service = | 395 ProfileSyncService* service = |
| 374 ProfileSyncServiceFactory::GetForProfile(profile_); | 396 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 375 if (waiting_for_sync_initialization_ && service->sync_initialized()) { | 397 if (waiting_for_sync_initialization_ && service->sync_initialized()) { |
| 376 waiting_for_sync_initialization_ = false; | 398 waiting_for_sync_initialization_ = false; |
| 377 service->RemoveObserver(this); | 399 service->RemoveObserver(this); |
| 378 FinishSetupSync(); | 400 FinishSetupSync(); |
| 379 return; | 401 return; |
| 380 } | 402 } |
| 381 | 403 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 void SupervisedUserService::Init() { | 623 void SupervisedUserService::Init() { |
| 602 DCHECK(!did_init_); | 624 DCHECK(!did_init_); |
| 603 did_init_ = true; | 625 did_init_ = true; |
| 604 DCHECK(GetSettingsService()->IsReady()); | 626 DCHECK(GetSettingsService()->IsReady()); |
| 605 | 627 |
| 606 pref_change_registrar_.Init(profile_->GetPrefs()); | 628 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 607 pref_change_registrar_.Add( | 629 pref_change_registrar_.Add( |
| 608 prefs::kSupervisedUserId, | 630 prefs::kSupervisedUserId, |
| 609 base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged, | 631 base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged, |
| 610 base::Unretained(this))); | 632 base::Unretained(this))); |
| 633 pref_change_registrar_.Add( | |
| 634 prefs::kRecordHistory, | |
| 635 base::Bind(&SupervisedUserService::OnHistoryRecordingStateChanged, | |
| 636 base::Unretained(this))); | |
| 611 | 637 |
| 612 ProfileSyncService* sync_service = | 638 ProfileSyncService* sync_service = |
| 613 ProfileSyncServiceFactory::GetForProfile(profile_); | 639 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 614 // Can be null in tests. | 640 // Can be null in tests. |
| 615 if (sync_service) | 641 if (sync_service) |
| 616 sync_service->AddPreferenceProvider(this); | 642 sync_service->AddPreferenceProvider(this); |
| 617 | 643 |
| 618 SetActive(ProfileIsSupervised()); | 644 SetActive(ProfileIsSupervised()); |
| 619 } | 645 } |
| 620 | 646 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 819 // The active user can be NULL in unit tests. | 845 // The active user can be NULL in unit tests. |
| 820 if (chromeos::UserManager::Get()->GetActiveUser()) { | 846 if (chromeos::UserManager::Get()->GetActiveUser()) { |
| 821 return UTF16ToUTF8(chromeos::UserManager::Get()->GetUserDisplayName( | 847 return UTF16ToUTF8(chromeos::UserManager::Get()->GetUserDisplayName( |
| 822 chromeos::UserManager::Get()->GetActiveUser()->GetUserID())); | 848 chromeos::UserManager::Get()->GetActiveUser()->GetUserID())); |
| 823 } | 849 } |
| 824 return std::string(); | 850 return std::string(); |
| 825 #else | 851 #else |
| 826 return profile_->GetPrefs()->GetString(prefs::kProfileName); | 852 return profile_->GetPrefs()->GetString(prefs::kProfileName); |
| 827 #endif | 853 #endif |
| 828 } | 854 } |
| OLD | NEW |