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