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/legacy/supervised_user_sync_service.h" | 5 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/prefs/scoped_user_pref_update.h" | 11 #include "base/prefs/scoped_user_pref_update.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/profiles/profile.h" | |
| 15 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 16 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 17 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 16 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 17 #include "components/pref_registry/pref_registry_syncable.h" | 19 #include "components/pref_registry/pref_registry_syncable.h" |
| 20 #include "components/signin/core/browser/signin_manager.h" | |
| 18 #include "sync/api/sync_change.h" | 21 #include "sync/api/sync_change.h" |
| 19 #include "sync/api/sync_data.h" | 22 #include "sync/api/sync_data.h" |
| 20 #include "sync/api/sync_error.h" | 23 #include "sync/api/sync_error.h" |
| 21 #include "sync/api/sync_error_factory.h" | 24 #include "sync/api/sync_error_factory.h" |
| 22 #include "sync/api/sync_merge_result.h" | 25 #include "sync/api/sync_merge_result.h" |
| 23 #include "sync/protocol/sync.pb.h" | 26 #include "sync/protocol/sync.pb.h" |
| 24 | 27 |
| 25 #if defined(OS_CHROMEOS) | 28 #if defined(OS_CHROMEOS) |
| 26 #include "components/user_manager/user_image/default_user_images.h" | 29 #include "components/user_manager/user_image/default_user_images.h" |
| 27 #endif | 30 #endif |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 const char SupervisedUserSyncService::kChromeAvatar[] = "chromeAvatar"; | 119 const char SupervisedUserSyncService::kChromeAvatar[] = "chromeAvatar"; |
| 117 const char SupervisedUserSyncService::kChromeOsAvatar[] = "chromeOsAvatar"; | 120 const char SupervisedUserSyncService::kChromeOsAvatar[] = "chromeOsAvatar"; |
| 118 const char SupervisedUserSyncService::kMasterKey[] = "masterKey"; | 121 const char SupervisedUserSyncService::kMasterKey[] = "masterKey"; |
| 119 const char SupervisedUserSyncService::kName[] = "name"; | 122 const char SupervisedUserSyncService::kName[] = "name"; |
| 120 const char SupervisedUserSyncService::kPasswordSignatureKey[] = | 123 const char SupervisedUserSyncService::kPasswordSignatureKey[] = |
| 121 "passwordSignatureKey"; | 124 "passwordSignatureKey"; |
| 122 const char SupervisedUserSyncService::kPasswordEncryptionKey[] = | 125 const char SupervisedUserSyncService::kPasswordEncryptionKey[] = |
| 123 "passwordEncryptionKey"; | 126 "passwordEncryptionKey"; |
| 124 const int SupervisedUserSyncService::kNoAvatar = -100; | 127 const int SupervisedUserSyncService::kNoAvatar = -100; |
| 125 | 128 |
| 126 SupervisedUserSyncService::SupervisedUserSyncService(PrefService* prefs) | 129 SupervisedUserSyncService::SupervisedUserSyncService(Profile* profile) |
| 127 : prefs_(prefs) { | 130 : profile_(profile), prefs_(profile->GetPrefs()) { |
| 128 pref_change_registrar_.Init(prefs_); | 131 SigninManagerFactory::GetForProfile(profile_)->AddObserver(this); |
| 129 pref_change_registrar_.Add( | |
| 130 prefs::kGoogleServicesLastUsername, | |
| 131 base::Bind(&SupervisedUserSyncService::OnLastSignedInUsernameChange, | |
| 132 base::Unretained(this))); | |
| 133 } | 132 } |
| 134 | 133 |
| 135 SupervisedUserSyncService::~SupervisedUserSyncService() { | 134 SupervisedUserSyncService::~SupervisedUserSyncService() { |
| 136 } | 135 } |
| 137 | 136 |
| 138 // static | 137 // static |
| 139 void SupervisedUserSyncService::RegisterProfilePrefs( | 138 void SupervisedUserSyncService::RegisterProfilePrefs( |
| 140 PrefRegistrySyncable* registry) { | 139 PrefRegistrySyncable* registry) { |
| 141 registry->RegisterDictionaryPref(prefs::kSupervisedUsers, | 140 registry->RegisterDictionaryPref(prefs::kSupervisedUsers, |
| 142 PrefRegistrySyncable::UNSYNCABLE_PREF); | 141 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 callback.Run(GetSupervisedUsers()); | 391 callback.Run(GetSupervisedUsers()); |
| 393 return; | 392 return; |
| 394 } | 393 } |
| 395 | 394 |
| 396 // Otherwise queue it up until we start syncing. | 395 // Otherwise queue it up until we start syncing. |
| 397 callbacks_.push_back(callback); | 396 callbacks_.push_back(callback); |
| 398 } | 397 } |
| 399 | 398 |
| 400 void SupervisedUserSyncService::Shutdown() { | 399 void SupervisedUserSyncService::Shutdown() { |
| 401 NotifySupervisedUsersSyncingStopped(); | 400 NotifySupervisedUsersSyncingStopped(); |
| 401 SigninManagerFactory::GetForProfile(profile_)->RemoveObserver(this); | |
| 402 } | 402 } |
| 403 | 403 |
| 404 SyncMergeResult SupervisedUserSyncService::MergeDataAndStartSyncing( | 404 SyncMergeResult SupervisedUserSyncService::MergeDataAndStartSyncing( |
| 405 ModelType type, | 405 ModelType type, |
| 406 const SyncDataList& initial_sync_data, | 406 const SyncDataList& initial_sync_data, |
| 407 scoped_ptr<SyncChangeProcessor> sync_processor, | 407 scoped_ptr<SyncChangeProcessor> sync_processor, |
| 408 scoped_ptr<SyncErrorFactory> error_handler) { | 408 scoped_ptr<SyncErrorFactory> error_handler) { |
| 409 DCHECK_EQ(SUPERVISED_USERS, type); | 409 DCHECK_EQ(SUPERVISED_USERS, type); |
| 410 sync_processor_ = sync_processor.Pass(); | 410 sync_processor_ = sync_processor.Pass(); |
| 411 error_handler_ = error_handler.Pass(); | 411 error_handler_ = error_handler.Pass(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 } | 534 } |
| 535 case SyncChange::ACTION_INVALID: { | 535 case SyncChange::ACTION_INVALID: { |
| 536 NOTREACHED(); | 536 NOTREACHED(); |
| 537 break; | 537 break; |
| 538 } | 538 } |
| 539 } | 539 } |
| 540 } | 540 } |
| 541 return error; | 541 return error; |
| 542 } | 542 } |
| 543 | 543 |
| 544 void SupervisedUserSyncService::OnLastSignedInUsernameChange() { | 544 void SupervisedUserSyncService::GoogleSignedOut( |
| 545 const std::string& account_id, | |
| 546 const std::string& username) { | |
| 545 DCHECK(!sync_processor_); | 547 DCHECK(!sync_processor_); |
| 546 | 548 |
| 547 // If the last signed in user changes, we clear all data, to avoid supervised | 549 // When the signed in user changes, we clear all data, to avoid supervised |
|
Bernhard Bauer
2015/03/23 15:50:01
"Clear all data on signout, [...]"?
Marc Treib
2015/03/23 16:03:05
Ah, forgot to update the comment. Done, thanks!
| |
| 548 // users from one custodian appearing in another one's profile. | 550 // users from one custodian appearing in another one's profile. |
| 549 prefs_->ClearPref(prefs::kSupervisedUsers); | 551 prefs_->ClearPref(prefs::kSupervisedUsers); |
| 550 } | 552 } |
| 551 | 553 |
| 552 void SupervisedUserSyncService::NotifySupervisedUserAcknowledged( | 554 void SupervisedUserSyncService::NotifySupervisedUserAcknowledged( |
| 553 const std::string& supervised_user_id) { | 555 const std::string& supervised_user_id) { |
| 554 FOR_EACH_OBSERVER(SupervisedUserSyncServiceObserver, observers_, | 556 FOR_EACH_OBSERVER(SupervisedUserSyncServiceObserver, observers_, |
| 555 OnSupervisedUserAcknowledged(supervised_user_id)); | 557 OnSupervisedUserAcknowledged(supervised_user_id)); |
| 556 } | 558 } |
| 557 | 559 |
| 558 void SupervisedUserSyncService::NotifySupervisedUsersSyncingStopped() { | 560 void SupervisedUserSyncService::NotifySupervisedUsersSyncingStopped() { |
| 559 FOR_EACH_OBSERVER(SupervisedUserSyncServiceObserver, observers_, | 561 FOR_EACH_OBSERVER(SupervisedUserSyncServiceObserver, observers_, |
| 560 OnSupervisedUsersSyncingStopped()); | 562 OnSupervisedUsersSyncingStopped()); |
| 561 } | 563 } |
| 562 | 564 |
| 563 void SupervisedUserSyncService::NotifySupervisedUsersChanged() { | 565 void SupervisedUserSyncService::NotifySupervisedUsersChanged() { |
| 564 FOR_EACH_OBSERVER(SupervisedUserSyncServiceObserver, | 566 FOR_EACH_OBSERVER(SupervisedUserSyncServiceObserver, |
| 565 observers_, | 567 observers_, |
| 566 OnSupervisedUsersChanged()); | 568 OnSupervisedUsersChanged()); |
| 567 } | 569 } |
| 568 | 570 |
| 569 void SupervisedUserSyncService::DispatchCallbacks() { | 571 void SupervisedUserSyncService::DispatchCallbacks() { |
| 570 const base::DictionaryValue* supervised_users = | 572 const base::DictionaryValue* supervised_users = |
| 571 prefs_->GetDictionary(prefs::kSupervisedUsers); | 573 prefs_->GetDictionary(prefs::kSupervisedUsers); |
| 572 for (const auto& callback : callbacks_) | 574 for (const auto& callback : callbacks_) |
| 573 callback.Run(supervised_users); | 575 callback.Run(supervised_users); |
| 574 callbacks_.clear(); | 576 callbacks_.clear(); |
| 575 } | 577 } |
| OLD | NEW |