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