Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: chrome/browser/supervised_user/supervised_user_pref_mapping_service.cc

Issue 335833003: Rename "managed (mode|user)" to "supervised user" (part 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments (+ a few other cleanups) Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/managed_mode/supervised_user_pref_mapping_service.h" 5 #include "chrome/browser/supervised_user/supervised_user_pref_mapping_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/managed_mode/managed_user_constants.h" 10 #include "chrome/browser/supervised_user/supervised_user_constants.h"
11 #include "chrome/browser/managed_mode/managed_user_shared_settings_service.h" 11 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service .h"
12 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 13
14 const int kNoAvatar = -1; 14 const int kNoAvatar = -1;
15 15
16 SupervisedUserPrefMappingService::SupervisedUserPrefMappingService( 16 SupervisedUserPrefMappingService::SupervisedUserPrefMappingService(
17 PrefService* prefs, 17 PrefService* prefs,
18 ManagedUserSharedSettingsService* shared_settings) 18 SupervisedUserSharedSettingsService* shared_settings)
19 : prefs_(prefs), 19 : prefs_(prefs),
20 shared_settings_(shared_settings), 20 shared_settings_(shared_settings),
21 managed_user_id_(prefs->GetString(prefs::kSupervisedUserId)), 21 supervised_user_id_(prefs->GetString(prefs::kSupervisedUserId)),
22 weak_ptr_factory_(this) {} 22 weak_ptr_factory_(this) {}
23 23
24 SupervisedUserPrefMappingService::~SupervisedUserPrefMappingService() {} 24 SupervisedUserPrefMappingService::~SupervisedUserPrefMappingService() {}
25 25
26 void SupervisedUserPrefMappingService::Init() { 26 void SupervisedUserPrefMappingService::Init() {
27 subscription_ = shared_settings_->Subscribe( 27 subscription_ = shared_settings_->Subscribe(
28 base::Bind(&SupervisedUserPrefMappingService::OnSharedSettingChanged, 28 base::Bind(&SupervisedUserPrefMappingService::OnSharedSettingChanged,
29 weak_ptr_factory_.GetWeakPtr())); 29 weak_ptr_factory_.GetWeakPtr()));
30 30
31 pref_change_registrar_.Init(prefs_); 31 pref_change_registrar_.Init(prefs_);
32 pref_change_registrar_.Add( 32 pref_change_registrar_.Add(
33 prefs::kProfileAvatarIndex, 33 prefs::kProfileAvatarIndex,
34 base::Bind(&SupervisedUserPrefMappingService::OnAvatarChanged, 34 base::Bind(&SupervisedUserPrefMappingService::OnAvatarChanged,
35 weak_ptr_factory_.GetWeakPtr())); 35 weak_ptr_factory_.GetWeakPtr()));
36 36
37 // Check if we need to update the shared setting with the avatar index. 37 // Check if we need to update the shared setting with the avatar index.
38 // Otherwise we update the user pref in case we missed a notification. 38 // Otherwise we update the user pref in case we missed a notification.
39 if (GetChromeAvatarIndex() == kNoAvatar) 39 if (GetChromeAvatarIndex() == kNoAvatar) {
40 OnAvatarChanged(); 40 OnAvatarChanged();
41 else 41 } else {
42 OnSharedSettingChanged(managed_user_id_, managed_users::kChromeAvatarIndex); 42 OnSharedSettingChanged(supervised_user_id_,
43 supervised_users::kChromeAvatarIndex);
44 }
43 } 45 }
44 46
45 void SupervisedUserPrefMappingService::OnAvatarChanged() { 47 void SupervisedUserPrefMappingService::OnAvatarChanged() {
46 int new_avatar_index = prefs_->GetInteger(prefs::kProfileAvatarIndex); 48 int new_avatar_index = prefs_->GetInteger(prefs::kProfileAvatarIndex);
47 if (new_avatar_index < 0) 49 if (new_avatar_index < 0)
48 return; 50 return;
49 51
50 // First check if the avatar index is a new value. 52 // First check if the avatar index is a new value.
51 if (GetChromeAvatarIndex() == new_avatar_index) 53 if (GetChromeAvatarIndex() == new_avatar_index)
52 return; 54 return;
53 55
54 // If yes, update the shared settings value. 56 // If yes, update the shared settings value.
55 shared_settings_->SetValue(managed_user_id_, 57 shared_settings_->SetValue(supervised_user_id_,
56 managed_users::kChromeAvatarIndex, 58 supervised_users::kChromeAvatarIndex,
57 base::FundamentalValue(new_avatar_index)); 59 base::FundamentalValue(new_avatar_index));
58 } 60 }
59 61
60 void SupervisedUserPrefMappingService::OnSharedSettingChanged( 62 void SupervisedUserPrefMappingService::OnSharedSettingChanged(
61 const std::string& mu_id, 63 const std::string& su_id,
62 const std::string& key) { 64 const std::string& key) {
63 DCHECK_EQ(mu_id, managed_user_id_); 65 DCHECK_EQ(su_id, supervised_user_id_);
64 if (key != managed_users::kChromeAvatarIndex) 66 if (key != supervised_users::kChromeAvatarIndex)
65 return; 67 return;
66 68
67 const base::Value* value = shared_settings_->GetValue(mu_id, key); 69 const base::Value* value = shared_settings_->GetValue(su_id, key);
68 int avatar_index; 70 int avatar_index;
69 bool success = value->GetAsInteger(&avatar_index); 71 bool success = value->GetAsInteger(&avatar_index);
70 DCHECK(success); 72 DCHECK(success);
71 prefs_->SetInteger(prefs::kProfileAvatarIndex, avatar_index); 73 prefs_->SetInteger(prefs::kProfileAvatarIndex, avatar_index);
72 } 74 }
73 75
74 void SupervisedUserPrefMappingService::Shutdown() { 76 void SupervisedUserPrefMappingService::Shutdown() {
75 subscription_.reset(); 77 subscription_.reset();
76 } 78 }
77 79
78 int SupervisedUserPrefMappingService::GetChromeAvatarIndex() { 80 int SupervisedUserPrefMappingService::GetChromeAvatarIndex() {
79 const base::Value* value = shared_settings_->GetValue( 81 const base::Value* value = shared_settings_->GetValue(
80 managed_user_id_, managed_users::kChromeAvatarIndex); 82 supervised_user_id_, supervised_users::kChromeAvatarIndex);
81 if (!value) 83 if (!value)
82 return kNoAvatar; 84 return kNoAvatar;
83 85
84 int current_avatar_index; 86 int current_avatar_index;
85 bool success = value->GetAsInteger(&current_avatar_index); 87 bool success = value->GetAsInteger(&current_avatar_index);
86 DCHECK(success); 88 DCHECK(success);
87 return current_avatar_index; 89 return current_avatar_index;
88 } 90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698