| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 20 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 20 #include "chrome/browser/signin/signin_manager_factory.h" | 21 #include "chrome/browser/signin/signin_manager_factory.h" |
| 21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 22 #include "components/pref_registry/pref_registry_syncable.h" | 23 #include "components/pref_registry/pref_registry_syncable.h" |
| 23 #include "components/prefs/scoped_user_pref_update.h" | 24 #include "components/prefs/scoped_user_pref_update.h" |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 DictionaryPrefUpdate update(prefs_, prefs::kSupervisedUsers); | 421 DictionaryPrefUpdate update(prefs_, prefs::kSupervisedUsers); |
| 421 base::DictionaryValue* dict = update.Get(); | 422 base::DictionaryValue* dict = update.Get(); |
| 422 result.set_num_items_before_association(dict->size()); | 423 result.set_num_items_before_association(dict->size()); |
| 423 std::set<std::string> seen_ids; | 424 std::set<std::string> seen_ids; |
| 424 int num_items_added = 0; | 425 int num_items_added = 0; |
| 425 int num_items_modified = 0; | 426 int num_items_modified = 0; |
| 426 for (const SyncData& sync_data : initial_sync_data) { | 427 for (const SyncData& sync_data : initial_sync_data) { |
| 427 DCHECK_EQ(SUPERVISED_USERS, sync_data.GetDataType()); | 428 DCHECK_EQ(SUPERVISED_USERS, sync_data.GetDataType()); |
| 428 const ManagedUserSpecifics& supervised_user = | 429 const ManagedUserSpecifics& supervised_user = |
| 429 sync_data.GetSpecifics().managed_user(); | 430 sync_data.GetSpecifics().managed_user(); |
| 430 base::DictionaryValue* value = new base::DictionaryValue(); | 431 std::unique_ptr<base::DictionaryValue> value = |
| 432 base::MakeUnique<base::DictionaryValue>(); |
| 431 value->SetString(kName, supervised_user.name()); | 433 value->SetString(kName, supervised_user.name()); |
| 432 value->SetBoolean(kAcknowledged, supervised_user.acknowledged()); | 434 value->SetBoolean(kAcknowledged, supervised_user.acknowledged()); |
| 433 value->SetString(kMasterKey, supervised_user.master_key()); | 435 value->SetString(kMasterKey, supervised_user.master_key()); |
| 434 value->SetString(kChromeAvatar, supervised_user.chrome_avatar()); | 436 value->SetString(kChromeAvatar, supervised_user.chrome_avatar()); |
| 435 value->SetString(kChromeOsAvatar, supervised_user.chromeos_avatar()); | 437 value->SetString(kChromeOsAvatar, supervised_user.chromeos_avatar()); |
| 436 value->SetString(kPasswordSignatureKey, | 438 value->SetString(kPasswordSignatureKey, |
| 437 supervised_user.password_signature_key()); | 439 supervised_user.password_signature_key()); |
| 438 value->SetString(kPasswordEncryptionKey, | 440 value->SetString(kPasswordEncryptionKey, |
| 439 supervised_user.password_encryption_key()); | 441 supervised_user.password_encryption_key()); |
| 440 if (dict->HasKey(supervised_user.id())) | 442 if (dict->HasKey(supervised_user.id())) |
| 441 num_items_modified++; | 443 num_items_modified++; |
| 442 else | 444 else |
| 443 num_items_added++; | 445 num_items_added++; |
| 444 dict->SetWithoutPathExpansion(supervised_user.id(), value); | 446 dict->SetWithoutPathExpansion(supervised_user.id(), std::move(value)); |
| 445 seen_ids.insert(supervised_user.id()); | 447 seen_ids.insert(supervised_user.id()); |
| 446 } | 448 } |
| 447 | 449 |
| 448 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 450 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
| 449 if (seen_ids.find(it.key()) != seen_ids.end()) | 451 if (seen_ids.find(it.key()) != seen_ids.end()) |
| 450 continue; | 452 continue; |
| 451 | 453 |
| 452 change_list.push_back( | 454 change_list.push_back( |
| 453 SyncChange(FROM_HERE, | 455 SyncChange(FROM_HERE, |
| 454 SyncChange::ACTION_ADD, | 456 SyncChange::ACTION_ADD, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 // an add action, it should not. | 511 // an add action, it should not. |
| 510 DCHECK_EQ( | 512 DCHECK_EQ( |
| 511 old_value ? SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD, | 513 old_value ? SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD, |
| 512 sync_change.change_type()); | 514 sync_change.change_type()); |
| 513 | 515 |
| 514 // If the supervised user switched from unacknowledged to acknowledged, | 516 // If the supervised user switched from unacknowledged to acknowledged, |
| 515 // we might need to continue with a registration. | 517 // we might need to continue with a registration. |
| 516 if (old_value && !old_value->HasKey(kAcknowledged)) | 518 if (old_value && !old_value->HasKey(kAcknowledged)) |
| 517 NotifySupervisedUserAcknowledged(supervised_user.id()); | 519 NotifySupervisedUserAcknowledged(supervised_user.id()); |
| 518 | 520 |
| 519 base::DictionaryValue* value = new base::DictionaryValue; | 521 std::unique_ptr<base::DictionaryValue> value = |
| 522 base::MakeUnique<base::DictionaryValue>(); |
| 520 value->SetString(kName, supervised_user.name()); | 523 value->SetString(kName, supervised_user.name()); |
| 521 value->SetBoolean(kAcknowledged, supervised_user.acknowledged()); | 524 value->SetBoolean(kAcknowledged, supervised_user.acknowledged()); |
| 522 value->SetString(kMasterKey, supervised_user.master_key()); | 525 value->SetString(kMasterKey, supervised_user.master_key()); |
| 523 value->SetString(kChromeAvatar, supervised_user.chrome_avatar()); | 526 value->SetString(kChromeAvatar, supervised_user.chrome_avatar()); |
| 524 value->SetString(kChromeOsAvatar, supervised_user.chromeos_avatar()); | 527 value->SetString(kChromeOsAvatar, supervised_user.chromeos_avatar()); |
| 525 value->SetString(kPasswordSignatureKey, | 528 value->SetString(kPasswordSignatureKey, |
| 526 supervised_user.password_signature_key()); | 529 supervised_user.password_signature_key()); |
| 527 value->SetString(kPasswordEncryptionKey, | 530 value->SetString(kPasswordEncryptionKey, |
| 528 supervised_user.password_encryption_key()); | 531 supervised_user.password_encryption_key()); |
| 529 dict->SetWithoutPathExpansion(supervised_user.id(), value); | 532 dict->SetWithoutPathExpansion(supervised_user.id(), std::move(value)); |
| 530 | 533 |
| 531 NotifySupervisedUsersChanged(); | 534 NotifySupervisedUsersChanged(); |
| 532 break; | 535 break; |
| 533 } | 536 } |
| 534 case SyncChange::ACTION_DELETE: { | 537 case SyncChange::ACTION_DELETE: { |
| 535 DCHECK(dict->HasKey(supervised_user.id())) << supervised_user.id(); | 538 DCHECK(dict->HasKey(supervised_user.id())) << supervised_user.id(); |
| 536 dict->RemoveWithoutPathExpansion(supervised_user.id(), NULL); | 539 dict->RemoveWithoutPathExpansion(supervised_user.id(), NULL); |
| 537 break; | 540 break; |
| 538 } | 541 } |
| 539 case SyncChange::ACTION_INVALID: { | 542 case SyncChange::ACTION_INVALID: { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 OnSupervisedUsersChanged()); | 575 OnSupervisedUsersChanged()); |
| 573 } | 576 } |
| 574 | 577 |
| 575 void SupervisedUserSyncService::DispatchCallbacks() { | 578 void SupervisedUserSyncService::DispatchCallbacks() { |
| 576 const base::DictionaryValue* supervised_users = | 579 const base::DictionaryValue* supervised_users = |
| 577 prefs_->GetDictionary(prefs::kSupervisedUsers); | 580 prefs_->GetDictionary(prefs::kSupervisedUsers); |
| 578 for (const auto& callback : callbacks_) | 581 for (const auto& callback : callbacks_) |
| 579 callback.Run(supervised_users); | 582 callback.Run(supervised_users); |
| 580 callbacks_.clear(); | 583 callbacks_.clear(); |
| 581 } | 584 } |
| OLD | NEW |