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

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: similarity 25 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);
Pam (message me for reviews) 2014/06/16 23:51:51 Now that this is multiple lines, the style guide m
43 } 44 }
44 45
45 void SupervisedUserPrefMappingService::OnAvatarChanged() { 46 void SupervisedUserPrefMappingService::OnAvatarChanged() {
46 int new_avatar_index = prefs_->GetInteger(prefs::kProfileAvatarIndex); 47 int new_avatar_index = prefs_->GetInteger(prefs::kProfileAvatarIndex);
47 if (new_avatar_index < 0) 48 if (new_avatar_index < 0)
48 return; 49 return;
49 50
50 // First check if the avatar index is a new value. 51 // First check if the avatar index is a new value.
51 if (GetChromeAvatarIndex() == new_avatar_index) 52 if (GetChromeAvatarIndex() == new_avatar_index)
52 return; 53 return;
53 54
54 // If yes, update the shared settings value. 55 // If yes, update the shared settings value.
55 shared_settings_->SetValue(managed_user_id_, 56 shared_settings_->SetValue(supervised_user_id_,
56 managed_users::kChromeAvatarIndex, 57 supervised_users::kChromeAvatarIndex,
57 base::FundamentalValue(new_avatar_index)); 58 base::FundamentalValue(new_avatar_index));
58 } 59 }
59 60
60 void SupervisedUserPrefMappingService::OnSharedSettingChanged( 61 void SupervisedUserPrefMappingService::OnSharedSettingChanged(
61 const std::string& mu_id, 62 const std::string& mu_id,
62 const std::string& key) { 63 const std::string& key) {
63 DCHECK_EQ(mu_id, managed_user_id_); 64 DCHECK_EQ(mu_id, supervised_user_id_);
64 if (key != managed_users::kChromeAvatarIndex) 65 if (key != supervised_users::kChromeAvatarIndex)
65 return; 66 return;
66 67
67 const base::Value* value = shared_settings_->GetValue(mu_id, key); 68 const base::Value* value = shared_settings_->GetValue(mu_id, key);
68 int avatar_index; 69 int avatar_index;
69 bool success = value->GetAsInteger(&avatar_index); 70 bool success = value->GetAsInteger(&avatar_index);
70 DCHECK(success); 71 DCHECK(success);
71 prefs_->SetInteger(prefs::kProfileAvatarIndex, avatar_index); 72 prefs_->SetInteger(prefs::kProfileAvatarIndex, avatar_index);
72 } 73 }
73 74
74 void SupervisedUserPrefMappingService::Shutdown() { 75 void SupervisedUserPrefMappingService::Shutdown() {
75 subscription_.reset(); 76 subscription_.reset();
76 } 77 }
77 78
78 int SupervisedUserPrefMappingService::GetChromeAvatarIndex() { 79 int SupervisedUserPrefMappingService::GetChromeAvatarIndex() {
79 const base::Value* value = shared_settings_->GetValue( 80 const base::Value* value = shared_settings_->GetValue(
80 managed_user_id_, managed_users::kChromeAvatarIndex); 81 supervised_user_id_, supervised_users::kChromeAvatarIndex);
81 if (!value) 82 if (!value)
82 return kNoAvatar; 83 return kNoAvatar;
83 84
84 int current_avatar_index; 85 int current_avatar_index;
85 bool success = value->GetAsInteger(&current_avatar_index); 86 bool success = value->GetAsInteger(&current_avatar_index);
86 DCHECK(success); 87 DCHECK(success);
87 return current_avatar_index; 88 return current_avatar_index;
88 } 89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698