| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/setup/me2me_native_messaging_host.h" | 5 #include "remoting/host/setup/me2me_native_messaging_host.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 // Features supported in addition to the base protocol. | 52 // Features supported in addition to the base protocol. |
| 53 const char* kSupportedFeatures[] = { | 53 const char* kSupportedFeatures[] = { |
| 54 "pairingRegistry", | 54 "pairingRegistry", |
| 55 "oauthClient", | 55 "oauthClient", |
| 56 "getRefreshTokenFromAuthCode", | 56 "getRefreshTokenFromAuthCode", |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 // Helper to extract the "config" part of a message as a DictionaryValue. | 59 // Helper to extract the "config" part of a message as a DictionaryValue. |
| 60 // Returns nullptr on failure, and logs an error message. | 60 // Returns nullptr on failure, and logs an error message. |
| 61 scoped_ptr<base::DictionaryValue> ConfigDictionaryFromMessage( | 61 std::unique_ptr<base::DictionaryValue> ConfigDictionaryFromMessage( |
| 62 scoped_ptr<base::DictionaryValue> message) { | 62 std::unique_ptr<base::DictionaryValue> message) { |
| 63 scoped_ptr<base::DictionaryValue> result; | 63 std::unique_ptr<base::DictionaryValue> result; |
| 64 const base::DictionaryValue* config_dict; | 64 const base::DictionaryValue* config_dict; |
| 65 if (message->GetDictionary("config", &config_dict)) { | 65 if (message->GetDictionary("config", &config_dict)) { |
| 66 result.reset(config_dict->DeepCopy()); | 66 result.reset(config_dict->DeepCopy()); |
| 67 } else { | 67 } else { |
| 68 LOG(ERROR) << "'config' dictionary not found"; | 68 LOG(ERROR) << "'config' dictionary not found"; |
| 69 } | 69 } |
| 70 return result; | 70 return result; |
| 71 } | 71 } |
| 72 | 72 |
| 73 } // namespace | 73 } // namespace |
| 74 | 74 |
| 75 namespace remoting { | 75 namespace remoting { |
| 76 | 76 |
| 77 Me2MeNativeMessagingHost::Me2MeNativeMessagingHost( | 77 Me2MeNativeMessagingHost::Me2MeNativeMessagingHost( |
| 78 bool needs_elevation, | 78 bool needs_elevation, |
| 79 intptr_t parent_window_handle, | 79 intptr_t parent_window_handle, |
| 80 scoped_ptr<extensions::NativeMessagingChannel> channel, | 80 std::unique_ptr<extensions::NativeMessagingChannel> channel, |
| 81 scoped_refptr<DaemonController> daemon_controller, | 81 scoped_refptr<DaemonController> daemon_controller, |
| 82 scoped_refptr<protocol::PairingRegistry> pairing_registry, | 82 scoped_refptr<protocol::PairingRegistry> pairing_registry, |
| 83 scoped_ptr<OAuthClient> oauth_client) | 83 std::unique_ptr<OAuthClient> oauth_client) |
| 84 : needs_elevation_(needs_elevation), | 84 : needs_elevation_(needs_elevation), |
| 85 #if defined(OS_WIN) | 85 #if defined(OS_WIN) |
| 86 parent_window_handle_(parent_window_handle), | 86 parent_window_handle_(parent_window_handle), |
| 87 #endif | 87 #endif |
| 88 channel_(std::move(channel)), | 88 channel_(std::move(channel)), |
| 89 log_message_handler_( | 89 log_message_handler_( |
| 90 base::Bind(&extensions::NativeMessagingChannel::SendMessage, | 90 base::Bind(&extensions::NativeMessagingChannel::SendMessage, |
| 91 base::Unretained(channel_.get()))), | 91 base::Unretained(channel_.get()))), |
| 92 daemon_controller_(daemon_controller), | 92 daemon_controller_(daemon_controller), |
| 93 pairing_registry_(pairing_registry), | 93 pairing_registry_(pairing_registry), |
| 94 oauth_client_(std::move(oauth_client)), | 94 oauth_client_(std::move(oauth_client)), |
| 95 weak_factory_(this) { | 95 weak_factory_(this) { |
| 96 weak_ptr_ = weak_factory_.GetWeakPtr(); | 96 weak_ptr_ = weak_factory_.GetWeakPtr(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 Me2MeNativeMessagingHost::~Me2MeNativeMessagingHost() { | 99 Me2MeNativeMessagingHost::~Me2MeNativeMessagingHost() { |
| 100 DCHECK(thread_checker_.CalledOnValidThread()); | 100 DCHECK(thread_checker_.CalledOnValidThread()); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void Me2MeNativeMessagingHost::Start( | 103 void Me2MeNativeMessagingHost::Start( |
| 104 const base::Closure& quit_closure) { | 104 const base::Closure& quit_closure) { |
| 105 DCHECK(thread_checker_.CalledOnValidThread()); | 105 DCHECK(thread_checker_.CalledOnValidThread()); |
| 106 DCHECK(!quit_closure.is_null()); | 106 DCHECK(!quit_closure.is_null()); |
| 107 | 107 |
| 108 quit_closure_ = quit_closure; | 108 quit_closure_ = quit_closure; |
| 109 | 109 |
| 110 channel_->Start(this); | 110 channel_->Start(this); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void Me2MeNativeMessagingHost::OnMessage(scoped_ptr<base::Value> message) { | 113 void Me2MeNativeMessagingHost::OnMessage(std::unique_ptr<base::Value> message) { |
| 114 DCHECK(thread_checker_.CalledOnValidThread()); | 114 DCHECK(thread_checker_.CalledOnValidThread()); |
| 115 | 115 |
| 116 if (!message->IsType(base::Value::TYPE_DICTIONARY)) { | 116 if (!message->IsType(base::Value::TYPE_DICTIONARY)) { |
| 117 LOG(ERROR) << "Received a message that's not a dictionary."; | 117 LOG(ERROR) << "Received a message that's not a dictionary."; |
| 118 channel_->SendMessage(nullptr); | 118 channel_->SendMessage(nullptr); |
| 119 return; | 119 return; |
| 120 } | 120 } |
| 121 | 121 |
| 122 scoped_ptr<base::DictionaryValue> message_dict( | 122 std::unique_ptr<base::DictionaryValue> message_dict( |
| 123 static_cast<base::DictionaryValue*>(message.release())); | 123 static_cast<base::DictionaryValue*>(message.release())); |
| 124 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue()); | 124 std::unique_ptr<base::DictionaryValue> response(new base::DictionaryValue()); |
| 125 | 125 |
| 126 // If the client supplies an ID, it will expect it in the response. This | 126 // If the client supplies an ID, it will expect it in the response. This |
| 127 // might be a string or a number, so cope with both. | 127 // might be a string or a number, so cope with both. |
| 128 const base::Value* id; | 128 const base::Value* id; |
| 129 if (message_dict->Get("id", &id)) | 129 if (message_dict->Get("id", &id)) |
| 130 response->Set("id", id->DeepCopy()); | 130 response->Set("id", id->DeepCopy()); |
| 131 | 131 |
| 132 std::string type; | 132 std::string type; |
| 133 if (!message_dict->GetString("type", &type)) { | 133 if (!message_dict->GetString("type", &type)) { |
| 134 LOG(ERROR) << "'type' not found"; | 134 LOG(ERROR) << "'type' not found"; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 OnError(); | 177 OnError(); |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 | 180 |
| 181 void Me2MeNativeMessagingHost::OnDisconnect() { | 181 void Me2MeNativeMessagingHost::OnDisconnect() { |
| 182 if (!quit_closure_.is_null()) | 182 if (!quit_closure_.is_null()) |
| 183 base::ResetAndReturn(&quit_closure_).Run(); | 183 base::ResetAndReturn(&quit_closure_).Run(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void Me2MeNativeMessagingHost::ProcessHello( | 186 void Me2MeNativeMessagingHost::ProcessHello( |
| 187 scoped_ptr<base::DictionaryValue> message, | 187 std::unique_ptr<base::DictionaryValue> message, |
| 188 scoped_ptr<base::DictionaryValue> response) { | 188 std::unique_ptr<base::DictionaryValue> response) { |
| 189 DCHECK(thread_checker_.CalledOnValidThread()); | 189 DCHECK(thread_checker_.CalledOnValidThread()); |
| 190 | 190 |
| 191 response->SetString("version", STRINGIZE(VERSION)); | 191 response->SetString("version", STRINGIZE(VERSION)); |
| 192 scoped_ptr<base::ListValue> supported_features_list(new base::ListValue()); | 192 std::unique_ptr<base::ListValue> supported_features_list( |
| 193 new base::ListValue()); |
| 193 supported_features_list->AppendStrings(std::vector<std::string>( | 194 supported_features_list->AppendStrings(std::vector<std::string>( |
| 194 kSupportedFeatures, kSupportedFeatures + arraysize(kSupportedFeatures))); | 195 kSupportedFeatures, kSupportedFeatures + arraysize(kSupportedFeatures))); |
| 195 response->Set("supportedFeatures", supported_features_list.release()); | 196 response->Set("supportedFeatures", supported_features_list.release()); |
| 196 channel_->SendMessage(std::move(response)); | 197 channel_->SendMessage(std::move(response)); |
| 197 } | 198 } |
| 198 | 199 |
| 199 void Me2MeNativeMessagingHost::ProcessClearPairedClients( | 200 void Me2MeNativeMessagingHost::ProcessClearPairedClients( |
| 200 scoped_ptr<base::DictionaryValue> message, | 201 std::unique_ptr<base::DictionaryValue> message, |
| 201 scoped_ptr<base::DictionaryValue> response) { | 202 std::unique_ptr<base::DictionaryValue> response) { |
| 202 DCHECK(thread_checker_.CalledOnValidThread()); | 203 DCHECK(thread_checker_.CalledOnValidThread()); |
| 203 | 204 |
| 204 if (needs_elevation_) { | 205 if (needs_elevation_) { |
| 205 if (!DelegateToElevatedHost(std::move(message))) | 206 if (!DelegateToElevatedHost(std::move(message))) |
| 206 SendBooleanResult(std::move(response), false); | 207 SendBooleanResult(std::move(response), false); |
| 207 return; | 208 return; |
| 208 } | 209 } |
| 209 | 210 |
| 210 if (pairing_registry_.get()) { | 211 if (pairing_registry_.get()) { |
| 211 pairing_registry_->ClearAllPairings( | 212 pairing_registry_->ClearAllPairings( |
| 212 base::Bind(&Me2MeNativeMessagingHost::SendBooleanResult, weak_ptr_, | 213 base::Bind(&Me2MeNativeMessagingHost::SendBooleanResult, weak_ptr_, |
| 213 base::Passed(&response))); | 214 base::Passed(&response))); |
| 214 } else { | 215 } else { |
| 215 SendBooleanResult(std::move(response), false); | 216 SendBooleanResult(std::move(response), false); |
| 216 } | 217 } |
| 217 } | 218 } |
| 218 | 219 |
| 219 void Me2MeNativeMessagingHost::ProcessDeletePairedClient( | 220 void Me2MeNativeMessagingHost::ProcessDeletePairedClient( |
| 220 scoped_ptr<base::DictionaryValue> message, | 221 std::unique_ptr<base::DictionaryValue> message, |
| 221 scoped_ptr<base::DictionaryValue> response) { | 222 std::unique_ptr<base::DictionaryValue> response) { |
| 222 DCHECK(thread_checker_.CalledOnValidThread()); | 223 DCHECK(thread_checker_.CalledOnValidThread()); |
| 223 | 224 |
| 224 if (needs_elevation_) { | 225 if (needs_elevation_) { |
| 225 if (!DelegateToElevatedHost(std::move(message))) | 226 if (!DelegateToElevatedHost(std::move(message))) |
| 226 SendBooleanResult(std::move(response), false); | 227 SendBooleanResult(std::move(response), false); |
| 227 return; | 228 return; |
| 228 } | 229 } |
| 229 | 230 |
| 230 std::string client_id; | 231 std::string client_id; |
| 231 if (!message->GetString(protocol::PairingRegistry::kClientIdKey, | 232 if (!message->GetString(protocol::PairingRegistry::kClientIdKey, |
| 232 &client_id)) { | 233 &client_id)) { |
| 233 LOG(ERROR) << "'" << protocol::PairingRegistry::kClientIdKey | 234 LOG(ERROR) << "'" << protocol::PairingRegistry::kClientIdKey |
| 234 << "' string not found."; | 235 << "' string not found."; |
| 235 OnError(); | 236 OnError(); |
| 236 return; | 237 return; |
| 237 } | 238 } |
| 238 | 239 |
| 239 if (pairing_registry_.get()) { | 240 if (pairing_registry_.get()) { |
| 240 pairing_registry_->DeletePairing( | 241 pairing_registry_->DeletePairing( |
| 241 client_id, base::Bind(&Me2MeNativeMessagingHost::SendBooleanResult, | 242 client_id, base::Bind(&Me2MeNativeMessagingHost::SendBooleanResult, |
| 242 weak_ptr_, base::Passed(&response))); | 243 weak_ptr_, base::Passed(&response))); |
| 243 } else { | 244 } else { |
| 244 SendBooleanResult(std::move(response), false); | 245 SendBooleanResult(std::move(response), false); |
| 245 } | 246 } |
| 246 } | 247 } |
| 247 | 248 |
| 248 void Me2MeNativeMessagingHost::ProcessGetHostName( | 249 void Me2MeNativeMessagingHost::ProcessGetHostName( |
| 249 scoped_ptr<base::DictionaryValue> message, | 250 std::unique_ptr<base::DictionaryValue> message, |
| 250 scoped_ptr<base::DictionaryValue> response) { | 251 std::unique_ptr<base::DictionaryValue> response) { |
| 251 DCHECK(thread_checker_.CalledOnValidThread()); | 252 DCHECK(thread_checker_.CalledOnValidThread()); |
| 252 | 253 |
| 253 response->SetString("hostname", net::GetHostName()); | 254 response->SetString("hostname", net::GetHostName()); |
| 254 channel_->SendMessage(std::move(response)); | 255 channel_->SendMessage(std::move(response)); |
| 255 } | 256 } |
| 256 | 257 |
| 257 void Me2MeNativeMessagingHost::ProcessGetPinHash( | 258 void Me2MeNativeMessagingHost::ProcessGetPinHash( |
| 258 scoped_ptr<base::DictionaryValue> message, | 259 std::unique_ptr<base::DictionaryValue> message, |
| 259 scoped_ptr<base::DictionaryValue> response) { | 260 std::unique_ptr<base::DictionaryValue> response) { |
| 260 DCHECK(thread_checker_.CalledOnValidThread()); | 261 DCHECK(thread_checker_.CalledOnValidThread()); |
| 261 | 262 |
| 262 std::string host_id; | 263 std::string host_id; |
| 263 if (!message->GetString("hostId", &host_id)) { | 264 if (!message->GetString("hostId", &host_id)) { |
| 264 LOG(ERROR) << "'hostId' not found: " << message.get(); | 265 LOG(ERROR) << "'hostId' not found: " << message.get(); |
| 265 OnError(); | 266 OnError(); |
| 266 return; | 267 return; |
| 267 } | 268 } |
| 268 std::string pin; | 269 std::string pin; |
| 269 if (!message->GetString("pin", &pin)) { | 270 if (!message->GetString("pin", &pin)) { |
| 270 LOG(ERROR) << "'pin' not found: " << message.get(); | 271 LOG(ERROR) << "'pin' not found: " << message.get(); |
| 271 OnError(); | 272 OnError(); |
| 272 return; | 273 return; |
| 273 } | 274 } |
| 274 response->SetString("hash", MakeHostPinHash(host_id, pin)); | 275 response->SetString("hash", MakeHostPinHash(host_id, pin)); |
| 275 channel_->SendMessage(std::move(response)); | 276 channel_->SendMessage(std::move(response)); |
| 276 } | 277 } |
| 277 | 278 |
| 278 void Me2MeNativeMessagingHost::ProcessGenerateKeyPair( | 279 void Me2MeNativeMessagingHost::ProcessGenerateKeyPair( |
| 279 scoped_ptr<base::DictionaryValue> message, | 280 std::unique_ptr<base::DictionaryValue> message, |
| 280 scoped_ptr<base::DictionaryValue> response) { | 281 std::unique_ptr<base::DictionaryValue> response) { |
| 281 DCHECK(thread_checker_.CalledOnValidThread()); | 282 DCHECK(thread_checker_.CalledOnValidThread()); |
| 282 | 283 |
| 283 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate(); | 284 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate(); |
| 284 response->SetString("privateKey", key_pair->ToString()); | 285 response->SetString("privateKey", key_pair->ToString()); |
| 285 response->SetString("publicKey", key_pair->GetPublicKey()); | 286 response->SetString("publicKey", key_pair->GetPublicKey()); |
| 286 channel_->SendMessage(std::move(response)); | 287 channel_->SendMessage(std::move(response)); |
| 287 } | 288 } |
| 288 | 289 |
| 289 void Me2MeNativeMessagingHost::ProcessUpdateDaemonConfig( | 290 void Me2MeNativeMessagingHost::ProcessUpdateDaemonConfig( |
| 290 scoped_ptr<base::DictionaryValue> message, | 291 std::unique_ptr<base::DictionaryValue> message, |
| 291 scoped_ptr<base::DictionaryValue> response) { | 292 std::unique_ptr<base::DictionaryValue> response) { |
| 292 DCHECK(thread_checker_.CalledOnValidThread()); | 293 DCHECK(thread_checker_.CalledOnValidThread()); |
| 293 | 294 |
| 294 if (needs_elevation_) { | 295 if (needs_elevation_) { |
| 295 if (!DelegateToElevatedHost(std::move(message))) | 296 if (!DelegateToElevatedHost(std::move(message))) |
| 296 SendAsyncResult(std::move(response), DaemonController::RESULT_FAILED); | 297 SendAsyncResult(std::move(response), DaemonController::RESULT_FAILED); |
| 297 return; | 298 return; |
| 298 } | 299 } |
| 299 | 300 |
| 300 scoped_ptr<base::DictionaryValue> config_dict = | 301 std::unique_ptr<base::DictionaryValue> config_dict = |
| 301 ConfigDictionaryFromMessage(std::move(message)); | 302 ConfigDictionaryFromMessage(std::move(message)); |
| 302 if (!config_dict) { | 303 if (!config_dict) { |
| 303 OnError(); | 304 OnError(); |
| 304 return; | 305 return; |
| 305 } | 306 } |
| 306 | 307 |
| 307 daemon_controller_->UpdateConfig( | 308 daemon_controller_->UpdateConfig( |
| 308 std::move(config_dict), | 309 std::move(config_dict), |
| 309 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_, | 310 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_, |
| 310 base::Passed(&response))); | 311 base::Passed(&response))); |
| 311 } | 312 } |
| 312 | 313 |
| 313 void Me2MeNativeMessagingHost::ProcessGetDaemonConfig( | 314 void Me2MeNativeMessagingHost::ProcessGetDaemonConfig( |
| 314 scoped_ptr<base::DictionaryValue> message, | 315 std::unique_ptr<base::DictionaryValue> message, |
| 315 scoped_ptr<base::DictionaryValue> response) { | 316 std::unique_ptr<base::DictionaryValue> response) { |
| 316 DCHECK(thread_checker_.CalledOnValidThread()); | 317 DCHECK(thread_checker_.CalledOnValidThread()); |
| 317 | 318 |
| 318 daemon_controller_->GetConfig( | 319 daemon_controller_->GetConfig( |
| 319 base::Bind(&Me2MeNativeMessagingHost::SendConfigResponse, weak_ptr_, | 320 base::Bind(&Me2MeNativeMessagingHost::SendConfigResponse, weak_ptr_, |
| 320 base::Passed(&response))); | 321 base::Passed(&response))); |
| 321 } | 322 } |
| 322 | 323 |
| 323 void Me2MeNativeMessagingHost::ProcessGetPairedClients( | 324 void Me2MeNativeMessagingHost::ProcessGetPairedClients( |
| 324 scoped_ptr<base::DictionaryValue> message, | 325 std::unique_ptr<base::DictionaryValue> message, |
| 325 scoped_ptr<base::DictionaryValue> response) { | 326 std::unique_ptr<base::DictionaryValue> response) { |
| 326 DCHECK(thread_checker_.CalledOnValidThread()); | 327 DCHECK(thread_checker_.CalledOnValidThread()); |
| 327 | 328 |
| 328 if (pairing_registry_.get()) { | 329 if (pairing_registry_.get()) { |
| 329 pairing_registry_->GetAllPairings( | 330 pairing_registry_->GetAllPairings( |
| 330 base::Bind(&Me2MeNativeMessagingHost::SendPairedClientsResponse, | 331 base::Bind(&Me2MeNativeMessagingHost::SendPairedClientsResponse, |
| 331 weak_ptr_, base::Passed(&response))); | 332 weak_ptr_, base::Passed(&response))); |
| 332 } else { | 333 } else { |
| 333 scoped_ptr<base::ListValue> no_paired_clients(new base::ListValue); | 334 std::unique_ptr<base::ListValue> no_paired_clients(new base::ListValue); |
| 334 SendPairedClientsResponse(std::move(response), | 335 SendPairedClientsResponse(std::move(response), |
| 335 std::move(no_paired_clients)); | 336 std::move(no_paired_clients)); |
| 336 } | 337 } |
| 337 } | 338 } |
| 338 | 339 |
| 339 void Me2MeNativeMessagingHost::ProcessGetUsageStatsConsent( | 340 void Me2MeNativeMessagingHost::ProcessGetUsageStatsConsent( |
| 340 scoped_ptr<base::DictionaryValue> message, | 341 std::unique_ptr<base::DictionaryValue> message, |
| 341 scoped_ptr<base::DictionaryValue> response) { | 342 std::unique_ptr<base::DictionaryValue> response) { |
| 342 DCHECK(thread_checker_.CalledOnValidThread()); | 343 DCHECK(thread_checker_.CalledOnValidThread()); |
| 343 | 344 |
| 344 daemon_controller_->GetUsageStatsConsent( | 345 daemon_controller_->GetUsageStatsConsent( |
| 345 base::Bind(&Me2MeNativeMessagingHost::SendUsageStatsConsentResponse, | 346 base::Bind(&Me2MeNativeMessagingHost::SendUsageStatsConsentResponse, |
| 346 weak_ptr_, base::Passed(&response))); | 347 weak_ptr_, base::Passed(&response))); |
| 347 } | 348 } |
| 348 | 349 |
| 349 void Me2MeNativeMessagingHost::ProcessStartDaemon( | 350 void Me2MeNativeMessagingHost::ProcessStartDaemon( |
| 350 scoped_ptr<base::DictionaryValue> message, | 351 std::unique_ptr<base::DictionaryValue> message, |
| 351 scoped_ptr<base::DictionaryValue> response) { | 352 std::unique_ptr<base::DictionaryValue> response) { |
| 352 DCHECK(thread_checker_.CalledOnValidThread()); | 353 DCHECK(thread_checker_.CalledOnValidThread()); |
| 353 | 354 |
| 354 if (needs_elevation_) { | 355 if (needs_elevation_) { |
| 355 if (!DelegateToElevatedHost(std::move(message))) | 356 if (!DelegateToElevatedHost(std::move(message))) |
| 356 SendAsyncResult(std::move(response), DaemonController::RESULT_FAILED); | 357 SendAsyncResult(std::move(response), DaemonController::RESULT_FAILED); |
| 357 return; | 358 return; |
| 358 } | 359 } |
| 359 | 360 |
| 360 bool consent; | 361 bool consent; |
| 361 if (!message->GetBoolean("consent", &consent)) { | 362 if (!message->GetBoolean("consent", &consent)) { |
| 362 LOG(ERROR) << "'consent' not found."; | 363 LOG(ERROR) << "'consent' not found."; |
| 363 OnError(); | 364 OnError(); |
| 364 return; | 365 return; |
| 365 } | 366 } |
| 366 | 367 |
| 367 scoped_ptr<base::DictionaryValue> config_dict = | 368 std::unique_ptr<base::DictionaryValue> config_dict = |
| 368 ConfigDictionaryFromMessage(std::move(message)); | 369 ConfigDictionaryFromMessage(std::move(message)); |
| 369 if (!config_dict) { | 370 if (!config_dict) { |
| 370 OnError(); | 371 OnError(); |
| 371 return; | 372 return; |
| 372 } | 373 } |
| 373 | 374 |
| 374 daemon_controller_->SetConfigAndStart( | 375 daemon_controller_->SetConfigAndStart( |
| 375 std::move(config_dict), consent, | 376 std::move(config_dict), consent, |
| 376 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_, | 377 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_, |
| 377 base::Passed(&response))); | 378 base::Passed(&response))); |
| 378 } | 379 } |
| 379 | 380 |
| 380 void Me2MeNativeMessagingHost::ProcessStopDaemon( | 381 void Me2MeNativeMessagingHost::ProcessStopDaemon( |
| 381 scoped_ptr<base::DictionaryValue> message, | 382 std::unique_ptr<base::DictionaryValue> message, |
| 382 scoped_ptr<base::DictionaryValue> response) { | 383 std::unique_ptr<base::DictionaryValue> response) { |
| 383 DCHECK(thread_checker_.CalledOnValidThread()); | 384 DCHECK(thread_checker_.CalledOnValidThread()); |
| 384 | 385 |
| 385 if (needs_elevation_) { | 386 if (needs_elevation_) { |
| 386 if (!DelegateToElevatedHost(std::move(message))) | 387 if (!DelegateToElevatedHost(std::move(message))) |
| 387 SendAsyncResult(std::move(response), DaemonController::RESULT_FAILED); | 388 SendAsyncResult(std::move(response), DaemonController::RESULT_FAILED); |
| 388 return; | 389 return; |
| 389 } | 390 } |
| 390 | 391 |
| 391 daemon_controller_->Stop( | 392 daemon_controller_->Stop( |
| 392 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_, | 393 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_, |
| 393 base::Passed(&response))); | 394 base::Passed(&response))); |
| 394 } | 395 } |
| 395 | 396 |
| 396 void Me2MeNativeMessagingHost::ProcessGetDaemonState( | 397 void Me2MeNativeMessagingHost::ProcessGetDaemonState( |
| 397 scoped_ptr<base::DictionaryValue> message, | 398 std::unique_ptr<base::DictionaryValue> message, |
| 398 scoped_ptr<base::DictionaryValue> response) { | 399 std::unique_ptr<base::DictionaryValue> response) { |
| 399 DCHECK(thread_checker_.CalledOnValidThread()); | 400 DCHECK(thread_checker_.CalledOnValidThread()); |
| 400 | 401 |
| 401 DaemonController::State state = daemon_controller_->GetState(); | 402 DaemonController::State state = daemon_controller_->GetState(); |
| 402 switch (state) { | 403 switch (state) { |
| 403 case DaemonController::STATE_NOT_IMPLEMENTED: | 404 case DaemonController::STATE_NOT_IMPLEMENTED: |
| 404 response->SetString("state", "NOT_IMPLEMENTED"); | 405 response->SetString("state", "NOT_IMPLEMENTED"); |
| 405 break; | 406 break; |
| 406 case DaemonController::STATE_STOPPED: | 407 case DaemonController::STATE_STOPPED: |
| 407 response->SetString("state", "STOPPED"); | 408 response->SetString("state", "STOPPED"); |
| 408 break; | 409 break; |
| 409 case DaemonController::STATE_STARTING: | 410 case DaemonController::STATE_STARTING: |
| 410 response->SetString("state", "STARTING"); | 411 response->SetString("state", "STARTING"); |
| 411 break; | 412 break; |
| 412 case DaemonController::STATE_STARTED: | 413 case DaemonController::STATE_STARTED: |
| 413 response->SetString("state", "STARTED"); | 414 response->SetString("state", "STARTED"); |
| 414 break; | 415 break; |
| 415 case DaemonController::STATE_STOPPING: | 416 case DaemonController::STATE_STOPPING: |
| 416 response->SetString("state", "STOPPING"); | 417 response->SetString("state", "STOPPING"); |
| 417 break; | 418 break; |
| 418 case DaemonController::STATE_UNKNOWN: | 419 case DaemonController::STATE_UNKNOWN: |
| 419 response->SetString("state", "UNKNOWN"); | 420 response->SetString("state", "UNKNOWN"); |
| 420 break; | 421 break; |
| 421 } | 422 } |
| 422 channel_->SendMessage(std::move(response)); | 423 channel_->SendMessage(std::move(response)); |
| 423 } | 424 } |
| 424 | 425 |
| 425 void Me2MeNativeMessagingHost::ProcessGetHostClientId( | 426 void Me2MeNativeMessagingHost::ProcessGetHostClientId( |
| 426 scoped_ptr<base::DictionaryValue> message, | 427 std::unique_ptr<base::DictionaryValue> message, |
| 427 scoped_ptr<base::DictionaryValue> response) { | 428 std::unique_ptr<base::DictionaryValue> response) { |
| 428 DCHECK(thread_checker_.CalledOnValidThread()); | 429 DCHECK(thread_checker_.CalledOnValidThread()); |
| 429 | 430 |
| 430 response->SetString("clientId", google_apis::GetOAuth2ClientID( | 431 response->SetString("clientId", google_apis::GetOAuth2ClientID( |
| 431 google_apis::CLIENT_REMOTING_HOST)); | 432 google_apis::CLIENT_REMOTING_HOST)); |
| 432 channel_->SendMessage(std::move(response)); | 433 channel_->SendMessage(std::move(response)); |
| 433 } | 434 } |
| 434 | 435 |
| 435 void Me2MeNativeMessagingHost::ProcessGetCredentialsFromAuthCode( | 436 void Me2MeNativeMessagingHost::ProcessGetCredentialsFromAuthCode( |
| 436 scoped_ptr<base::DictionaryValue> message, | 437 std::unique_ptr<base::DictionaryValue> message, |
| 437 scoped_ptr<base::DictionaryValue> response, | 438 std::unique_ptr<base::DictionaryValue> response, |
| 438 bool need_user_email) { | 439 bool need_user_email) { |
| 439 DCHECK(thread_checker_.CalledOnValidThread()); | 440 DCHECK(thread_checker_.CalledOnValidThread()); |
| 440 | 441 |
| 441 std::string auth_code; | 442 std::string auth_code; |
| 442 if (!message->GetString("authorizationCode", &auth_code)) { | 443 if (!message->GetString("authorizationCode", &auth_code)) { |
| 443 LOG(ERROR) << "'authorizationCode' string not found."; | 444 LOG(ERROR) << "'authorizationCode' string not found."; |
| 444 OnError(); | 445 OnError(); |
| 445 return; | 446 return; |
| 446 } | 447 } |
| 447 | 448 |
| 448 gaia::OAuthClientInfo oauth_client_info = { | 449 gaia::OAuthClientInfo oauth_client_info = { |
| 449 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING_HOST), | 450 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING_HOST), |
| 450 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING_HOST), | 451 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING_HOST), |
| 451 kServiceAccountRedirectUri | 452 kServiceAccountRedirectUri |
| 452 }; | 453 }; |
| 453 | 454 |
| 454 oauth_client_->GetCredentialsFromAuthCode( | 455 oauth_client_->GetCredentialsFromAuthCode( |
| 455 oauth_client_info, auth_code, need_user_email, base::Bind( | 456 oauth_client_info, auth_code, need_user_email, base::Bind( |
| 456 &Me2MeNativeMessagingHost::SendCredentialsResponse, weak_ptr_, | 457 &Me2MeNativeMessagingHost::SendCredentialsResponse, weak_ptr_, |
| 457 base::Passed(&response))); | 458 base::Passed(&response))); |
| 458 } | 459 } |
| 459 | 460 |
| 460 void Me2MeNativeMessagingHost::SendConfigResponse( | 461 void Me2MeNativeMessagingHost::SendConfigResponse( |
| 461 scoped_ptr<base::DictionaryValue> response, | 462 std::unique_ptr<base::DictionaryValue> response, |
| 462 scoped_ptr<base::DictionaryValue> config) { | 463 std::unique_ptr<base::DictionaryValue> config) { |
| 463 DCHECK(thread_checker_.CalledOnValidThread()); | 464 DCHECK(thread_checker_.CalledOnValidThread()); |
| 464 | 465 |
| 465 if (config) { | 466 if (config) { |
| 466 response->Set("config", config.release()); | 467 response->Set("config", config.release()); |
| 467 } else { | 468 } else { |
| 468 response->Set("config", base::Value::CreateNullValue()); | 469 response->Set("config", base::Value::CreateNullValue()); |
| 469 } | 470 } |
| 470 channel_->SendMessage(std::move(response)); | 471 channel_->SendMessage(std::move(response)); |
| 471 } | 472 } |
| 472 | 473 |
| 473 void Me2MeNativeMessagingHost::SendPairedClientsResponse( | 474 void Me2MeNativeMessagingHost::SendPairedClientsResponse( |
| 474 scoped_ptr<base::DictionaryValue> response, | 475 std::unique_ptr<base::DictionaryValue> response, |
| 475 scoped_ptr<base::ListValue> pairings) { | 476 std::unique_ptr<base::ListValue> pairings) { |
| 476 DCHECK(thread_checker_.CalledOnValidThread()); | 477 DCHECK(thread_checker_.CalledOnValidThread()); |
| 477 | 478 |
| 478 response->Set("pairedClients", pairings.release()); | 479 response->Set("pairedClients", pairings.release()); |
| 479 channel_->SendMessage(std::move(response)); | 480 channel_->SendMessage(std::move(response)); |
| 480 } | 481 } |
| 481 | 482 |
| 482 void Me2MeNativeMessagingHost::SendUsageStatsConsentResponse( | 483 void Me2MeNativeMessagingHost::SendUsageStatsConsentResponse( |
| 483 scoped_ptr<base::DictionaryValue> response, | 484 std::unique_ptr<base::DictionaryValue> response, |
| 484 const DaemonController::UsageStatsConsent& consent) { | 485 const DaemonController::UsageStatsConsent& consent) { |
| 485 DCHECK(thread_checker_.CalledOnValidThread()); | 486 DCHECK(thread_checker_.CalledOnValidThread()); |
| 486 | 487 |
| 487 response->SetBoolean("supported", consent.supported); | 488 response->SetBoolean("supported", consent.supported); |
| 488 response->SetBoolean("allowed", consent.allowed); | 489 response->SetBoolean("allowed", consent.allowed); |
| 489 response->SetBoolean("setByPolicy", consent.set_by_policy); | 490 response->SetBoolean("setByPolicy", consent.set_by_policy); |
| 490 channel_->SendMessage(std::move(response)); | 491 channel_->SendMessage(std::move(response)); |
| 491 } | 492 } |
| 492 | 493 |
| 493 void Me2MeNativeMessagingHost::SendAsyncResult( | 494 void Me2MeNativeMessagingHost::SendAsyncResult( |
| 494 scoped_ptr<base::DictionaryValue> response, | 495 std::unique_ptr<base::DictionaryValue> response, |
| 495 DaemonController::AsyncResult result) { | 496 DaemonController::AsyncResult result) { |
| 496 DCHECK(thread_checker_.CalledOnValidThread()); | 497 DCHECK(thread_checker_.CalledOnValidThread()); |
| 497 | 498 |
| 498 switch (result) { | 499 switch (result) { |
| 499 case DaemonController::RESULT_OK: | 500 case DaemonController::RESULT_OK: |
| 500 response->SetString("result", "OK"); | 501 response->SetString("result", "OK"); |
| 501 break; | 502 break; |
| 502 case DaemonController::RESULT_FAILED: | 503 case DaemonController::RESULT_FAILED: |
| 503 response->SetString("result", "FAILED"); | 504 response->SetString("result", "FAILED"); |
| 504 break; | 505 break; |
| 505 case DaemonController::RESULT_CANCELLED: | 506 case DaemonController::RESULT_CANCELLED: |
| 506 response->SetString("result", "CANCELLED"); | 507 response->SetString("result", "CANCELLED"); |
| 507 break; | 508 break; |
| 508 } | 509 } |
| 509 channel_->SendMessage(std::move(response)); | 510 channel_->SendMessage(std::move(response)); |
| 510 } | 511 } |
| 511 | 512 |
| 512 void Me2MeNativeMessagingHost::SendBooleanResult( | 513 void Me2MeNativeMessagingHost::SendBooleanResult( |
| 513 scoped_ptr<base::DictionaryValue> response, bool result) { | 514 std::unique_ptr<base::DictionaryValue> response, |
| 515 bool result) { |
| 514 DCHECK(thread_checker_.CalledOnValidThread()); | 516 DCHECK(thread_checker_.CalledOnValidThread()); |
| 515 | 517 |
| 516 response->SetBoolean("result", result); | 518 response->SetBoolean("result", result); |
| 517 channel_->SendMessage(std::move(response)); | 519 channel_->SendMessage(std::move(response)); |
| 518 } | 520 } |
| 519 | 521 |
| 520 void Me2MeNativeMessagingHost::SendCredentialsResponse( | 522 void Me2MeNativeMessagingHost::SendCredentialsResponse( |
| 521 scoped_ptr<base::DictionaryValue> response, | 523 std::unique_ptr<base::DictionaryValue> response, |
| 522 const std::string& user_email, | 524 const std::string& user_email, |
| 523 const std::string& refresh_token) { | 525 const std::string& refresh_token) { |
| 524 DCHECK(thread_checker_.CalledOnValidThread()); | 526 DCHECK(thread_checker_.CalledOnValidThread()); |
| 525 | 527 |
| 526 if (!user_email.empty()) { | 528 if (!user_email.empty()) { |
| 527 response->SetString("userEmail", user_email); | 529 response->SetString("userEmail", user_email); |
| 528 } | 530 } |
| 529 response->SetString("refreshToken", refresh_token); | 531 response->SetString("refreshToken", refresh_token); |
| 530 channel_->SendMessage(std::move(response)); | 532 channel_->SendMessage(std::move(response)); |
| 531 } | 533 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 542 base::ResetAndReturn(&quit_closure_).Run(); | 544 base::ResetAndReturn(&quit_closure_).Run(); |
| 543 } | 545 } |
| 544 | 546 |
| 545 #if defined(OS_WIN) | 547 #if defined(OS_WIN) |
| 546 Me2MeNativeMessagingHost::ElevatedChannelEventHandler:: | 548 Me2MeNativeMessagingHost::ElevatedChannelEventHandler:: |
| 547 ElevatedChannelEventHandler(Me2MeNativeMessagingHost* host) | 549 ElevatedChannelEventHandler(Me2MeNativeMessagingHost* host) |
| 548 : parent_(host) { | 550 : parent_(host) { |
| 549 } | 551 } |
| 550 | 552 |
| 551 void Me2MeNativeMessagingHost::ElevatedChannelEventHandler::OnMessage( | 553 void Me2MeNativeMessagingHost::ElevatedChannelEventHandler::OnMessage( |
| 552 scoped_ptr<base::Value> message) { | 554 std::unique_ptr<base::Value> message) { |
| 553 DCHECK(parent_->thread_checker_.CalledOnValidThread()); | 555 DCHECK(parent_->thread_checker_.CalledOnValidThread()); |
| 554 | 556 |
| 555 // Simply pass along the response from the elevated host to the client. | 557 // Simply pass along the response from the elevated host to the client. |
| 556 parent_->channel_->SendMessage(std::move(message)); | 558 parent_->channel_->SendMessage(std::move(message)); |
| 557 } | 559 } |
| 558 | 560 |
| 559 void Me2MeNativeMessagingHost::ElevatedChannelEventHandler::OnDisconnect() { | 561 void Me2MeNativeMessagingHost::ElevatedChannelEventHandler::OnDisconnect() { |
| 560 parent_->OnDisconnect(); | 562 parent_->OnDisconnect(); |
| 561 } | 563 } |
| 562 | 564 |
| 563 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( | 565 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( |
| 564 scoped_ptr<base::DictionaryValue> message) { | 566 std::unique_ptr<base::DictionaryValue> message) { |
| 565 DCHECK(thread_checker_.CalledOnValidThread()); | 567 DCHECK(thread_checker_.CalledOnValidThread()); |
| 566 | 568 |
| 567 EnsureElevatedHostCreated(); | 569 EnsureElevatedHostCreated(); |
| 568 | 570 |
| 569 // elevated_channel_ will be null if user rejects the UAC request. | 571 // elevated_channel_ will be null if user rejects the UAC request. |
| 570 if (elevated_channel_) | 572 if (elevated_channel_) |
| 571 elevated_channel_->SendMessage(std::move(message)); | 573 elevated_channel_->SendMessage(std::move(message)); |
| 572 | 574 |
| 573 return elevated_channel_ != nullptr; | 575 return elevated_channel_ != nullptr; |
| 574 } | 576 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 void Me2MeNativeMessagingHost::DisconnectElevatedHost() { | 736 void Me2MeNativeMessagingHost::DisconnectElevatedHost() { |
| 735 DCHECK(thread_checker_.CalledOnValidThread()); | 737 DCHECK(thread_checker_.CalledOnValidThread()); |
| 736 | 738 |
| 737 // This will send an EOF to the elevated host, triggering its shutdown. | 739 // This will send an EOF to the elevated host, triggering its shutdown. |
| 738 elevated_channel_.reset(); | 740 elevated_channel_.reset(); |
| 739 } | 741 } |
| 740 | 742 |
| 741 #else // defined(OS_WIN) | 743 #else // defined(OS_WIN) |
| 742 | 744 |
| 743 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( | 745 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( |
| 744 scoped_ptr<base::DictionaryValue> message) { | 746 std::unique_ptr<base::DictionaryValue> message) { |
| 745 NOTREACHED(); | 747 NOTREACHED(); |
| 746 return false; | 748 return false; |
| 747 } | 749 } |
| 748 | 750 |
| 749 #endif // !defined(OS_WIN) | 751 #endif // !defined(OS_WIN) |
| 750 | 752 |
| 751 } // namespace remoting | 753 } // namespace remoting |
| OLD | NEW |