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

Side by Side Diff: chrome/browser/supervised_user/chromeos/supervised_user_password_service.cc

Issue 1165323004: We should use UserID object to identify users instead of username. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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/supervised_user/chromeos/supervised_user_password_servi ce.h" 5 #include "chrome/browser/supervised_user/chromeos/supervised_user_password_servi ce.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/chromeos/login/supervised/supervised_user_authenticatio n.h" 9 #include "chrome/browser/chromeos/login/supervised/supervised_user_authenticatio n.h"
10 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" 10 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
11 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" 11 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h"
12 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h" 12 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h"
13 #include "chrome/browser/supervised_user/supervised_user_constants.h" 13 #include "chrome/browser/supervised_user/supervised_user_constants.h"
14 #include "components/user_manager/user_id.h"
14 15
15 namespace chromeos { 16 namespace chromeos {
16 17
17 SupervisedUserPasswordService::SupervisedUserPasswordService() 18 SupervisedUserPasswordService::SupervisedUserPasswordService()
18 : weak_ptr_factory_(this) {} 19 : user_id_(std::string(), std::string()), weak_ptr_factory_(this) {}
19 20
20 SupervisedUserPasswordService::~SupervisedUserPasswordService() {} 21 SupervisedUserPasswordService::~SupervisedUserPasswordService() {}
21 22
22 void SupervisedUserPasswordService::Init( 23 void SupervisedUserPasswordService::Init(
23 const std::string& user_id, 24 const user_manager::UserID& user_id,
24 SupervisedUserSharedSettingsService* shared_settings_service) { 25 SupervisedUserSharedSettingsService* shared_settings_service) {
25 user_id_ = user_id; 26 user_id_ = user_id;
26 settings_service_ = shared_settings_service; 27 settings_service_ = shared_settings_service;
27 settings_service_subscription_ = settings_service_->Subscribe( 28 settings_service_subscription_ = settings_service_->Subscribe(
28 base::Bind(&SupervisedUserPasswordService::OnSharedSettingsChange, 29 base::Bind(&SupervisedUserPasswordService::OnSharedSettingsChange,
29 weak_ptr_factory_.GetWeakPtr())); 30 weak_ptr_factory_.GetWeakPtr()));
30 31
31 // Force value check in case we have missed some notification. 32 // Force value check in case we have missed some notification.
32 33
33 chromeos::SupervisedUserManager* supervised_user_manager = 34 chromeos::SupervisedUserManager* supervised_user_manager =
34 ChromeUserManager::Get()->GetSupervisedUserManager(); 35 ChromeUserManager::Get()->GetSupervisedUserManager();
35 36
36 OnSharedSettingsChange(supervised_user_manager->GetUserSyncId(user_id), 37 OnSharedSettingsChange(supervised_user_manager->GetUserSyncId(user_id),
37 supervised_users::kChromeOSPasswordData); 38 supervised_users::kChromeOSPasswordData);
38 } 39 }
39 40
40 void SupervisedUserPasswordService::OnSharedSettingsChange( 41 void SupervisedUserPasswordService::OnSharedSettingsChange(
41 const std::string& su_id, 42 const std::string& su_id,
42 const std::string& key) { 43 const std::string& key) {
43 if (key != supervised_users::kChromeOSPasswordData) 44 if (key != supervised_users::kChromeOSPasswordData)
44 return; 45 return;
45 chromeos::SupervisedUserManager* supervised_user_manager = 46 chromeos::SupervisedUserManager* supervised_user_manager =
46 ChromeUserManager::Get()->GetSupervisedUserManager(); 47 ChromeUserManager::Get()->GetSupervisedUserManager();
47 const user_manager::User* user = supervised_user_manager->FindBySyncId(su_id); 48 const user_manager::User* user = supervised_user_manager->FindBySyncId(su_id);
48 if (user == NULL) { 49 if (user == NULL) {
49 LOG(WARNING) << "Got notification for user not on device."; 50 LOG(WARNING) << "Got notification for user not on device.";
50 return; 51 return;
51 } 52 }
52 DCHECK(user_id_ == user->email()); 53 DCHECK(user_id_ == user->GetUserID());
53 if (user_id_ != user->email()) 54 if (user_id_ != user->GetUserID())
54 return; 55 return;
55 const base::Value* value = settings_service_->GetValue(su_id, key); 56 const base::Value* value = settings_service_->GetValue(su_id, key);
56 if (value == NULL) { 57 if (value == NULL) {
57 LOG(WARNING) << "Got empty value from sync."; 58 LOG(WARNING) << "Got empty value from sync.";
58 return; 59 return;
59 } 60 }
60 const base::DictionaryValue* dict; 61 const base::DictionaryValue* dict;
61 if (!value->GetAsDictionary(&dict)) { 62 if (!value->GetAsDictionary(&dict)) {
62 LOG(WARNING) << "Got non-dictionary value from sync."; 63 LOG(WARNING) << "Got non-dictionary value from sync.";
63 return; 64 return;
64 } 65 }
65 chromeos::SupervisedUserAuthentication* auth = 66 chromeos::SupervisedUserAuthentication* auth =
66 supervised_user_manager->GetAuthentication(); 67 supervised_user_manager->GetAuthentication();
67 if (!auth->NeedPasswordChange(user_id_, dict)) 68 if (!auth->NeedPasswordChange(user_id_, dict))
68 return; 69 return;
69 auth->ScheduleSupervisedPasswordChange(user_id_, dict); 70 auth->ScheduleSupervisedPasswordChange(user_id_, dict);
70 } 71 }
71 72
72 void SupervisedUserPasswordService::Shutdown() { 73 void SupervisedUserPasswordService::Shutdown() {
73 settings_service_subscription_.reset(); 74 settings_service_subscription_.reset();
74 } 75 }
75 76
76 } // namespace chromeos 77 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698