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/signin/easy_unlock_service_signin_chromeos.h" | 5 #include "chrome/browser/signin/easy_unlock_service_signin_chromeos.h" |
6 | 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" |
| 10 #include "base/values.h" |
| 11 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" |
| 12 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
| 13 #include "chromeos/chromeos_switches.h" |
| 14 #include "chromeos/login/auth/user_context.h" |
| 15 |
7 EasyUnlockServiceSignin::EasyUnlockServiceSignin(Profile* profile) | 16 EasyUnlockServiceSignin::EasyUnlockServiceSignin(Profile* profile) |
8 : EasyUnlockService(profile) { | 17 : EasyUnlockService(profile), |
| 18 weak_ptr_factory_(this) { |
9 } | 19 } |
10 | 20 |
11 EasyUnlockServiceSignin::~EasyUnlockServiceSignin() { | 21 EasyUnlockServiceSignin::~EasyUnlockServiceSignin() { |
12 } | 22 } |
13 | 23 |
| 24 void EasyUnlockServiceSignin::SetAssociatedUser(const std::string& user_id) { |
| 25 if (user_id_ == user_id) |
| 26 return; |
| 27 |
| 28 user_id_ = user_id; |
| 29 FetchCryptohomeKeys(); |
| 30 } |
| 31 |
14 EasyUnlockService::Type EasyUnlockServiceSignin::GetType() const { | 32 EasyUnlockService::Type EasyUnlockServiceSignin::GetType() const { |
15 return EasyUnlockService::TYPE_SIGNIN; | 33 return EasyUnlockService::TYPE_SIGNIN; |
16 } | 34 } |
17 | 35 |
18 std::string EasyUnlockServiceSignin::GetUserEmail() const { | 36 std::string EasyUnlockServiceSignin::GetUserEmail() const { |
19 // TODO(tbarzic): Implement this (http://crbug.com/401634). | 37 return user_id_; |
20 return ""; | |
21 } | 38 } |
22 | 39 |
23 void EasyUnlockServiceSignin::LaunchSetup() { | 40 void EasyUnlockServiceSignin::LaunchSetup() { |
24 NOTREACHED(); | 41 NOTREACHED(); |
25 } | 42 } |
26 | 43 |
27 const base::DictionaryValue* EasyUnlockServiceSignin::GetPermitAccess() const { | 44 const base::DictionaryValue* EasyUnlockServiceSignin::GetPermitAccess() const { |
28 // TODO(tbarzic): Implement this (http://crbug.com/401634). | 45 // TODO(tbarzic): Implement this (http://crbug.com/401634). |
29 return NULL; | 46 return NULL; |
30 } | 47 } |
31 | 48 |
32 void EasyUnlockServiceSignin::SetPermitAccess( | 49 void EasyUnlockServiceSignin::SetPermitAccess( |
33 const base::DictionaryValue& permit) { | 50 const base::DictionaryValue& permit) { |
34 NOTREACHED(); | 51 NOTREACHED(); |
35 } | 52 } |
36 | 53 |
37 void EasyUnlockServiceSignin::ClearPermitAccess() { | 54 void EasyUnlockServiceSignin::ClearPermitAccess() { |
38 NOTREACHED(); | 55 NOTREACHED(); |
39 } | 56 } |
40 | 57 |
41 const base::ListValue* EasyUnlockServiceSignin::GetRemoteDevices() const { | 58 const base::ListValue* EasyUnlockServiceSignin::GetRemoteDevices() const { |
42 // TODO(tbarzic): Implement this (http://crbug.com/401634). | 59 return remote_devices_value_.get(); |
43 return NULL; | |
44 } | 60 } |
45 | 61 |
46 void EasyUnlockServiceSignin::SetRemoteDevices( | 62 void EasyUnlockServiceSignin::SetRemoteDevices( |
47 const base::ListValue& devices) { | 63 const base::ListValue& devices) { |
48 NOTREACHED(); | 64 NOTREACHED(); |
49 } | 65 } |
50 | 66 |
51 void EasyUnlockServiceSignin::ClearRemoteDevices() { | 67 void EasyUnlockServiceSignin::ClearRemoteDevices() { |
52 NOTREACHED(); | 68 NOTREACHED(); |
53 } | 69 } |
54 | 70 |
55 void EasyUnlockServiceSignin::RunTurnOffFlow() { | 71 void EasyUnlockServiceSignin::RunTurnOffFlow() { |
56 NOTREACHED(); | 72 NOTREACHED(); |
57 } | 73 } |
58 | 74 |
59 void EasyUnlockServiceSignin::ResetTurnOffFlow() { | 75 void EasyUnlockServiceSignin::ResetTurnOffFlow() { |
60 NOTREACHED(); | 76 NOTREACHED(); |
61 } | 77 } |
62 | 78 |
63 EasyUnlockService::TurnOffFlowStatus | 79 EasyUnlockService::TurnOffFlowStatus |
64 EasyUnlockServiceSignin::GetTurnOffFlowStatus() const { | 80 EasyUnlockServiceSignin::GetTurnOffFlowStatus() const { |
65 return EasyUnlockService::IDLE; | 81 return EasyUnlockService::IDLE; |
66 } | 82 } |
67 | 83 |
| 84 std::string EasyUnlockServiceSignin::GetChallenge() const { |
| 85 // TODO(xiyuan): Use correct remote device instead of hard coded first one. |
| 86 size_t device_index = 0; |
| 87 return device_index < remote_devices_.size() |
| 88 ? remote_devices_[device_index].challenge |
| 89 : std::string(); |
| 90 } |
| 91 |
68 void EasyUnlockServiceSignin::InitializeInternal() { | 92 void EasyUnlockServiceSignin::InitializeInternal() { |
69 } | 93 } |
70 | 94 |
71 bool EasyUnlockServiceSignin::IsAllowedInternal() { | 95 bool EasyUnlockServiceSignin::IsAllowedInternal() { |
72 // TODO(tbarzic): Implement this (http://crbug.com/401634). | 96 return !user_id_.empty() && !remote_devices_.empty() && |
73 return false; | 97 CommandLine::ForCurrentProcess()->HasSwitch( |
| 98 chromeos::switches::kEnableEasySignin); |
74 } | 99 } |
75 | 100 |
| 101 void EasyUnlockServiceSignin::FetchCryptohomeKeys() { |
| 102 remote_devices_.clear(); |
| 103 remote_devices_value_.reset(); |
| 104 if (user_id_.empty()) { |
| 105 UpdateAppState(); |
| 106 return; |
| 107 } |
| 108 |
| 109 chromeos::EasyUnlockKeyManager* key_manager = |
| 110 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager(); |
| 111 DCHECK(key_manager); |
| 112 key_manager->GetDeviceDataList( |
| 113 chromeos::UserContext(user_id_), |
| 114 base::Bind(&EasyUnlockServiceSignin::OnCryptohomeKeysFetched, |
| 115 weak_ptr_factory_.GetWeakPtr())); |
| 116 } |
| 117 |
| 118 void EasyUnlockServiceSignin::OnCryptohomeKeysFetched( |
| 119 bool success, |
| 120 const chromeos::EasyUnlockDeviceKeyDataList& devices) { |
| 121 if (!success) { |
| 122 LOG(WARNING) << "Easy unlock cryptohome keys not found for user " |
| 123 << user_id_; |
| 124 return; |
| 125 } |
| 126 |
| 127 remote_devices_ = devices; |
| 128 remote_devices_value_.reset(new base::ListValue); |
| 129 chromeos::EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList( |
| 130 remote_devices_, remote_devices_value_.get()); |
| 131 |
| 132 UpdateAppState(); |
| 133 } |
OLD | NEW |