OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/chromeos/cros/login_library.h" | 5 #include "chrome/browser/chromeos/cros/login_library.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "chrome/browser/chrome_thread.h" | 8 #include "chrome/browser/chrome_thread.h" |
9 #include "chrome/browser/chromeos/cros/cros_library.h" | 9 #include "chrome/browser/chromeos/cros/cros_library.h" |
10 | 10 |
11 namespace chromeos { | 11 namespace chromeos { |
12 | 12 |
13 class LoginLibraryImpl : public LoginLibrary { | 13 class LoginLibraryImpl : public LoginLibrary { |
14 public: | 14 public: |
15 LoginLibraryImpl() | 15 LoginLibraryImpl() |
16 : set_owner_key_callback_(NULL) { | 16 : set_owner_key_callback_(NULL) { |
17 if (CrosLibrary::Get()->EnsureLoaded()) | 17 if (CrosLibrary::Get()->EnsureLoaded()) |
18 Init(); | 18 Init(); |
19 } | 19 } |
20 virtual ~LoginLibraryImpl() { | 20 virtual ~LoginLibraryImpl() { |
21 if (session_connection_) { | 21 if (session_connection_) { |
22 chromeos::DisconnectSession(session_connection_); | 22 chromeos::DisconnectSession(session_connection_); |
23 } | 23 } |
24 } | 24 } |
25 | 25 |
26 bool EmitLoginPromptReady() { | 26 bool EmitLoginPromptReady() { |
27 return chromeos::EmitLoginPromptReady(); | 27 return chromeos::EmitLoginPromptReady(); |
28 } | 28 } |
29 | 29 |
30 bool SetOwnerKey(const std::vector<uint8>& public_key_der, | 30 bool CheckWhitelist(const std::string& email, |
31 Delegate<bool>* callback) { | 31 std::vector<uint8>* OUT_signature) { |
32 DCHECK(callback) << "must provide a callback to SetOwnerKey()"; | 32 return chromeos::CheckWhitelist(email.c_str(), OUT_signature); |
| 33 } |
| 34 |
| 35 bool RetrieveProperty(const std::string& name, |
| 36 std::string* OUT_value, |
| 37 std::vector<uint8>* OUT_signature) { |
| 38 return chromeos::RetrieveProperty(name.c_str(), OUT_value, OUT_signature); |
| 39 } |
| 40 |
| 41 bool SetOwnerKeyAsync(const std::vector<uint8>& public_key_der, |
| 42 Delegate<bool>* callback) { |
| 43 DCHECK(callback) << "must provide a callback to SetOwnerKeyAsync()"; |
| 44 if (set_owner_key_callback_) |
| 45 return false; |
33 set_owner_key_callback_ = callback; | 46 set_owner_key_callback_ = callback; |
34 return chromeos::SetOwnerKey(public_key_der); | 47 return chromeos::SetOwnerKey(public_key_der); |
35 } | 48 } |
36 | 49 |
| 50 bool StorePropertyAsync(const std::string& name, |
| 51 const std::string& value, |
| 52 const std::vector<uint8>& signature, |
| 53 Delegate<bool>* callback) { |
| 54 DCHECK(callback) << "must provide a callback to StorePropertyAsync()"; |
| 55 if (property_op_callback_) |
| 56 return false; |
| 57 property_op_callback_ = callback; |
| 58 return chromeos::StoreProperty(name.c_str(), value.c_str(), signature); |
| 59 } |
| 60 |
| 61 bool UnwhitelistAsync(const std::string& email, |
| 62 const std::vector<uint8>& signature, |
| 63 Delegate<bool>* callback) { |
| 64 DCHECK(callback) << "must provide a callback to UnwhitelistAsync()"; |
| 65 if (whitelist_op_callback_) |
| 66 return false; |
| 67 whitelist_op_callback_ = callback; |
| 68 return chromeos::Unwhitelist(email.c_str(), signature); |
| 69 } |
| 70 |
| 71 bool WhitelistAsync(const std::string& email, |
| 72 const std::vector<uint8>& signature, |
| 73 Delegate<bool>* callback) { |
| 74 DCHECK(callback) << "must provide a callback to WhitelistAsync()"; |
| 75 if (whitelist_op_callback_) |
| 76 return false; |
| 77 whitelist_op_callback_ = callback; |
| 78 return chromeos::Whitelist(email.c_str(), signature); |
| 79 } |
| 80 |
37 bool StartSession(const std::string& user_email, | 81 bool StartSession(const std::string& user_email, |
38 const std::string& unique_id /* unused */) { | 82 const std::string& unique_id /* unused */) { |
39 // only pass unique_id through once we use it for something. | 83 // only pass unique_id through once we use it for something. |
40 return chromeos::StartSession(user_email.c_str(), ""); | 84 return chromeos::StartSession(user_email.c_str(), ""); |
41 } | 85 } |
42 | 86 |
43 bool StopSession(const std::string& unique_id /* unused */) { | 87 bool StopSession(const std::string& unique_id /* unused */) { |
44 // only pass unique_id through once we use it for something. | 88 // only pass unique_id through once we use it for something. |
45 return chromeos::StopSession(""); | 89 return chromeos::StopSession(""); |
46 } | 90 } |
47 | 91 |
48 bool RestartJob(int pid, const std::string& command_line) { | 92 bool RestartJob(int pid, const std::string& command_line) { |
49 return chromeos::RestartJob(pid, command_line.c_str()); | 93 return chromeos::RestartJob(pid, command_line.c_str()); |
50 } | 94 } |
51 | 95 |
52 private: | 96 private: |
53 static void Handler(void* object, const OwnershipEvent& event) { | 97 static void Handler(void* object, const OwnershipEvent& event) { |
54 LoginLibraryImpl* self = static_cast<LoginLibraryImpl*>(object); | 98 LoginLibraryImpl* self = static_cast<LoginLibraryImpl*>(object); |
55 switch (event) { | 99 switch (event) { |
56 case SetKeySuccess: | 100 case SetKeySuccess: |
57 self->CompleteSetOwnerKey(true); | 101 self->CompleteSetOwnerKey(true); |
58 break; | 102 break; |
59 case SetKeyFailure: | 103 case SetKeyFailure: |
60 self->CompleteSetOwnerKey(false); | 104 self->CompleteSetOwnerKey(false); |
61 break; | 105 break; |
62 case WhitelistOpSuccess: | 106 case WhitelistOpSuccess: |
| 107 self->CompleteWhitelistOp(true); |
| 108 break; |
63 case WhitelistOpFailure: | 109 case WhitelistOpFailure: |
| 110 self->CompleteWhitelistOp(false); |
| 111 break; |
64 case PropertyOpSuccess: | 112 case PropertyOpSuccess: |
| 113 self->CompletePropertyOp(true); |
| 114 break; |
65 case PropertyOpFailure: | 115 case PropertyOpFailure: |
66 NOTIMPLEMENTED(); | 116 self->CompletePropertyOp(false); |
67 break; | 117 break; |
68 default: | 118 default: |
69 NOTREACHED(); | 119 NOTREACHED(); |
| 120 break; |
70 } | 121 } |
71 } | 122 } |
72 | 123 |
73 void Init() { | 124 void Init() { |
74 session_connection_ = chromeos::MonitorSession(&Handler, this); | 125 session_connection_ = chromeos::MonitorSession(&Handler, this); |
75 } | 126 } |
76 | 127 |
77 void CompleteSetOwnerKey(bool result) { | 128 void CompleteSetOwnerKey(bool result) { |
78 CHECK(set_owner_key_callback_) << "CompleteSetOwnerKey() called without " | 129 CHECK(set_owner_key_callback_) << "CompleteSetOwnerKey() called without " |
79 "a registered callback!"; | 130 "a registered callback!"; |
80 set_owner_key_callback_->Run(result); | 131 set_owner_key_callback_->Run(result); |
81 set_owner_key_callback_ = NULL; | 132 set_owner_key_callback_ = NULL; |
82 } | 133 } |
83 | 134 |
| 135 void CompleteWhitelistOp(bool result) { |
| 136 CHECK(whitelist_op_callback_); |
| 137 whitelist_op_callback_->Run(result); |
| 138 whitelist_op_callback_ = NULL; |
| 139 } |
| 140 |
| 141 void CompletePropertyOp(bool result) { |
| 142 CHECK(property_op_callback_); |
| 143 property_op_callback_->Run(result); |
| 144 property_op_callback_ = NULL; |
| 145 } |
| 146 |
84 chromeos::SessionConnection session_connection_; | 147 chromeos::SessionConnection session_connection_; |
85 | 148 |
86 Delegate<bool>* set_owner_key_callback_; | 149 Delegate<bool>* set_owner_key_callback_; |
| 150 Delegate<bool>* whitelist_op_callback_; |
| 151 Delegate<bool>* property_op_callback_; |
87 | 152 |
88 DISALLOW_COPY_AND_ASSIGN(LoginLibraryImpl); | 153 DISALLOW_COPY_AND_ASSIGN(LoginLibraryImpl); |
89 }; | 154 }; |
90 | 155 |
91 class LoginLibraryStubImpl : public LoginLibrary { | 156 class LoginLibraryStubImpl : public LoginLibrary { |
92 public: | 157 public: |
93 LoginLibraryStubImpl() {} | 158 LoginLibraryStubImpl() {} |
94 virtual ~LoginLibraryStubImpl() {} | 159 virtual ~LoginLibraryStubImpl() {} |
95 | 160 |
96 bool EmitLoginPromptReady() { return true; } | 161 bool EmitLoginPromptReady() { return true; } |
97 bool SetOwnerKey(const std::vector<uint8>& public_key_der, | 162 bool CheckWhitelist(const std::string& email, |
98 Delegate<bool>* callback) { | 163 std::vector<uint8>* OUT_signature) { |
| 164 OUT_signature->assign(2, 0); |
| 165 return true; |
| 166 } |
| 167 bool RetrieveProperty(const std::string& name, |
| 168 std::string* OUT_value, |
| 169 std::vector<uint8>* OUT_signature) { |
| 170 OUT_value->assign("stub"); |
| 171 OUT_signature->assign(2, 0); |
| 172 return true; |
| 173 } |
| 174 bool SetOwnerKeyAsync(const std::vector<uint8>& public_key_der, |
| 175 Delegate<bool>* callback) { |
99 ChromeThread::PostTask( | 176 ChromeThread::PostTask( |
100 ChromeThread::UI, FROM_HERE, | 177 ChromeThread::UI, FROM_HERE, |
101 NewRunnableFunction(&SetOwnerKeyStubCallback, callback)); | 178 NewRunnableFunction(&DoStubCallback, callback)); |
| 179 return true; |
| 180 } |
| 181 bool StorePropertyAsync(const std::string& name, |
| 182 const std::string& value, |
| 183 const std::vector<uint8>& signature, |
| 184 Delegate<bool>* callback) { |
| 185 ChromeThread::PostTask( |
| 186 ChromeThread::UI, FROM_HERE, |
| 187 NewRunnableFunction(&DoStubCallback, callback)); |
| 188 return true; |
| 189 } |
| 190 bool UnwhitelistAsync(const std::string& email, |
| 191 const std::vector<uint8>& signature, |
| 192 Delegate<bool>* callback) { |
| 193 ChromeThread::PostTask( |
| 194 ChromeThread::UI, FROM_HERE, |
| 195 NewRunnableFunction(&DoStubCallback, callback)); |
| 196 return true; |
| 197 } |
| 198 bool WhitelistAsync(const std::string& email, |
| 199 const std::vector<uint8>& signature, |
| 200 Delegate<bool>* callback) { |
| 201 ChromeThread::PostTask( |
| 202 ChromeThread::UI, FROM_HERE, |
| 203 NewRunnableFunction(&DoStubCallback, callback)); |
102 return true; | 204 return true; |
103 } | 205 } |
104 bool StartSession(const std::string& user_email, | 206 bool StartSession(const std::string& user_email, |
105 const std::string& unique_id /* unused */) { return true; } | 207 const std::string& unique_id /* unused */) { return true; } |
106 bool StopSession(const std::string& unique_id /* unused */) { return true; } | 208 bool StopSession(const std::string& unique_id /* unused */) { return true; } |
107 bool RestartJob(int pid, const std::string& command_line) { return true; } | 209 bool RestartJob(int pid, const std::string& command_line) { return true; } |
108 | 210 |
109 private: | 211 private: |
110 static void SetOwnerKeyStubCallback(Delegate<bool>* callback) { | 212 static void DoStubCallback(Delegate<bool>* callback) { |
111 callback->Run(true); | 213 callback->Run(true); |
112 } | 214 } |
113 | 215 |
114 DISALLOW_COPY_AND_ASSIGN(LoginLibraryStubImpl); | 216 DISALLOW_COPY_AND_ASSIGN(LoginLibraryStubImpl); |
115 }; | 217 }; |
116 | 218 |
117 // static | 219 // static |
118 LoginLibrary* LoginLibrary::GetImpl(bool stub) { | 220 LoginLibrary* LoginLibrary::GetImpl(bool stub) { |
119 if (stub) | 221 if (stub) |
120 return new LoginLibraryStubImpl(); | 222 return new LoginLibraryStubImpl(); |
121 else | 223 else |
122 return new LoginLibraryImpl(); | 224 return new LoginLibraryImpl(); |
123 } | 225 } |
124 | 226 |
125 } // namespace chromeos | 227 } // namespace chromeos |
OLD | NEW |