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 : may_session_sync_(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 (MaySyncSessions()) |
| 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::OnNewSettingsAvailable( | |
| 375 const base::DictionaryValue* settings) { | |
|
Marc Treib
2014/08/19 14:00:27
Indent 4 spaces only. You can also try "git cl for
| |
| 376 bool has_session_sync_state_changed = FetchNewSessionSyncState(settings); | |
| 377 if (has_session_sync_state_changed) { | |
| 378 ReinitializeProfileSyncService(); | |
| 379 } | |
| 380 } | |
| 381 | |
| 382 bool SupervisedUserService::FetchNewSessionSyncState( | |
| 383 const base::DictionaryValue* settings) { | |
|
Marc Treib
2014/08/19 14:00:27
^^
| |
| 384 bool old_may_session_sync_ = may_session_sync_; | |
|
Marc Treib
2014/08/19 14:00:27
No trailing underscore on local variable.
| |
| 385 const base::Value* value = NULL; | |
| 386 if (settings && | |
|
Marc Treib
2014/08/19 14:00:27
Can settings be null here? If so, please add a com
| |
| 387 settings->GetWithoutPathExpansion(supervised_users::kRecordHistory, | |
| 388 &value)) | |
| 389 value->GetAsBoolean(&may_session_sync_); | |
| 390 return old_may_session_sync_ != may_session_sync_; | |
| 391 } | |
| 392 | |
| 393 void SupervisedUserService::ReinitializeProfileSyncService() { | |
| 394 ProfileSyncService* sync_service = | |
| 395 ProfileSyncServiceFactory::GetForProfile(profile_); | |
| 396 if (!sync_service->sync_initialized()) | |
|
Marc Treib
2014/08/19 14:00:27
Also check sync_service->setup_in_progress() ?
| |
| 397 return; | |
| 398 // The following lines force the ProfileSyncService to reload its changed data | |
| 399 sync_service->SetSetupInProgress(true); | |
| 400 sync_service->SetSetupInProgress(false); | |
| 401 } | |
| 402 | |
| 403 bool SupervisedUserService::MaySyncSessions() const { | |
| 404 return may_session_sync_; | |
| 405 } | |
| 406 | |
| 372 void SupervisedUserService::OnStateChanged() { | 407 void SupervisedUserService::OnStateChanged() { |
| 373 ProfileSyncService* service = | 408 ProfileSyncService* service = |
| 374 ProfileSyncServiceFactory::GetForProfile(profile_); | 409 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 375 if (waiting_for_sync_initialization_ && service->sync_initialized()) { | 410 if (waiting_for_sync_initialization_ && service->sync_initialized()) { |
| 376 waiting_for_sync_initialization_ = false; | 411 waiting_for_sync_initialization_ = false; |
| 377 service->RemoveObserver(this); | 412 service->RemoveObserver(this); |
| 378 FinishSetupSync(); | 413 FinishSetupSync(); |
| 379 return; | 414 return; |
| 380 } | 415 } |
| 381 | 416 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 650 // Re-set the default theme to turn the SU theme on/off. | 685 // Re-set the default theme to turn the SU theme on/off. |
| 651 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_); | 686 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_); |
| 652 if (theme_service->UsingDefaultTheme() || theme_service->UsingSystemTheme()) { | 687 if (theme_service->UsingDefaultTheme() || theme_service->UsingSystemTheme()) { |
| 653 ThemeServiceFactory::GetForProfile(profile_)->UseDefaultTheme(); | 688 ThemeServiceFactory::GetForProfile(profile_)->UseDefaultTheme(); |
| 654 } | 689 } |
| 655 #endif | 690 #endif |
| 656 | 691 |
| 657 SupervisedUserSettingsService* settings_service = GetSettingsService(); | 692 SupervisedUserSettingsService* settings_service = GetSettingsService(); |
| 658 settings_service->SetActive(active_); | 693 settings_service->SetActive(active_); |
| 659 | 694 |
| 695 settings_service->Subscribe( | |
| 696 base::Bind(&SupervisedUserService::OnNewSettingsAvailable, | |
| 697 weak_ptr_factory_.GetWeakPtr())); | |
| 698 | |
| 660 #if defined(ENABLE_EXTENSIONS) | 699 #if defined(ENABLE_EXTENSIONS) |
| 661 SetExtensionsActive(); | 700 SetExtensionsActive(); |
| 662 #endif | 701 #endif |
| 663 | 702 |
| 664 if (active_) { | 703 if (active_) { |
| 665 if (CommandLine::ForCurrentProcess()->HasSwitch( | 704 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 666 switches::kPermissionRequestApiUrl)) { | 705 switches::kPermissionRequestApiUrl)) { |
| 667 permissions_creator_ = | 706 permissions_creator_ = |
| 668 PermissionRequestCreatorApiary::CreateWithProfile(profile_); | 707 PermissionRequestCreatorApiary::CreateWithProfile(profile_); |
| 669 } else { | 708 } else { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 819 // The active user can be NULL in unit tests. | 858 // The active user can be NULL in unit tests. |
| 820 if (chromeos::UserManager::Get()->GetActiveUser()) { | 859 if (chromeos::UserManager::Get()->GetActiveUser()) { |
| 821 return UTF16ToUTF8(chromeos::UserManager::Get()->GetUserDisplayName( | 860 return UTF16ToUTF8(chromeos::UserManager::Get()->GetUserDisplayName( |
| 822 chromeos::UserManager::Get()->GetActiveUser()->GetUserID())); | 861 chromeos::UserManager::Get()->GetActiveUser()->GetUserID())); |
| 823 } | 862 } |
| 824 return std::string(); | 863 return std::string(); |
| 825 #else | 864 #else |
| 826 return profile_->GetPrefs()->GetString(prefs::kProfileName); | 865 return profile_->GetPrefs()->GetString(prefs::kProfileName); |
| 827 #endif | 866 #endif |
| 828 } | 867 } |
| OLD | NEW |