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

Side by Side Diff: remoting/host/setup/me2me_native_messaging_host.cc

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

Powered by Google App Engine
This is Rietveld 408576698