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

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

Issue 1549493004: Use std::move() instead of .Pass() in remoting/host (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_not_pass
Patch Set: include <utility> Created 5 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 #include <utility>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/strings/stringize_macros.h" 16 #include "base/strings/stringize_macros.h"
16 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // Returns nullptr on failure, and logs an error message. 60 // Returns nullptr on failure, and logs an error message.
60 scoped_ptr<base::DictionaryValue> ConfigDictionaryFromMessage( 61 scoped_ptr<base::DictionaryValue> ConfigDictionaryFromMessage(
61 scoped_ptr<base::DictionaryValue> message) { 62 scoped_ptr<base::DictionaryValue> message) {
62 scoped_ptr<base::DictionaryValue> result; 63 scoped_ptr<base::DictionaryValue> result;
63 const base::DictionaryValue* config_dict; 64 const base::DictionaryValue* config_dict;
64 if (message->GetDictionary("config", &config_dict)) { 65 if (message->GetDictionary("config", &config_dict)) {
65 result.reset(config_dict->DeepCopy()); 66 result.reset(config_dict->DeepCopy());
66 } else { 67 } else {
67 LOG(ERROR) << "'config' dictionary not found"; 68 LOG(ERROR) << "'config' dictionary not found";
68 } 69 }
69 return result.Pass(); 70 return result;
70 } 71 }
71 72
72 } // namespace 73 } // namespace
73 74
74 namespace remoting { 75 namespace remoting {
75 76
76 Me2MeNativeMessagingHost::Me2MeNativeMessagingHost( 77 Me2MeNativeMessagingHost::Me2MeNativeMessagingHost(
77 bool needs_elevation, 78 bool needs_elevation,
78 intptr_t parent_window_handle, 79 intptr_t parent_window_handle,
79 scoped_ptr<extensions::NativeMessagingChannel> channel, 80 scoped_ptr<extensions::NativeMessagingChannel> channel,
80 scoped_refptr<DaemonController> daemon_controller, 81 scoped_refptr<DaemonController> daemon_controller,
81 scoped_refptr<protocol::PairingRegistry> pairing_registry, 82 scoped_refptr<protocol::PairingRegistry> pairing_registry,
82 scoped_ptr<OAuthClient> oauth_client) 83 scoped_ptr<OAuthClient> oauth_client)
83 : needs_elevation_(needs_elevation), 84 : needs_elevation_(needs_elevation),
84 #if defined(OS_WIN) 85 #if defined(OS_WIN)
85 parent_window_handle_(parent_window_handle), 86 parent_window_handle_(parent_window_handle),
86 #endif 87 #endif
87 channel_(channel.Pass()), 88 channel_(std::move(channel)),
88 log_message_handler_( 89 log_message_handler_(
89 base::Bind(&extensions::NativeMessagingChannel::SendMessage, 90 base::Bind(&extensions::NativeMessagingChannel::SendMessage,
90 base::Unretained(channel_.get()))), 91 base::Unretained(channel_.get()))),
91 daemon_controller_(daemon_controller), 92 daemon_controller_(daemon_controller),
92 pairing_registry_(pairing_registry), 93 pairing_registry_(pairing_registry),
93 oauth_client_(oauth_client.Pass()), 94 oauth_client_(std::move(oauth_client)),
94 weak_factory_(this) { 95 weak_factory_(this) {
95 weak_ptr_ = weak_factory_.GetWeakPtr(); 96 weak_ptr_ = weak_factory_.GetWeakPtr();
96 } 97 }
97 98
98 Me2MeNativeMessagingHost::~Me2MeNativeMessagingHost() { 99 Me2MeNativeMessagingHost::~Me2MeNativeMessagingHost() {
99 DCHECK(thread_checker_.CalledOnValidThread()); 100 DCHECK(thread_checker_.CalledOnValidThread());
100 } 101 }
101 102
102 void Me2MeNativeMessagingHost::Start( 103 void Me2MeNativeMessagingHost::Start(
103 const base::Closure& quit_closure) { 104 const base::Closure& quit_closure) {
(...skipping 27 matching lines...) Expand all
131 std::string type; 132 std::string type;
132 if (!message_dict->GetString("type", &type)) { 133 if (!message_dict->GetString("type", &type)) {
133 LOG(ERROR) << "'type' not found"; 134 LOG(ERROR) << "'type' not found";
134 channel_->SendMessage(nullptr); 135 channel_->SendMessage(nullptr);
135 return; 136 return;
136 } 137 }
137 138
138 response->SetString("type", type + "Response"); 139 response->SetString("type", type + "Response");
139 140
140 if (type == "hello") { 141 if (type == "hello") {
141 ProcessHello(message_dict.Pass(), response.Pass()); 142 ProcessHello(std::move(message_dict), std::move(response));
142 } else if (type == "clearPairedClients") { 143 } else if (type == "clearPairedClients") {
143 ProcessClearPairedClients(message_dict.Pass(), response.Pass()); 144 ProcessClearPairedClients(std::move(message_dict), std::move(response));
144 } else if (type == "deletePairedClient") { 145 } else if (type == "deletePairedClient") {
145 ProcessDeletePairedClient(message_dict.Pass(), response.Pass()); 146 ProcessDeletePairedClient(std::move(message_dict), std::move(response));
146 } else if (type == "getHostName") { 147 } else if (type == "getHostName") {
147 ProcessGetHostName(message_dict.Pass(), response.Pass()); 148 ProcessGetHostName(std::move(message_dict), std::move(response));
148 } else if (type == "getPinHash") { 149 } else if (type == "getPinHash") {
149 ProcessGetPinHash(message_dict.Pass(), response.Pass()); 150 ProcessGetPinHash(std::move(message_dict), std::move(response));
150 } else if (type == "generateKeyPair") { 151 } else if (type == "generateKeyPair") {
151 ProcessGenerateKeyPair(message_dict.Pass(), response.Pass()); 152 ProcessGenerateKeyPair(std::move(message_dict), std::move(response));
152 } else if (type == "updateDaemonConfig") { 153 } else if (type == "updateDaemonConfig") {
153 ProcessUpdateDaemonConfig(message_dict.Pass(), response.Pass()); 154 ProcessUpdateDaemonConfig(std::move(message_dict), std::move(response));
154 } else if (type == "getDaemonConfig") { 155 } else if (type == "getDaemonConfig") {
155 ProcessGetDaemonConfig(message_dict.Pass(), response.Pass()); 156 ProcessGetDaemonConfig(std::move(message_dict), std::move(response));
156 } else if (type == "getPairedClients") { 157 } else if (type == "getPairedClients") {
157 ProcessGetPairedClients(message_dict.Pass(), response.Pass()); 158 ProcessGetPairedClients(std::move(message_dict), std::move(response));
158 } else if (type == "getUsageStatsConsent") { 159 } else if (type == "getUsageStatsConsent") {
159 ProcessGetUsageStatsConsent(message_dict.Pass(), response.Pass()); 160 ProcessGetUsageStatsConsent(std::move(message_dict), std::move(response));
160 } else if (type == "startDaemon") { 161 } else if (type == "startDaemon") {
161 ProcessStartDaemon(message_dict.Pass(), response.Pass()); 162 ProcessStartDaemon(std::move(message_dict), std::move(response));
162 } else if (type == "stopDaemon") { 163 } else if (type == "stopDaemon") {
163 ProcessStopDaemon(message_dict.Pass(), response.Pass()); 164 ProcessStopDaemon(std::move(message_dict), std::move(response));
164 } else if (type == "getDaemonState") { 165 } else if (type == "getDaemonState") {
165 ProcessGetDaemonState(message_dict.Pass(), response.Pass()); 166 ProcessGetDaemonState(std::move(message_dict), std::move(response));
166 } else if (type == "getHostClientId") { 167 } else if (type == "getHostClientId") {
167 ProcessGetHostClientId(message_dict.Pass(), response.Pass()); 168 ProcessGetHostClientId(std::move(message_dict), std::move(response));
168 } else if (type == "getCredentialsFromAuthCode") { 169 } else if (type == "getCredentialsFromAuthCode") {
169 ProcessGetCredentialsFromAuthCode( 170 ProcessGetCredentialsFromAuthCode(
170 message_dict.Pass(), response.Pass(), true); 171 std::move(message_dict), std::move(response), true);
171 } else if (type == "getRefreshTokenFromAuthCode") { 172 } else if (type == "getRefreshTokenFromAuthCode") {
172 ProcessGetCredentialsFromAuthCode( 173 ProcessGetCredentialsFromAuthCode(
173 message_dict.Pass(), response.Pass(), false); 174 std::move(message_dict), std::move(response), false);
174 } else { 175 } else {
175 LOG(ERROR) << "Unsupported request type: " << type; 176 LOG(ERROR) << "Unsupported request type: " << type;
176 OnError(); 177 OnError();
177 } 178 }
178 } 179 }
179 180
180 void Me2MeNativeMessagingHost::OnDisconnect() { 181 void Me2MeNativeMessagingHost::OnDisconnect() {
181 if (!quit_closure_.is_null()) 182 if (!quit_closure_.is_null())
182 base::ResetAndReturn(&quit_closure_).Run(); 183 base::ResetAndReturn(&quit_closure_).Run();
183 } 184 }
184 185
185 void Me2MeNativeMessagingHost::ProcessHello( 186 void Me2MeNativeMessagingHost::ProcessHello(
186 scoped_ptr<base::DictionaryValue> message, 187 scoped_ptr<base::DictionaryValue> message,
187 scoped_ptr<base::DictionaryValue> response) { 188 scoped_ptr<base::DictionaryValue> response) {
188 DCHECK(thread_checker_.CalledOnValidThread()); 189 DCHECK(thread_checker_.CalledOnValidThread());
189 190
190 response->SetString("version", STRINGIZE(VERSION)); 191 response->SetString("version", STRINGIZE(VERSION));
191 scoped_ptr<base::ListValue> supported_features_list(new base::ListValue()); 192 scoped_ptr<base::ListValue> supported_features_list(new base::ListValue());
192 supported_features_list->AppendStrings(std::vector<std::string>( 193 supported_features_list->AppendStrings(std::vector<std::string>(
193 kSupportedFeatures, kSupportedFeatures + arraysize(kSupportedFeatures))); 194 kSupportedFeatures, kSupportedFeatures + arraysize(kSupportedFeatures)));
194 response->Set("supportedFeatures", supported_features_list.release()); 195 response->Set("supportedFeatures", supported_features_list.release());
195 channel_->SendMessage(response.Pass()); 196 channel_->SendMessage(std::move(response));
196 } 197 }
197 198
198 void Me2MeNativeMessagingHost::ProcessClearPairedClients( 199 void Me2MeNativeMessagingHost::ProcessClearPairedClients(
199 scoped_ptr<base::DictionaryValue> message, 200 scoped_ptr<base::DictionaryValue> message,
200 scoped_ptr<base::DictionaryValue> response) { 201 scoped_ptr<base::DictionaryValue> response) {
201 DCHECK(thread_checker_.CalledOnValidThread()); 202 DCHECK(thread_checker_.CalledOnValidThread());
202 203
203 if (needs_elevation_) { 204 if (needs_elevation_) {
204 if (!DelegateToElevatedHost(message.Pass())) 205 if (!DelegateToElevatedHost(std::move(message)))
205 SendBooleanResult(response.Pass(), false); 206 SendBooleanResult(std::move(response), false);
206 return; 207 return;
207 } 208 }
208 209
209 if (pairing_registry_.get()) { 210 if (pairing_registry_.get()) {
210 pairing_registry_->ClearAllPairings( 211 pairing_registry_->ClearAllPairings(
211 base::Bind(&Me2MeNativeMessagingHost::SendBooleanResult, weak_ptr_, 212 base::Bind(&Me2MeNativeMessagingHost::SendBooleanResult, weak_ptr_,
212 base::Passed(&response))); 213 base::Passed(&response)));
213 } else { 214 } else {
214 SendBooleanResult(response.Pass(), false); 215 SendBooleanResult(std::move(response), false);
215 } 216 }
216 } 217 }
217 218
218 void Me2MeNativeMessagingHost::ProcessDeletePairedClient( 219 void Me2MeNativeMessagingHost::ProcessDeletePairedClient(
219 scoped_ptr<base::DictionaryValue> message, 220 scoped_ptr<base::DictionaryValue> message,
220 scoped_ptr<base::DictionaryValue> response) { 221 scoped_ptr<base::DictionaryValue> response) {
221 DCHECK(thread_checker_.CalledOnValidThread()); 222 DCHECK(thread_checker_.CalledOnValidThread());
222 223
223 if (needs_elevation_) { 224 if (needs_elevation_) {
224 if (!DelegateToElevatedHost(message.Pass())) 225 if (!DelegateToElevatedHost(std::move(message)))
225 SendBooleanResult(response.Pass(), false); 226 SendBooleanResult(std::move(response), false);
226 return; 227 return;
227 } 228 }
228 229
229 std::string client_id; 230 std::string client_id;
230 if (!message->GetString(protocol::PairingRegistry::kClientIdKey, 231 if (!message->GetString(protocol::PairingRegistry::kClientIdKey,
231 &client_id)) { 232 &client_id)) {
232 LOG(ERROR) << "'" << protocol::PairingRegistry::kClientIdKey 233 LOG(ERROR) << "'" << protocol::PairingRegistry::kClientIdKey
233 << "' string not found."; 234 << "' string not found.";
234 OnError(); 235 OnError();
235 return; 236 return;
236 } 237 }
237 238
238 if (pairing_registry_.get()) { 239 if (pairing_registry_.get()) {
239 pairing_registry_->DeletePairing( 240 pairing_registry_->DeletePairing(
240 client_id, base::Bind(&Me2MeNativeMessagingHost::SendBooleanResult, 241 client_id, base::Bind(&Me2MeNativeMessagingHost::SendBooleanResult,
241 weak_ptr_, base::Passed(&response))); 242 weak_ptr_, base::Passed(&response)));
242 } else { 243 } else {
243 SendBooleanResult(response.Pass(), false); 244 SendBooleanResult(std::move(response), false);
244 } 245 }
245 } 246 }
246 247
247 void Me2MeNativeMessagingHost::ProcessGetHostName( 248 void Me2MeNativeMessagingHost::ProcessGetHostName(
248 scoped_ptr<base::DictionaryValue> message, 249 scoped_ptr<base::DictionaryValue> message,
249 scoped_ptr<base::DictionaryValue> response) { 250 scoped_ptr<base::DictionaryValue> response) {
250 DCHECK(thread_checker_.CalledOnValidThread()); 251 DCHECK(thread_checker_.CalledOnValidThread());
251 252
252 response->SetString("hostname", net::GetHostName()); 253 response->SetString("hostname", net::GetHostName());
253 channel_->SendMessage(response.Pass()); 254 channel_->SendMessage(std::move(response));
254 } 255 }
255 256
256 void Me2MeNativeMessagingHost::ProcessGetPinHash( 257 void Me2MeNativeMessagingHost::ProcessGetPinHash(
257 scoped_ptr<base::DictionaryValue> message, 258 scoped_ptr<base::DictionaryValue> message,
258 scoped_ptr<base::DictionaryValue> response) { 259 scoped_ptr<base::DictionaryValue> response) {
259 DCHECK(thread_checker_.CalledOnValidThread()); 260 DCHECK(thread_checker_.CalledOnValidThread());
260 261
261 std::string host_id; 262 std::string host_id;
262 if (!message->GetString("hostId", &host_id)) { 263 if (!message->GetString("hostId", &host_id)) {
263 LOG(ERROR) << "'hostId' not found: " << message; 264 LOG(ERROR) << "'hostId' not found: " << message;
264 OnError(); 265 OnError();
265 return; 266 return;
266 } 267 }
267 std::string pin; 268 std::string pin;
268 if (!message->GetString("pin", &pin)) { 269 if (!message->GetString("pin", &pin)) {
269 LOG(ERROR) << "'pin' not found: " << message; 270 LOG(ERROR) << "'pin' not found: " << message;
270 OnError(); 271 OnError();
271 return; 272 return;
272 } 273 }
273 response->SetString("hash", MakeHostPinHash(host_id, pin)); 274 response->SetString("hash", MakeHostPinHash(host_id, pin));
274 channel_->SendMessage(response.Pass()); 275 channel_->SendMessage(std::move(response));
275 } 276 }
276 277
277 void Me2MeNativeMessagingHost::ProcessGenerateKeyPair( 278 void Me2MeNativeMessagingHost::ProcessGenerateKeyPair(
278 scoped_ptr<base::DictionaryValue> message, 279 scoped_ptr<base::DictionaryValue> message,
279 scoped_ptr<base::DictionaryValue> response) { 280 scoped_ptr<base::DictionaryValue> response) {
280 DCHECK(thread_checker_.CalledOnValidThread()); 281 DCHECK(thread_checker_.CalledOnValidThread());
281 282
282 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate(); 283 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate();
283 response->SetString("privateKey", key_pair->ToString()); 284 response->SetString("privateKey", key_pair->ToString());
284 response->SetString("publicKey", key_pair->GetPublicKey()); 285 response->SetString("publicKey", key_pair->GetPublicKey());
285 channel_->SendMessage(response.Pass()); 286 channel_->SendMessage(std::move(response));
286 } 287 }
287 288
288 void Me2MeNativeMessagingHost::ProcessUpdateDaemonConfig( 289 void Me2MeNativeMessagingHost::ProcessUpdateDaemonConfig(
289 scoped_ptr<base::DictionaryValue> message, 290 scoped_ptr<base::DictionaryValue> message,
290 scoped_ptr<base::DictionaryValue> response) { 291 scoped_ptr<base::DictionaryValue> response) {
291 DCHECK(thread_checker_.CalledOnValidThread()); 292 DCHECK(thread_checker_.CalledOnValidThread());
292 293
293 if (needs_elevation_) { 294 if (needs_elevation_) {
294 if (!DelegateToElevatedHost(message.Pass())) 295 if (!DelegateToElevatedHost(std::move(message)))
295 SendAsyncResult(response.Pass(), DaemonController::RESULT_FAILED); 296 SendAsyncResult(std::move(response), DaemonController::RESULT_FAILED);
296 return; 297 return;
297 } 298 }
298 299
299 scoped_ptr<base::DictionaryValue> config_dict = 300 scoped_ptr<base::DictionaryValue> config_dict =
300 ConfigDictionaryFromMessage(message.Pass()); 301 ConfigDictionaryFromMessage(std::move(message));
301 if (!config_dict) { 302 if (!config_dict) {
302 OnError(); 303 OnError();
303 return; 304 return;
304 } 305 }
305 306
306 daemon_controller_->UpdateConfig( 307 daemon_controller_->UpdateConfig(
307 config_dict.Pass(), 308 std::move(config_dict),
308 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_, 309 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_,
309 base::Passed(&response))); 310 base::Passed(&response)));
310 } 311 }
311 312
312 void Me2MeNativeMessagingHost::ProcessGetDaemonConfig( 313 void Me2MeNativeMessagingHost::ProcessGetDaemonConfig(
313 scoped_ptr<base::DictionaryValue> message, 314 scoped_ptr<base::DictionaryValue> message,
314 scoped_ptr<base::DictionaryValue> response) { 315 scoped_ptr<base::DictionaryValue> response) {
315 DCHECK(thread_checker_.CalledOnValidThread()); 316 DCHECK(thread_checker_.CalledOnValidThread());
316 317
317 daemon_controller_->GetConfig( 318 daemon_controller_->GetConfig(
318 base::Bind(&Me2MeNativeMessagingHost::SendConfigResponse, weak_ptr_, 319 base::Bind(&Me2MeNativeMessagingHost::SendConfigResponse, weak_ptr_,
319 base::Passed(&response))); 320 base::Passed(&response)));
320 } 321 }
321 322
322 void Me2MeNativeMessagingHost::ProcessGetPairedClients( 323 void Me2MeNativeMessagingHost::ProcessGetPairedClients(
323 scoped_ptr<base::DictionaryValue> message, 324 scoped_ptr<base::DictionaryValue> message,
324 scoped_ptr<base::DictionaryValue> response) { 325 scoped_ptr<base::DictionaryValue> response) {
325 DCHECK(thread_checker_.CalledOnValidThread()); 326 DCHECK(thread_checker_.CalledOnValidThread());
326 327
327 if (pairing_registry_.get()) { 328 if (pairing_registry_.get()) {
328 pairing_registry_->GetAllPairings( 329 pairing_registry_->GetAllPairings(
329 base::Bind(&Me2MeNativeMessagingHost::SendPairedClientsResponse, 330 base::Bind(&Me2MeNativeMessagingHost::SendPairedClientsResponse,
330 weak_ptr_, base::Passed(&response))); 331 weak_ptr_, base::Passed(&response)));
331 } else { 332 } else {
332 scoped_ptr<base::ListValue> no_paired_clients(new base::ListValue); 333 scoped_ptr<base::ListValue> no_paired_clients(new base::ListValue);
333 SendPairedClientsResponse(response.Pass(), no_paired_clients.Pass()); 334 SendPairedClientsResponse(std::move(response),
335 std::move(no_paired_clients));
334 } 336 }
335 } 337 }
336 338
337 void Me2MeNativeMessagingHost::ProcessGetUsageStatsConsent( 339 void Me2MeNativeMessagingHost::ProcessGetUsageStatsConsent(
338 scoped_ptr<base::DictionaryValue> message, 340 scoped_ptr<base::DictionaryValue> message,
339 scoped_ptr<base::DictionaryValue> response) { 341 scoped_ptr<base::DictionaryValue> response) {
340 DCHECK(thread_checker_.CalledOnValidThread()); 342 DCHECK(thread_checker_.CalledOnValidThread());
341 343
342 daemon_controller_->GetUsageStatsConsent( 344 daemon_controller_->GetUsageStatsConsent(
343 base::Bind(&Me2MeNativeMessagingHost::SendUsageStatsConsentResponse, 345 base::Bind(&Me2MeNativeMessagingHost::SendUsageStatsConsentResponse,
344 weak_ptr_, base::Passed(&response))); 346 weak_ptr_, base::Passed(&response)));
345 } 347 }
346 348
347 void Me2MeNativeMessagingHost::ProcessStartDaemon( 349 void Me2MeNativeMessagingHost::ProcessStartDaemon(
348 scoped_ptr<base::DictionaryValue> message, 350 scoped_ptr<base::DictionaryValue> message,
349 scoped_ptr<base::DictionaryValue> response) { 351 scoped_ptr<base::DictionaryValue> response) {
350 DCHECK(thread_checker_.CalledOnValidThread()); 352 DCHECK(thread_checker_.CalledOnValidThread());
351 353
352 if (needs_elevation_) { 354 if (needs_elevation_) {
353 if (!DelegateToElevatedHost(message.Pass())) 355 if (!DelegateToElevatedHost(std::move(message)))
354 SendAsyncResult(response.Pass(), DaemonController::RESULT_FAILED); 356 SendAsyncResult(std::move(response), DaemonController::RESULT_FAILED);
355 return; 357 return;
356 } 358 }
357 359
358 bool consent; 360 bool consent;
359 if (!message->GetBoolean("consent", &consent)) { 361 if (!message->GetBoolean("consent", &consent)) {
360 LOG(ERROR) << "'consent' not found."; 362 LOG(ERROR) << "'consent' not found.";
361 OnError(); 363 OnError();
362 return; 364 return;
363 } 365 }
364 366
365 scoped_ptr<base::DictionaryValue> config_dict = 367 scoped_ptr<base::DictionaryValue> config_dict =
366 ConfigDictionaryFromMessage(message.Pass()); 368 ConfigDictionaryFromMessage(std::move(message));
367 if (!config_dict) { 369 if (!config_dict) {
368 OnError(); 370 OnError();
369 return; 371 return;
370 } 372 }
371 373
372 daemon_controller_->SetConfigAndStart( 374 daemon_controller_->SetConfigAndStart(
373 config_dict.Pass(), consent, 375 std::move(config_dict), consent,
374 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_, 376 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_,
375 base::Passed(&response))); 377 base::Passed(&response)));
376 } 378 }
377 379
378 void Me2MeNativeMessagingHost::ProcessStopDaemon( 380 void Me2MeNativeMessagingHost::ProcessStopDaemon(
379 scoped_ptr<base::DictionaryValue> message, 381 scoped_ptr<base::DictionaryValue> message,
380 scoped_ptr<base::DictionaryValue> response) { 382 scoped_ptr<base::DictionaryValue> response) {
381 DCHECK(thread_checker_.CalledOnValidThread()); 383 DCHECK(thread_checker_.CalledOnValidThread());
382 384
383 if (needs_elevation_) { 385 if (needs_elevation_) {
384 if (!DelegateToElevatedHost(message.Pass())) 386 if (!DelegateToElevatedHost(std::move(message)))
385 SendAsyncResult(response.Pass(), DaemonController::RESULT_FAILED); 387 SendAsyncResult(std::move(response), DaemonController::RESULT_FAILED);
386 return; 388 return;
387 } 389 }
388 390
389 daemon_controller_->Stop( 391 daemon_controller_->Stop(
390 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_, 392 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_,
391 base::Passed(&response))); 393 base::Passed(&response)));
392 } 394 }
393 395
394 void Me2MeNativeMessagingHost::ProcessGetDaemonState( 396 void Me2MeNativeMessagingHost::ProcessGetDaemonState(
395 scoped_ptr<base::DictionaryValue> message, 397 scoped_ptr<base::DictionaryValue> message,
(...skipping 14 matching lines...) Expand all
410 case DaemonController::STATE_STARTED: 412 case DaemonController::STATE_STARTED:
411 response->SetString("state", "STARTED"); 413 response->SetString("state", "STARTED");
412 break; 414 break;
413 case DaemonController::STATE_STOPPING: 415 case DaemonController::STATE_STOPPING:
414 response->SetString("state", "STOPPING"); 416 response->SetString("state", "STOPPING");
415 break; 417 break;
416 case DaemonController::STATE_UNKNOWN: 418 case DaemonController::STATE_UNKNOWN:
417 response->SetString("state", "UNKNOWN"); 419 response->SetString("state", "UNKNOWN");
418 break; 420 break;
419 } 421 }
420 channel_->SendMessage(response.Pass()); 422 channel_->SendMessage(std::move(response));
421 } 423 }
422 424
423 void Me2MeNativeMessagingHost::ProcessGetHostClientId( 425 void Me2MeNativeMessagingHost::ProcessGetHostClientId(
424 scoped_ptr<base::DictionaryValue> message, 426 scoped_ptr<base::DictionaryValue> message,
425 scoped_ptr<base::DictionaryValue> response) { 427 scoped_ptr<base::DictionaryValue> response) {
426 DCHECK(thread_checker_.CalledOnValidThread()); 428 DCHECK(thread_checker_.CalledOnValidThread());
427 429
428 response->SetString("clientId", google_apis::GetOAuth2ClientID( 430 response->SetString("clientId", google_apis::GetOAuth2ClientID(
429 google_apis::CLIENT_REMOTING_HOST)); 431 google_apis::CLIENT_REMOTING_HOST));
430 channel_->SendMessage(response.Pass()); 432 channel_->SendMessage(std::move(response));
431 } 433 }
432 434
433 void Me2MeNativeMessagingHost::ProcessGetCredentialsFromAuthCode( 435 void Me2MeNativeMessagingHost::ProcessGetCredentialsFromAuthCode(
434 scoped_ptr<base::DictionaryValue> message, 436 scoped_ptr<base::DictionaryValue> message,
435 scoped_ptr<base::DictionaryValue> response, 437 scoped_ptr<base::DictionaryValue> response,
436 bool need_user_email) { 438 bool need_user_email) {
437 DCHECK(thread_checker_.CalledOnValidThread()); 439 DCHECK(thread_checker_.CalledOnValidThread());
438 440
439 std::string auth_code; 441 std::string auth_code;
440 if (!message->GetString("authorizationCode", &auth_code)) { 442 if (!message->GetString("authorizationCode", &auth_code)) {
(...skipping 17 matching lines...) Expand all
458 void Me2MeNativeMessagingHost::SendConfigResponse( 460 void Me2MeNativeMessagingHost::SendConfigResponse(
459 scoped_ptr<base::DictionaryValue> response, 461 scoped_ptr<base::DictionaryValue> response,
460 scoped_ptr<base::DictionaryValue> config) { 462 scoped_ptr<base::DictionaryValue> config) {
461 DCHECK(thread_checker_.CalledOnValidThread()); 463 DCHECK(thread_checker_.CalledOnValidThread());
462 464
463 if (config) { 465 if (config) {
464 response->Set("config", config.release()); 466 response->Set("config", config.release());
465 } else { 467 } else {
466 response->Set("config", base::Value::CreateNullValue()); 468 response->Set("config", base::Value::CreateNullValue());
467 } 469 }
468 channel_->SendMessage(response.Pass()); 470 channel_->SendMessage(std::move(response));
469 } 471 }
470 472
471 void Me2MeNativeMessagingHost::SendPairedClientsResponse( 473 void Me2MeNativeMessagingHost::SendPairedClientsResponse(
472 scoped_ptr<base::DictionaryValue> response, 474 scoped_ptr<base::DictionaryValue> response,
473 scoped_ptr<base::ListValue> pairings) { 475 scoped_ptr<base::ListValue> pairings) {
474 DCHECK(thread_checker_.CalledOnValidThread()); 476 DCHECK(thread_checker_.CalledOnValidThread());
475 477
476 response->Set("pairedClients", pairings.release()); 478 response->Set("pairedClients", pairings.release());
477 channel_->SendMessage(response.Pass()); 479 channel_->SendMessage(std::move(response));
478 } 480 }
479 481
480 void Me2MeNativeMessagingHost::SendUsageStatsConsentResponse( 482 void Me2MeNativeMessagingHost::SendUsageStatsConsentResponse(
481 scoped_ptr<base::DictionaryValue> response, 483 scoped_ptr<base::DictionaryValue> response,
482 const DaemonController::UsageStatsConsent& consent) { 484 const DaemonController::UsageStatsConsent& consent) {
483 DCHECK(thread_checker_.CalledOnValidThread()); 485 DCHECK(thread_checker_.CalledOnValidThread());
484 486
485 response->SetBoolean("supported", consent.supported); 487 response->SetBoolean("supported", consent.supported);
486 response->SetBoolean("allowed", consent.allowed); 488 response->SetBoolean("allowed", consent.allowed);
487 response->SetBoolean("setByPolicy", consent.set_by_policy); 489 response->SetBoolean("setByPolicy", consent.set_by_policy);
488 channel_->SendMessage(response.Pass()); 490 channel_->SendMessage(std::move(response));
489 } 491 }
490 492
491 void Me2MeNativeMessagingHost::SendAsyncResult( 493 void Me2MeNativeMessagingHost::SendAsyncResult(
492 scoped_ptr<base::DictionaryValue> response, 494 scoped_ptr<base::DictionaryValue> response,
493 DaemonController::AsyncResult result) { 495 DaemonController::AsyncResult result) {
494 DCHECK(thread_checker_.CalledOnValidThread()); 496 DCHECK(thread_checker_.CalledOnValidThread());
495 497
496 switch (result) { 498 switch (result) {
497 case DaemonController::RESULT_OK: 499 case DaemonController::RESULT_OK:
498 response->SetString("result", "OK"); 500 response->SetString("result", "OK");
499 break; 501 break;
500 case DaemonController::RESULT_FAILED: 502 case DaemonController::RESULT_FAILED:
501 response->SetString("result", "FAILED"); 503 response->SetString("result", "FAILED");
502 break; 504 break;
503 case DaemonController::RESULT_CANCELLED: 505 case DaemonController::RESULT_CANCELLED:
504 response->SetString("result", "CANCELLED"); 506 response->SetString("result", "CANCELLED");
505 break; 507 break;
506 case DaemonController::RESULT_FAILED_DIRECTORY: 508 case DaemonController::RESULT_FAILED_DIRECTORY:
507 response->SetString("result", "FAILED_DIRECTORY"); 509 response->SetString("result", "FAILED_DIRECTORY");
508 break; 510 break;
509 } 511 }
510 channel_->SendMessage(response.Pass()); 512 channel_->SendMessage(std::move(response));
511 } 513 }
512 514
513 void Me2MeNativeMessagingHost::SendBooleanResult( 515 void Me2MeNativeMessagingHost::SendBooleanResult(
514 scoped_ptr<base::DictionaryValue> response, bool result) { 516 scoped_ptr<base::DictionaryValue> response, bool result) {
515 DCHECK(thread_checker_.CalledOnValidThread()); 517 DCHECK(thread_checker_.CalledOnValidThread());
516 518
517 response->SetBoolean("result", result); 519 response->SetBoolean("result", result);
518 channel_->SendMessage(response.Pass()); 520 channel_->SendMessage(std::move(response));
519 } 521 }
520 522
521 void Me2MeNativeMessagingHost::SendCredentialsResponse( 523 void Me2MeNativeMessagingHost::SendCredentialsResponse(
522 scoped_ptr<base::DictionaryValue> response, 524 scoped_ptr<base::DictionaryValue> response,
523 const std::string& user_email, 525 const std::string& user_email,
524 const std::string& refresh_token) { 526 const std::string& refresh_token) {
525 DCHECK(thread_checker_.CalledOnValidThread()); 527 DCHECK(thread_checker_.CalledOnValidThread());
526 528
527 if (!user_email.empty()) { 529 if (!user_email.empty()) {
528 response->SetString("userEmail", user_email); 530 response->SetString("userEmail", user_email);
529 } 531 }
530 response->SetString("refreshToken", refresh_token); 532 response->SetString("refreshToken", refresh_token);
531 channel_->SendMessage(response.Pass()); 533 channel_->SendMessage(std::move(response));
532 } 534 }
533 535
534 void Me2MeNativeMessagingHost::OnError() { 536 void Me2MeNativeMessagingHost::OnError() {
535 // Trigger a host shutdown by sending a nullptr message. 537 // Trigger a host shutdown by sending a nullptr message.
536 channel_->SendMessage(nullptr); 538 channel_->SendMessage(nullptr);
537 } 539 }
538 540
539 void Me2MeNativeMessagingHost::Stop() { 541 void Me2MeNativeMessagingHost::Stop() {
540 DCHECK(thread_checker_.CalledOnValidThread()); 542 DCHECK(thread_checker_.CalledOnValidThread());
541 543
542 if (!quit_closure_.is_null()) 544 if (!quit_closure_.is_null())
543 base::ResetAndReturn(&quit_closure_).Run(); 545 base::ResetAndReturn(&quit_closure_).Run();
544 } 546 }
545 547
546 #if defined(OS_WIN) 548 #if defined(OS_WIN)
547 Me2MeNativeMessagingHost::ElevatedChannelEventHandler:: 549 Me2MeNativeMessagingHost::ElevatedChannelEventHandler::
548 ElevatedChannelEventHandler(Me2MeNativeMessagingHost* host) 550 ElevatedChannelEventHandler(Me2MeNativeMessagingHost* host)
549 : parent_(host) { 551 : parent_(host) {
550 } 552 }
551 553
552 void Me2MeNativeMessagingHost::ElevatedChannelEventHandler::OnMessage( 554 void Me2MeNativeMessagingHost::ElevatedChannelEventHandler::OnMessage(
553 scoped_ptr<base::Value> message) { 555 scoped_ptr<base::Value> message) {
554 DCHECK(parent_->thread_checker_.CalledOnValidThread()); 556 DCHECK(parent_->thread_checker_.CalledOnValidThread());
555 557
556 // Simply pass along the response from the elevated host to the client. 558 // Simply pass along the response from the elevated host to the client.
557 parent_->channel_->SendMessage(message.Pass()); 559 parent_->channel_->SendMessage(std::move(message));
558 } 560 }
559 561
560 void Me2MeNativeMessagingHost::ElevatedChannelEventHandler::OnDisconnect() { 562 void Me2MeNativeMessagingHost::ElevatedChannelEventHandler::OnDisconnect() {
561 parent_->OnDisconnect(); 563 parent_->OnDisconnect();
562 } 564 }
563 565
564 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( 566 bool Me2MeNativeMessagingHost::DelegateToElevatedHost(
565 scoped_ptr<base::DictionaryValue> message) { 567 scoped_ptr<base::DictionaryValue> message) {
566 DCHECK(thread_checker_.CalledOnValidThread()); 568 DCHECK(thread_checker_.CalledOnValidThread());
567 569
568 EnsureElevatedHostCreated(); 570 EnsureElevatedHostCreated();
569 571
570 // elevated_channel_ will be null if user rejects the UAC request. 572 // elevated_channel_ will be null if user rejects the UAC request.
571 if (elevated_channel_) 573 if (elevated_channel_)
572 elevated_channel_->SendMessage(message.Pass()); 574 elevated_channel_->SendMessage(std::move(message));
573 575
574 return elevated_channel_ != nullptr; 576 return elevated_channel_ != nullptr;
575 } 577 }
576 578
577 void Me2MeNativeMessagingHost::EnsureElevatedHostCreated() { 579 void Me2MeNativeMessagingHost::EnsureElevatedHostCreated() {
578 DCHECK(thread_checker_.CalledOnValidThread()); 580 DCHECK(thread_checker_.CalledOnValidThread());
579 DCHECK(needs_elevation_); 581 DCHECK(needs_elevation_);
580 582
581 if (elevated_channel_) 583 if (elevated_channel_)
582 return; 584 return;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 745
744 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( 746 bool Me2MeNativeMessagingHost::DelegateToElevatedHost(
745 scoped_ptr<base::DictionaryValue> message) { 747 scoped_ptr<base::DictionaryValue> message) {
746 NOTREACHED(); 748 NOTREACHED();
747 return false; 749 return false;
748 } 750 }
749 751
750 #endif // !defined(OS_WIN) 752 #endif // !defined(OS_WIN)
751 753
752 } // namespace remoting 754 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/setup/host_starter.cc ('k') | remoting/host/setup/me2me_native_messaging_host_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698