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_sync_service.h" | 5 #include "chrome/browser/supervised_user/supervised_user_sync_service.h" |
6 | 6 |
| 7 #include <set> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/callback.h" | 10 #include "base/callback.h" |
9 #include "base/prefs/scoped_user_pref_update.h" | 11 #include "base/prefs/scoped_user_pref_update.h" |
10 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
12 #include "base/values.h" | 14 #include "base/values.h" |
13 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 15 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
14 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
15 #include "components/pref_registry/pref_registry_syncable.h" | 17 #include "components/pref_registry/pref_registry_syncable.h" |
16 #include "sync/api/sync_change.h" | 18 #include "sync/api/sync_change.h" |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 | 412 |
411 SyncChangeList change_list; | 413 SyncChangeList change_list; |
412 SyncMergeResult result(SUPERVISED_USERS); | 414 SyncMergeResult result(SUPERVISED_USERS); |
413 | 415 |
414 DictionaryPrefUpdate update(prefs_, prefs::kSupervisedUsers); | 416 DictionaryPrefUpdate update(prefs_, prefs::kSupervisedUsers); |
415 base::DictionaryValue* dict = update.Get(); | 417 base::DictionaryValue* dict = update.Get(); |
416 result.set_num_items_before_association(dict->size()); | 418 result.set_num_items_before_association(dict->size()); |
417 std::set<std::string> seen_ids; | 419 std::set<std::string> seen_ids; |
418 int num_items_added = 0; | 420 int num_items_added = 0; |
419 int num_items_modified = 0; | 421 int num_items_modified = 0; |
420 for (SyncDataList::const_iterator it = initial_sync_data.begin(); | 422 for (const SyncData& sync_data : initial_sync_data) { |
421 it != initial_sync_data.end(); ++it) { | 423 DCHECK_EQ(SUPERVISED_USERS, sync_data.GetDataType()); |
422 DCHECK_EQ(SUPERVISED_USERS, it->GetDataType()); | |
423 const ManagedUserSpecifics& supervised_user = | 424 const ManagedUserSpecifics& supervised_user = |
424 it->GetSpecifics().managed_user(); | 425 sync_data.GetSpecifics().managed_user(); |
425 base::DictionaryValue* value = new base::DictionaryValue(); | 426 base::DictionaryValue* value = new base::DictionaryValue(); |
426 value->SetString(kName, supervised_user.name()); | 427 value->SetString(kName, supervised_user.name()); |
427 value->SetBoolean(kAcknowledged, supervised_user.acknowledged()); | 428 value->SetBoolean(kAcknowledged, supervised_user.acknowledged()); |
428 value->SetString(kMasterKey, supervised_user.master_key()); | 429 value->SetString(kMasterKey, supervised_user.master_key()); |
429 value->SetString(kChromeAvatar, supervised_user.chrome_avatar()); | 430 value->SetString(kChromeAvatar, supervised_user.chrome_avatar()); |
430 value->SetString(kChromeOsAvatar, supervised_user.chromeos_avatar()); | 431 value->SetString(kChromeOsAvatar, supervised_user.chromeos_avatar()); |
431 value->SetString(kPasswordSignatureKey, | 432 value->SetString(kPasswordSignatureKey, |
432 supervised_user.password_signature_key()); | 433 supervised_user.password_signature_key()); |
433 value->SetString(kPasswordEncryptionKey, | 434 value->SetString(kPasswordEncryptionKey, |
434 supervised_user.password_encryption_key()); | 435 supervised_user.password_encryption_key()); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 | 480 |
480 return data; | 481 return data; |
481 } | 482 } |
482 | 483 |
483 SyncError SupervisedUserSyncService::ProcessSyncChanges( | 484 SyncError SupervisedUserSyncService::ProcessSyncChanges( |
484 const tracked_objects::Location& from_here, | 485 const tracked_objects::Location& from_here, |
485 const SyncChangeList& change_list) { | 486 const SyncChangeList& change_list) { |
486 SyncError error; | 487 SyncError error; |
487 DictionaryPrefUpdate update(prefs_, prefs::kSupervisedUsers); | 488 DictionaryPrefUpdate update(prefs_, prefs::kSupervisedUsers); |
488 base::DictionaryValue* dict = update.Get(); | 489 base::DictionaryValue* dict = update.Get(); |
489 for (SyncChangeList::const_iterator it = change_list.begin(); | 490 for (const SyncChange& sync_change : change_list) { |
490 it != change_list.end(); ++it) { | 491 SyncData data = sync_change.sync_data(); |
491 SyncData data = it->sync_data(); | |
492 DCHECK_EQ(SUPERVISED_USERS, data.GetDataType()); | 492 DCHECK_EQ(SUPERVISED_USERS, data.GetDataType()); |
493 const ManagedUserSpecifics& supervised_user = | 493 const ManagedUserSpecifics& supervised_user = |
494 data.GetSpecifics().managed_user(); | 494 data.GetSpecifics().managed_user(); |
495 switch (it->change_type()) { | 495 switch (sync_change.change_type()) { |
496 case SyncChange::ACTION_ADD: | 496 case SyncChange::ACTION_ADD: |
497 case SyncChange::ACTION_UPDATE: { | 497 case SyncChange::ACTION_UPDATE: { |
498 // Every item we get from the server should be acknowledged. | 498 // Every item we get from the server should be acknowledged. |
499 DCHECK(supervised_user.acknowledged()); | 499 DCHECK(supervised_user.acknowledged()); |
500 const base::DictionaryValue* old_value = NULL; | 500 const base::DictionaryValue* old_value = NULL; |
501 dict->GetDictionaryWithoutPathExpansion(supervised_user.id(), | 501 dict->GetDictionaryWithoutPathExpansion(supervised_user.id(), |
502 &old_value); | 502 &old_value); |
503 | 503 |
504 // For an update action, the supervised user should already exist, for | 504 // For an update action, the supervised user should already exist, for |
505 // an add action, it should not. | 505 // an add action, it should not. |
506 DCHECK_EQ( | 506 DCHECK_EQ( |
507 old_value ? SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD, | 507 old_value ? SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD, |
508 it->change_type()); | 508 sync_change.change_type()); |
509 | 509 |
510 // If the supervised user switched from unacknowledged to acknowledged, | 510 // If the supervised user switched from unacknowledged to acknowledged, |
511 // we might need to continue with a registration. | 511 // we might need to continue with a registration. |
512 if (old_value && !old_value->HasKey(kAcknowledged)) | 512 if (old_value && !old_value->HasKey(kAcknowledged)) |
513 NotifySupervisedUserAcknowledged(supervised_user.id()); | 513 NotifySupervisedUserAcknowledged(supervised_user.id()); |
514 | 514 |
515 base::DictionaryValue* value = new base::DictionaryValue; | 515 base::DictionaryValue* value = new base::DictionaryValue; |
516 value->SetString(kName, supervised_user.name()); | 516 value->SetString(kName, supervised_user.name()); |
517 value->SetBoolean(kAcknowledged, supervised_user.acknowledged()); | 517 value->SetBoolean(kAcknowledged, supervised_user.acknowledged()); |
518 value->SetString(kMasterKey, supervised_user.master_key()); | 518 value->SetString(kMasterKey, supervised_user.master_key()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 | 562 |
563 void SupervisedUserSyncService::NotifySupervisedUsersChanged() { | 563 void SupervisedUserSyncService::NotifySupervisedUsersChanged() { |
564 FOR_EACH_OBSERVER(SupervisedUserSyncServiceObserver, | 564 FOR_EACH_OBSERVER(SupervisedUserSyncServiceObserver, |
565 observers_, | 565 observers_, |
566 OnSupervisedUsersChanged()); | 566 OnSupervisedUsersChanged()); |
567 } | 567 } |
568 | 568 |
569 void SupervisedUserSyncService::DispatchCallbacks() { | 569 void SupervisedUserSyncService::DispatchCallbacks() { |
570 const base::DictionaryValue* supervised_users = | 570 const base::DictionaryValue* supervised_users = |
571 prefs_->GetDictionary(prefs::kSupervisedUsers); | 571 prefs_->GetDictionary(prefs::kSupervisedUsers); |
572 for (std::vector<SupervisedUsersCallback>::iterator it = callbacks_.begin(); | 572 for (const auto& callback : callbacks_) |
573 it != callbacks_.end(); ++it) { | 573 callback.Run(supervised_users); |
574 it->Run(supervised_users); | |
575 } | |
576 callbacks_.clear(); | 574 callbacks_.clear(); |
577 } | 575 } |
OLD | NEW |