OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "remoting/host/setup/me2me_native_messaging_host.h" | 5 #include "remoting/host/setup/me2me_native_messaging_host.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/callback_helpers.h" | |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/strings/stringize_macros.h" | 14 #include "base/strings/stringize_macros.h" |
14 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
15 #include "base/values.h" | 16 #include "base/values.h" |
16 #include "google_apis/gaia/gaia_oauth_client.h" | 17 #include "google_apis/gaia/gaia_oauth_client.h" |
17 #include "google_apis/google_api_keys.h" | 18 #include "google_apis/google_api_keys.h" |
18 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
19 #include "remoting/base/rsa_key_pair.h" | 20 #include "remoting/base/rsa_key_pair.h" |
20 #include "remoting/host/pin_hash.h" | 21 #include "remoting/host/pin_hash.h" |
21 #include "remoting/host/setup/oauth_client.h" | 22 #include "remoting/host/setup/oauth_client.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
45 LOG(ERROR) << "'config' dictionary not found"; | 46 LOG(ERROR) << "'config' dictionary not found"; |
46 } | 47 } |
47 return result.Pass(); | 48 return result.Pass(); |
48 } | 49 } |
49 | 50 |
50 } // namespace | 51 } // namespace |
51 | 52 |
52 namespace remoting { | 53 namespace remoting { |
53 | 54 |
54 NativeMessagingHost::NativeMessagingHost( | 55 NativeMessagingHost::NativeMessagingHost( |
56 scoped_ptr<NativeMessagingChannel> channel, | |
55 scoped_refptr<DaemonController> daemon_controller, | 57 scoped_refptr<DaemonController> daemon_controller, |
56 scoped_refptr<protocol::PairingRegistry> pairing_registry, | 58 scoped_refptr<protocol::PairingRegistry> pairing_registry, |
57 scoped_ptr<OAuthClient> oauth_client) | 59 scoped_ptr<OAuthClient> oauth_client) |
58 : daemon_controller_(daemon_controller), | 60 : channel_(channel.Pass()), |
61 daemon_controller_(daemon_controller), | |
59 pairing_registry_(pairing_registry), | 62 pairing_registry_(pairing_registry), |
60 oauth_client_(oauth_client.Pass()), | 63 oauth_client_(oauth_client.Pass()), |
61 weak_factory_(this) { | 64 weak_factory_(this) { |
62 weak_ptr_ = weak_factory_.GetWeakPtr(); | 65 weak_ptr_ = weak_factory_.GetWeakPtr(); |
63 } | 66 } |
64 | 67 |
65 NativeMessagingHost::~NativeMessagingHost() { | 68 NativeMessagingHost::~NativeMessagingHost() { |
69 DCHECK(thread_checker_.CalledOnValidThread()); | |
66 } | 70 } |
67 | 71 |
68 void NativeMessagingHost::SetSendMessageCallback( | 72 void NativeMessagingHost::Start( |
69 const SendMessageCallback& send_message) { | 73 const base::Closure& quit_closure) { |
70 send_message_ = send_message; | 74 DCHECK(thread_checker_.CalledOnValidThread()); |
75 | |
76 channel_->Start( | |
77 base::Bind(&NativeMessagingHost::ProcessMessage, weak_ptr_), | |
78 quit_closure); | |
71 } | 79 } |
72 | 80 |
73 void NativeMessagingHost::ProcessMessage( | 81 void NativeMessagingHost::ProcessMessage( |
74 scoped_ptr<base::DictionaryValue> message) { | 82 scoped_ptr<base::DictionaryValue> message) { |
83 DCHECK(thread_checker_.CalledOnValidThread()); | |
84 | |
75 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue()); | 85 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue()); |
76 | 86 |
77 // If the client supplies an ID, it will expect it in the response. This | 87 // If the client supplies an ID, it will expect it in the response. This |
78 // might be a string or a number, so cope with both. | 88 // might be a string or a number, so cope with both. |
79 const base::Value* id; | 89 const base::Value* id; |
80 if (message->Get("id", &id)) | 90 if (message->Get("id", &id)) |
81 response->Set("id", id->DeepCopy()); | 91 response->Set("id", id->DeepCopy()); |
82 | 92 |
83 std::string type; | 93 std::string type; |
84 if (!message->GetString("type", &type)) { | 94 if (!message->GetString("type", &type)) { |
85 LOG(ERROR) << "'type' not found"; | 95 LOG(ERROR) << "'type' not found"; |
86 send_message_.Run(scoped_ptr<base::DictionaryValue>()); | 96 channel_->SendMessage(scoped_ptr<base::DictionaryValue>()); |
87 return; | 97 return; |
88 } | 98 } |
89 | 99 |
90 response->SetString("type", type + "Response"); | 100 response->SetString("type", type + "Response"); |
91 | 101 |
92 bool success = false; | 102 bool success = false; |
93 if (type == "hello") { | 103 if (type == "hello") { |
94 success = ProcessHello(*message, response.Pass()); | 104 success = ProcessHello(*message, response.Pass()); |
95 } else if (type == "clearPairedClients") { | 105 } else if (type == "clearPairedClients") { |
96 success = ProcessClearPairedClients(*message, response.Pass()); | 106 success = ProcessClearPairedClients(*message, response.Pass()); |
(...skipping 21 matching lines...) Expand all Loading... | |
118 success = ProcessGetDaemonState(*message, response.Pass()); | 128 success = ProcessGetDaemonState(*message, response.Pass()); |
119 } else if (type == "getHostClientId") { | 129 } else if (type == "getHostClientId") { |
120 success = ProcessGetHostClientId(*message, response.Pass()); | 130 success = ProcessGetHostClientId(*message, response.Pass()); |
121 } else if (type == "getCredentialsFromAuthCode") { | 131 } else if (type == "getCredentialsFromAuthCode") { |
122 success = ProcessGetCredentialsFromAuthCode(*message, response.Pass()); | 132 success = ProcessGetCredentialsFromAuthCode(*message, response.Pass()); |
123 } else { | 133 } else { |
124 LOG(ERROR) << "Unsupported request type: " << type; | 134 LOG(ERROR) << "Unsupported request type: " << type; |
125 } | 135 } |
126 | 136 |
127 if (!success) | 137 if (!success) |
128 send_message_.Run(scoped_ptr<base::DictionaryValue>()); | 138 channel_->SendMessage(scoped_ptr<base::DictionaryValue>()); |
129 } | 139 } |
130 | 140 |
131 bool NativeMessagingHost::ProcessHello( | 141 bool NativeMessagingHost::ProcessHello( |
132 const base::DictionaryValue& message, | 142 const base::DictionaryValue& message, |
133 scoped_ptr<base::DictionaryValue> response) { | 143 scoped_ptr<base::DictionaryValue> response) { |
144 DCHECK(thread_checker_.CalledOnValidThread()); | |
Sergey Ulanov
2013/12/12 23:55:16
I'm not sure these checks in Process*() are useful
| |
145 | |
134 response->SetString("version", STRINGIZE(VERSION)); | 146 response->SetString("version", STRINGIZE(VERSION)); |
135 scoped_ptr<base::ListValue> supported_features_list(new base::ListValue()); | 147 scoped_ptr<base::ListValue> supported_features_list(new base::ListValue()); |
136 supported_features_list->AppendStrings(std::vector<std::string>( | 148 supported_features_list->AppendStrings(std::vector<std::string>( |
137 kSupportedFeatures, kSupportedFeatures + arraysize(kSupportedFeatures))); | 149 kSupportedFeatures, kSupportedFeatures + arraysize(kSupportedFeatures))); |
138 response->Set("supportedFeatures", supported_features_list.release()); | 150 response->Set("supportedFeatures", supported_features_list.release()); |
139 send_message_.Run(response.Pass()); | 151 channel_->SendMessage(response.Pass()); |
140 return true; | 152 return true; |
141 } | 153 } |
142 | 154 |
143 bool NativeMessagingHost::ProcessClearPairedClients( | 155 bool NativeMessagingHost::ProcessClearPairedClients( |
144 const base::DictionaryValue& message, | 156 const base::DictionaryValue& message, |
145 scoped_ptr<base::DictionaryValue> response) { | 157 scoped_ptr<base::DictionaryValue> response) { |
158 DCHECK(thread_checker_.CalledOnValidThread()); | |
159 | |
146 if (pairing_registry_) { | 160 if (pairing_registry_) { |
147 pairing_registry_->ClearAllPairings( | 161 pairing_registry_->ClearAllPairings( |
148 base::Bind(&NativeMessagingHost::SendBooleanResult, weak_ptr_, | 162 base::Bind(&NativeMessagingHost::SendBooleanResult, weak_ptr_, |
149 base::Passed(&response))); | 163 base::Passed(&response))); |
150 } else { | 164 } else { |
151 SendBooleanResult(response.Pass(), false); | 165 SendBooleanResult(response.Pass(), false); |
152 } | 166 } |
153 return true; | 167 return true; |
154 } | 168 } |
155 | 169 |
156 bool NativeMessagingHost::ProcessDeletePairedClient( | 170 bool NativeMessagingHost::ProcessDeletePairedClient( |
157 const base::DictionaryValue& message, | 171 const base::DictionaryValue& message, |
158 scoped_ptr<base::DictionaryValue> response) { | 172 scoped_ptr<base::DictionaryValue> response) { |
173 DCHECK(thread_checker_.CalledOnValidThread()); | |
174 | |
159 std::string client_id; | 175 std::string client_id; |
160 if (!message.GetString(protocol::PairingRegistry::kClientIdKey, &client_id)) { | 176 if (!message.GetString(protocol::PairingRegistry::kClientIdKey, &client_id)) { |
161 LOG(ERROR) << "'" << protocol::PairingRegistry::kClientIdKey | 177 LOG(ERROR) << "'" << protocol::PairingRegistry::kClientIdKey |
162 << "' string not found."; | 178 << "' string not found."; |
163 return false; | 179 return false; |
164 } | 180 } |
165 | 181 |
166 if (pairing_registry_) { | 182 if (pairing_registry_) { |
167 pairing_registry_->DeletePairing( | 183 pairing_registry_->DeletePairing( |
168 client_id, base::Bind(&NativeMessagingHost::SendBooleanResult, | 184 client_id, base::Bind(&NativeMessagingHost::SendBooleanResult, |
169 weak_ptr_, base::Passed(&response))); | 185 weak_ptr_, base::Passed(&response))); |
170 } else { | 186 } else { |
171 SendBooleanResult(response.Pass(), false); | 187 SendBooleanResult(response.Pass(), false); |
172 } | 188 } |
173 return true; | 189 return true; |
174 } | 190 } |
175 | 191 |
176 bool NativeMessagingHost::ProcessGetHostName( | 192 bool NativeMessagingHost::ProcessGetHostName( |
177 const base::DictionaryValue& message, | 193 const base::DictionaryValue& message, |
178 scoped_ptr<base::DictionaryValue> response) { | 194 scoped_ptr<base::DictionaryValue> response) { |
195 DCHECK(thread_checker_.CalledOnValidThread()); | |
196 | |
179 response->SetString("hostname", net::GetHostName()); | 197 response->SetString("hostname", net::GetHostName()); |
180 send_message_.Run(response.Pass()); | 198 channel_->SendMessage(response.Pass()); |
181 return true; | 199 return true; |
182 } | 200 } |
183 | 201 |
184 bool NativeMessagingHost::ProcessGetPinHash( | 202 bool NativeMessagingHost::ProcessGetPinHash( |
185 const base::DictionaryValue& message, | 203 const base::DictionaryValue& message, |
186 scoped_ptr<base::DictionaryValue> response) { | 204 scoped_ptr<base::DictionaryValue> response) { |
205 DCHECK(thread_checker_.CalledOnValidThread()); | |
206 | |
187 std::string host_id; | 207 std::string host_id; |
188 if (!message.GetString("hostId", &host_id)) { | 208 if (!message.GetString("hostId", &host_id)) { |
189 LOG(ERROR) << "'hostId' not found: " << message; | 209 LOG(ERROR) << "'hostId' not found: " << message; |
190 return false; | 210 return false; |
191 } | 211 } |
192 std::string pin; | 212 std::string pin; |
193 if (!message.GetString("pin", &pin)) { | 213 if (!message.GetString("pin", &pin)) { |
194 LOG(ERROR) << "'pin' not found: " << message; | 214 LOG(ERROR) << "'pin' not found: " << message; |
195 return false; | 215 return false; |
196 } | 216 } |
197 response->SetString("hash", MakeHostPinHash(host_id, pin)); | 217 response->SetString("hash", MakeHostPinHash(host_id, pin)); |
198 send_message_.Run(response.Pass()); | 218 channel_->SendMessage(response.Pass()); |
199 return true; | 219 return true; |
200 } | 220 } |
201 | 221 |
202 bool NativeMessagingHost::ProcessGenerateKeyPair( | 222 bool NativeMessagingHost::ProcessGenerateKeyPair( |
203 const base::DictionaryValue& message, | 223 const base::DictionaryValue& message, |
204 scoped_ptr<base::DictionaryValue> response) { | 224 scoped_ptr<base::DictionaryValue> response) { |
225 DCHECK(thread_checker_.CalledOnValidThread()); | |
226 | |
205 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate(); | 227 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate(); |
206 response->SetString("privateKey", key_pair->ToString()); | 228 response->SetString("privateKey", key_pair->ToString()); |
207 response->SetString("publicKey", key_pair->GetPublicKey()); | 229 response->SetString("publicKey", key_pair->GetPublicKey()); |
208 send_message_.Run(response.Pass()); | 230 channel_->SendMessage(response.Pass()); |
209 return true; | 231 return true; |
210 } | 232 } |
211 | 233 |
212 bool NativeMessagingHost::ProcessUpdateDaemonConfig( | 234 bool NativeMessagingHost::ProcessUpdateDaemonConfig( |
213 const base::DictionaryValue& message, | 235 const base::DictionaryValue& message, |
214 scoped_ptr<base::DictionaryValue> response) { | 236 scoped_ptr<base::DictionaryValue> response) { |
237 DCHECK(thread_checker_.CalledOnValidThread()); | |
238 | |
215 scoped_ptr<base::DictionaryValue> config_dict = | 239 scoped_ptr<base::DictionaryValue> config_dict = |
216 ConfigDictionaryFromMessage(message); | 240 ConfigDictionaryFromMessage(message); |
217 if (!config_dict) | 241 if (!config_dict) |
218 return false; | 242 return false; |
219 | 243 |
220 daemon_controller_->UpdateConfig( | 244 daemon_controller_->UpdateConfig( |
221 config_dict.Pass(), | 245 config_dict.Pass(), |
222 base::Bind(&NativeMessagingHost::SendAsyncResult, weak_ptr_, | 246 base::Bind(&NativeMessagingHost::SendAsyncResult, weak_ptr_, |
223 base::Passed(&response))); | 247 base::Passed(&response))); |
224 return true; | 248 return true; |
225 } | 249 } |
226 | 250 |
227 bool NativeMessagingHost::ProcessGetDaemonConfig( | 251 bool NativeMessagingHost::ProcessGetDaemonConfig( |
228 const base::DictionaryValue& message, | 252 const base::DictionaryValue& message, |
229 scoped_ptr<base::DictionaryValue> response) { | 253 scoped_ptr<base::DictionaryValue> response) { |
254 DCHECK(thread_checker_.CalledOnValidThread()); | |
255 | |
230 daemon_controller_->GetConfig( | 256 daemon_controller_->GetConfig( |
231 base::Bind(&NativeMessagingHost::SendConfigResponse, weak_ptr_, | 257 base::Bind(&NativeMessagingHost::SendConfigResponse, weak_ptr_, |
232 base::Passed(&response))); | 258 base::Passed(&response))); |
233 return true; | 259 return true; |
234 } | 260 } |
235 | 261 |
236 bool NativeMessagingHost::ProcessGetPairedClients( | 262 bool NativeMessagingHost::ProcessGetPairedClients( |
237 const base::DictionaryValue& message, | 263 const base::DictionaryValue& message, |
238 scoped_ptr<base::DictionaryValue> response) { | 264 scoped_ptr<base::DictionaryValue> response) { |
265 DCHECK(thread_checker_.CalledOnValidThread()); | |
266 | |
239 if (pairing_registry_) { | 267 if (pairing_registry_) { |
240 pairing_registry_->GetAllPairings( | 268 pairing_registry_->GetAllPairings( |
241 base::Bind(&NativeMessagingHost::SendPairedClientsResponse, weak_ptr_, | 269 base::Bind(&NativeMessagingHost::SendPairedClientsResponse, weak_ptr_, |
242 base::Passed(&response))); | 270 base::Passed(&response))); |
243 } else { | 271 } else { |
244 scoped_ptr<base::ListValue> no_paired_clients(new base::ListValue); | 272 scoped_ptr<base::ListValue> no_paired_clients(new base::ListValue); |
245 SendPairedClientsResponse(response.Pass(), no_paired_clients.Pass()); | 273 SendPairedClientsResponse(response.Pass(), no_paired_clients.Pass()); |
246 } | 274 } |
247 return true; | 275 return true; |
248 } | 276 } |
249 | 277 |
250 bool NativeMessagingHost::ProcessGetUsageStatsConsent( | 278 bool NativeMessagingHost::ProcessGetUsageStatsConsent( |
251 const base::DictionaryValue& message, | 279 const base::DictionaryValue& message, |
252 scoped_ptr<base::DictionaryValue> response) { | 280 scoped_ptr<base::DictionaryValue> response) { |
281 DCHECK(thread_checker_.CalledOnValidThread()); | |
282 | |
253 daemon_controller_->GetUsageStatsConsent( | 283 daemon_controller_->GetUsageStatsConsent( |
254 base::Bind(&NativeMessagingHost::SendUsageStatsConsentResponse, | 284 base::Bind(&NativeMessagingHost::SendUsageStatsConsentResponse, |
255 weak_ptr_, base::Passed(&response))); | 285 weak_ptr_, base::Passed(&response))); |
256 return true; | 286 return true; |
257 } | 287 } |
258 | 288 |
259 bool NativeMessagingHost::ProcessStartDaemon( | 289 bool NativeMessagingHost::ProcessStartDaemon( |
260 const base::DictionaryValue& message, | 290 const base::DictionaryValue& message, |
261 scoped_ptr<base::DictionaryValue> response) { | 291 scoped_ptr<base::DictionaryValue> response) { |
292 DCHECK(thread_checker_.CalledOnValidThread()); | |
293 | |
262 bool consent; | 294 bool consent; |
263 if (!message.GetBoolean("consent", &consent)) { | 295 if (!message.GetBoolean("consent", &consent)) { |
264 LOG(ERROR) << "'consent' not found."; | 296 LOG(ERROR) << "'consent' not found."; |
265 return false; | 297 return false; |
266 } | 298 } |
267 | 299 |
268 scoped_ptr<base::DictionaryValue> config_dict = | 300 scoped_ptr<base::DictionaryValue> config_dict = |
269 ConfigDictionaryFromMessage(message); | 301 ConfigDictionaryFromMessage(message); |
270 if (!config_dict) | 302 if (!config_dict) |
271 return false; | 303 return false; |
272 | 304 |
273 daemon_controller_->SetConfigAndStart( | 305 daemon_controller_->SetConfigAndStart( |
274 config_dict.Pass(), consent, | 306 config_dict.Pass(), consent, |
275 base::Bind(&NativeMessagingHost::SendAsyncResult, weak_ptr_, | 307 base::Bind(&NativeMessagingHost::SendAsyncResult, weak_ptr_, |
276 base::Passed(&response))); | 308 base::Passed(&response))); |
277 return true; | 309 return true; |
278 } | 310 } |
279 | 311 |
280 bool NativeMessagingHost::ProcessStopDaemon( | 312 bool NativeMessagingHost::ProcessStopDaemon( |
281 const base::DictionaryValue& message, | 313 const base::DictionaryValue& message, |
282 scoped_ptr<base::DictionaryValue> response) { | 314 scoped_ptr<base::DictionaryValue> response) { |
315 DCHECK(thread_checker_.CalledOnValidThread()); | |
316 | |
283 daemon_controller_->Stop( | 317 daemon_controller_->Stop( |
284 base::Bind(&NativeMessagingHost::SendAsyncResult, weak_ptr_, | 318 base::Bind(&NativeMessagingHost::SendAsyncResult, weak_ptr_, |
285 base::Passed(&response))); | 319 base::Passed(&response))); |
286 return true; | 320 return true; |
287 } | 321 } |
288 | 322 |
289 bool NativeMessagingHost::ProcessGetDaemonState( | 323 bool NativeMessagingHost::ProcessGetDaemonState( |
290 const base::DictionaryValue& message, | 324 const base::DictionaryValue& message, |
291 scoped_ptr<base::DictionaryValue> response) { | 325 scoped_ptr<base::DictionaryValue> response) { |
326 DCHECK(thread_checker_.CalledOnValidThread()); | |
327 | |
292 DaemonController::State state = daemon_controller_->GetState(); | 328 DaemonController::State state = daemon_controller_->GetState(); |
293 switch (state) { | 329 switch (state) { |
294 case DaemonController::STATE_NOT_IMPLEMENTED: | 330 case DaemonController::STATE_NOT_IMPLEMENTED: |
295 response->SetString("state", "NOT_IMPLEMENTED"); | 331 response->SetString("state", "NOT_IMPLEMENTED"); |
296 break; | 332 break; |
297 case DaemonController::STATE_NOT_INSTALLED: | 333 case DaemonController::STATE_NOT_INSTALLED: |
298 response->SetString("state", "NOT_INSTALLED"); | 334 response->SetString("state", "NOT_INSTALLED"); |
299 break; | 335 break; |
300 case DaemonController::STATE_INSTALLING: | 336 case DaemonController::STATE_INSTALLING: |
301 response->SetString("state", "INSTALLING"); | 337 response->SetString("state", "INSTALLING"); |
302 break; | 338 break; |
303 case DaemonController::STATE_STOPPED: | 339 case DaemonController::STATE_STOPPED: |
304 response->SetString("state", "STOPPED"); | 340 response->SetString("state", "STOPPED"); |
305 break; | 341 break; |
306 case DaemonController::STATE_STARTING: | 342 case DaemonController::STATE_STARTING: |
307 response->SetString("state", "STARTING"); | 343 response->SetString("state", "STARTING"); |
308 break; | 344 break; |
309 case DaemonController::STATE_STARTED: | 345 case DaemonController::STATE_STARTED: |
310 response->SetString("state", "STARTED"); | 346 response->SetString("state", "STARTED"); |
311 break; | 347 break; |
312 case DaemonController::STATE_STOPPING: | 348 case DaemonController::STATE_STOPPING: |
313 response->SetString("state", "STOPPING"); | 349 response->SetString("state", "STOPPING"); |
314 break; | 350 break; |
315 case DaemonController::STATE_UNKNOWN: | 351 case DaemonController::STATE_UNKNOWN: |
316 response->SetString("state", "UNKNOWN"); | 352 response->SetString("state", "UNKNOWN"); |
317 break; | 353 break; |
318 } | 354 } |
319 send_message_.Run(response.Pass()); | 355 channel_->SendMessage(response.Pass()); |
320 return true; | 356 return true; |
321 } | 357 } |
322 | 358 |
323 bool NativeMessagingHost::ProcessGetHostClientId( | 359 bool NativeMessagingHost::ProcessGetHostClientId( |
324 const base::DictionaryValue& message, | 360 const base::DictionaryValue& message, |
325 scoped_ptr<base::DictionaryValue> response) { | 361 scoped_ptr<base::DictionaryValue> response) { |
362 DCHECK(thread_checker_.CalledOnValidThread()); | |
363 | |
326 response->SetString("clientId", google_apis::GetOAuth2ClientID( | 364 response->SetString("clientId", google_apis::GetOAuth2ClientID( |
327 google_apis::CLIENT_REMOTING_HOST)); | 365 google_apis::CLIENT_REMOTING_HOST)); |
328 send_message_.Run(response.Pass()); | 366 channel_->SendMessage(response.Pass()); |
329 return true; | 367 return true; |
330 } | 368 } |
331 | 369 |
332 bool NativeMessagingHost::ProcessGetCredentialsFromAuthCode( | 370 bool NativeMessagingHost::ProcessGetCredentialsFromAuthCode( |
333 const base::DictionaryValue& message, | 371 const base::DictionaryValue& message, |
334 scoped_ptr<base::DictionaryValue> response) { | 372 scoped_ptr<base::DictionaryValue> response) { |
373 DCHECK(thread_checker_.CalledOnValidThread()); | |
374 | |
335 std::string auth_code; | 375 std::string auth_code; |
336 if (!message.GetString("authorizationCode", &auth_code)) { | 376 if (!message.GetString("authorizationCode", &auth_code)) { |
337 LOG(ERROR) << "'authorizationCode' string not found."; | 377 LOG(ERROR) << "'authorizationCode' string not found."; |
338 return false; | 378 return false; |
339 } | 379 } |
340 | 380 |
341 gaia::OAuthClientInfo oauth_client_info = { | 381 gaia::OAuthClientInfo oauth_client_info = { |
342 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING_HOST), | 382 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING_HOST), |
343 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING_HOST), | 383 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING_HOST), |
344 kServiceAccountRedirectUri | 384 kServiceAccountRedirectUri |
345 }; | 385 }; |
346 | 386 |
347 oauth_client_->GetCredentialsFromAuthCode( | 387 oauth_client_->GetCredentialsFromAuthCode( |
348 oauth_client_info, auth_code, base::Bind( | 388 oauth_client_info, auth_code, base::Bind( |
349 &NativeMessagingHost::SendCredentialsResponse, weak_ptr_, | 389 &NativeMessagingHost::SendCredentialsResponse, weak_ptr_, |
350 base::Passed(&response))); | 390 base::Passed(&response))); |
351 | 391 |
352 return true; | 392 return true; |
353 } | 393 } |
354 | 394 |
355 void NativeMessagingHost::SendConfigResponse( | 395 void NativeMessagingHost::SendConfigResponse( |
356 scoped_ptr<base::DictionaryValue> response, | 396 scoped_ptr<base::DictionaryValue> response, |
357 scoped_ptr<base::DictionaryValue> config) { | 397 scoped_ptr<base::DictionaryValue> config) { |
398 DCHECK(thread_checker_.CalledOnValidThread()); | |
399 | |
358 if (config) { | 400 if (config) { |
359 response->Set("config", config.release()); | 401 response->Set("config", config.release()); |
360 } else { | 402 } else { |
361 response->Set("config", Value::CreateNullValue()); | 403 response->Set("config", Value::CreateNullValue()); |
362 } | 404 } |
363 send_message_.Run(response.Pass()); | 405 channel_->SendMessage(response.Pass()); |
364 } | 406 } |
365 | 407 |
366 void NativeMessagingHost::SendPairedClientsResponse( | 408 void NativeMessagingHost::SendPairedClientsResponse( |
367 scoped_ptr<base::DictionaryValue> response, | 409 scoped_ptr<base::DictionaryValue> response, |
368 scoped_ptr<base::ListValue> pairings) { | 410 scoped_ptr<base::ListValue> pairings) { |
411 DCHECK(thread_checker_.CalledOnValidThread()); | |
412 | |
369 response->Set("pairedClients", pairings.release()); | 413 response->Set("pairedClients", pairings.release()); |
370 send_message_.Run(response.Pass()); | 414 channel_->SendMessage(response.Pass()); |
371 } | 415 } |
372 | 416 |
373 void NativeMessagingHost::SendUsageStatsConsentResponse( | 417 void NativeMessagingHost::SendUsageStatsConsentResponse( |
374 scoped_ptr<base::DictionaryValue> response, | 418 scoped_ptr<base::DictionaryValue> response, |
375 const DaemonController::UsageStatsConsent& consent) { | 419 const DaemonController::UsageStatsConsent& consent) { |
420 DCHECK(thread_checker_.CalledOnValidThread()); | |
421 | |
376 response->SetBoolean("supported", consent.supported); | 422 response->SetBoolean("supported", consent.supported); |
377 response->SetBoolean("allowed", consent.allowed); | 423 response->SetBoolean("allowed", consent.allowed); |
378 response->SetBoolean("setByPolicy", consent.set_by_policy); | 424 response->SetBoolean("setByPolicy", consent.set_by_policy); |
379 send_message_.Run(response.Pass()); | 425 channel_->SendMessage(response.Pass()); |
380 } | 426 } |
381 | 427 |
382 void NativeMessagingHost::SendAsyncResult( | 428 void NativeMessagingHost::SendAsyncResult( |
383 scoped_ptr<base::DictionaryValue> response, | 429 scoped_ptr<base::DictionaryValue> response, |
384 DaemonController::AsyncResult result) { | 430 DaemonController::AsyncResult result) { |
431 DCHECK(thread_checker_.CalledOnValidThread()); | |
432 | |
385 switch (result) { | 433 switch (result) { |
386 case DaemonController::RESULT_OK: | 434 case DaemonController::RESULT_OK: |
387 response->SetString("result", "OK"); | 435 response->SetString("result", "OK"); |
388 break; | 436 break; |
389 case DaemonController::RESULT_FAILED: | 437 case DaemonController::RESULT_FAILED: |
390 response->SetString("result", "FAILED"); | 438 response->SetString("result", "FAILED"); |
391 break; | 439 break; |
392 case DaemonController::RESULT_CANCELLED: | 440 case DaemonController::RESULT_CANCELLED: |
393 response->SetString("result", "CANCELLED"); | 441 response->SetString("result", "CANCELLED"); |
394 break; | 442 break; |
395 case DaemonController::RESULT_FAILED_DIRECTORY: | 443 case DaemonController::RESULT_FAILED_DIRECTORY: |
396 response->SetString("result", "FAILED_DIRECTORY"); | 444 response->SetString("result", "FAILED_DIRECTORY"); |
397 break; | 445 break; |
398 } | 446 } |
399 send_message_.Run(response.Pass()); | 447 channel_->SendMessage(response.Pass()); |
400 } | 448 } |
401 | 449 |
402 void NativeMessagingHost::SendBooleanResult( | 450 void NativeMessagingHost::SendBooleanResult( |
403 scoped_ptr<base::DictionaryValue> response, bool result) { | 451 scoped_ptr<base::DictionaryValue> response, bool result) { |
452 DCHECK(thread_checker_.CalledOnValidThread()); | |
453 | |
404 response->SetBoolean("result", result); | 454 response->SetBoolean("result", result); |
405 send_message_.Run(response.Pass()); | 455 channel_->SendMessage(response.Pass()); |
406 } | 456 } |
407 | 457 |
408 void NativeMessagingHost::SendCredentialsResponse( | 458 void NativeMessagingHost::SendCredentialsResponse( |
409 scoped_ptr<base::DictionaryValue> response, | 459 scoped_ptr<base::DictionaryValue> response, |
410 const std::string& user_email, | 460 const std::string& user_email, |
411 const std::string& refresh_token) { | 461 const std::string& refresh_token) { |
462 DCHECK(thread_checker_.CalledOnValidThread()); | |
463 | |
412 response->SetString("userEmail", user_email); | 464 response->SetString("userEmail", user_email); |
413 response->SetString("refreshToken", refresh_token); | 465 response->SetString("refreshToken", refresh_token); |
414 send_message_.Run(response.Pass()); | 466 channel_->SendMessage(response.Pass()); |
415 } | 467 } |
416 | 468 |
417 } // namespace remoting | 469 } // namespace remoting |
OLD | NEW |