| 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_type_(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 (IncludesSyncSessionsType()) |
| 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 includes_sync_sessions_type_ = |
| 376 profile_->GetPrefs()->GetBoolean(prefs::kRecordHistory); |
| 377 ProfileSyncServiceFactory::GetForProfile(profile_) |
| 378 ->ReconfigureDatatypeManager(); |
| 379 } |
| 380 |
| 381 bool SupervisedUserService::IncludesSyncSessionsType() const { |
| 382 return includes_sync_sessions_type_; |
| 383 } |
| 384 |
| 372 void SupervisedUserService::OnStateChanged() { | 385 void SupervisedUserService::OnStateChanged() { |
| 373 ProfileSyncService* service = | 386 ProfileSyncService* service = |
| 374 ProfileSyncServiceFactory::GetForProfile(profile_); | 387 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 375 if (waiting_for_sync_initialization_ && service->sync_initialized()) { | 388 if (waiting_for_sync_initialization_ && service->sync_initialized()) { |
| 376 waiting_for_sync_initialization_ = false; | 389 waiting_for_sync_initialization_ = false; |
| 377 service->RemoveObserver(this); | 390 service->RemoveObserver(this); |
| 378 FinishSetupSync(); | 391 FinishSetupSync(); |
| 379 return; | 392 return; |
| 380 } | 393 } |
| 381 | 394 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 void SupervisedUserService::Init() { | 614 void SupervisedUserService::Init() { |
| 602 DCHECK(!did_init_); | 615 DCHECK(!did_init_); |
| 603 did_init_ = true; | 616 did_init_ = true; |
| 604 DCHECK(GetSettingsService()->IsReady()); | 617 DCHECK(GetSettingsService()->IsReady()); |
| 605 | 618 |
| 606 pref_change_registrar_.Init(profile_->GetPrefs()); | 619 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 607 pref_change_registrar_.Add( | 620 pref_change_registrar_.Add( |
| 608 prefs::kSupervisedUserId, | 621 prefs::kSupervisedUserId, |
| 609 base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged, | 622 base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged, |
| 610 base::Unretained(this))); | 623 base::Unretained(this))); |
| 624 pref_change_registrar_.Add( |
| 625 prefs::kRecordHistory, |
| 626 base::Bind(&SupervisedUserService::OnHistoryRecordingStateChanged, |
| 627 base::Unretained(this))); |
| 611 | 628 |
| 612 ProfileSyncService* sync_service = | 629 ProfileSyncService* sync_service = |
| 613 ProfileSyncServiceFactory::GetForProfile(profile_); | 630 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 614 // Can be null in tests. | 631 // Can be null in tests. |
| 615 if (sync_service) | 632 if (sync_service) |
| 616 sync_service->AddPreferenceProvider(this); | 633 sync_service->AddPreferenceProvider(this); |
| 617 | 634 |
| 618 SetActive(ProfileIsSupervised()); | 635 SetActive(ProfileIsSupervised()); |
| 619 } | 636 } |
| 620 | 637 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 // The active user can be NULL in unit tests. | 836 // The active user can be NULL in unit tests. |
| 820 if (chromeos::UserManager::Get()->GetActiveUser()) { | 837 if (chromeos::UserManager::Get()->GetActiveUser()) { |
| 821 return UTF16ToUTF8(chromeos::UserManager::Get()->GetUserDisplayName( | 838 return UTF16ToUTF8(chromeos::UserManager::Get()->GetUserDisplayName( |
| 822 chromeos::UserManager::Get()->GetActiveUser()->GetUserID())); | 839 chromeos::UserManager::Get()->GetActiveUser()->GetUserID())); |
| 823 } | 840 } |
| 824 return std::string(); | 841 return std::string(); |
| 825 #else | 842 #else |
| 826 return profile_->GetPrefs()->GetString(prefs::kProfileName); | 843 return profile_->GetPrefs()->GetString(prefs::kProfileName); |
| 827 #endif | 844 #endif |
| 828 } | 845 } |
| OLD | NEW |