| 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 <cstdint> | 7 #include <cstdint> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 weak_ptr_ = weak_factory_.GetWeakPtr(); | 89 weak_ptr_ = weak_factory_.GetWeakPtr(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 Me2MeNativeMessagingHost::~Me2MeNativeMessagingHost() { | 92 Me2MeNativeMessagingHost::~Me2MeNativeMessagingHost() { |
| 93 DCHECK(task_runner()->BelongsToCurrentThread()); | 93 DCHECK(task_runner()->BelongsToCurrentThread()); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void Me2MeNativeMessagingHost::OnMessage(const std::string& message) { | 96 void Me2MeNativeMessagingHost::OnMessage(const std::string& message) { |
| 97 DCHECK(task_runner()->BelongsToCurrentThread()); | 97 DCHECK(task_runner()->BelongsToCurrentThread()); |
| 98 | 98 |
| 99 std::unique_ptr<base::DictionaryValue> response(new base::DictionaryValue()); | 99 auto response = base::MakeUnique<base::DictionaryValue>(); |
| 100 std::unique_ptr<base::Value> message_value = base::JSONReader::Read(message); | 100 std::unique_ptr<base::Value> message_value = base::JSONReader::Read(message); |
| 101 if (!message_value->IsType(base::Value::Type::DICTIONARY)) { | 101 if (!message_value->IsType(base::Value::Type::DICTIONARY)) { |
| 102 OnError("Received a message that's not a dictionary."); | 102 OnError("Received a message that's not a dictionary."); |
| 103 return; | 103 return; |
| 104 } | 104 } |
| 105 | 105 |
| 106 std::unique_ptr<base::DictionaryValue> message_dict( | 106 std::unique_ptr<base::DictionaryValue> message_dict( |
| 107 static_cast<base::DictionaryValue*>(message_value.release())); | 107 static_cast<base::DictionaryValue*>(message_value.release())); |
| 108 | 108 |
| 109 // If the client supplies an ID, it will expect it in the response. This | 109 // If the client supplies an ID, it will expect it in the response. This |
| 110 // might be a string or a number, so cope with both. | 110 // might be a string or a number, so cope with both. |
| 111 const base::Value* id; | 111 const base::Value* id; |
| 112 if (message_dict->Get("id", &id)) | 112 if (message_dict->Get("id", &id)) |
| 113 response->Set("id", id->CreateDeepCopy()); | 113 response->Set("id", base::MakeUnique<base::Value>(*id)); |
| 114 | 114 |
| 115 std::string type; | 115 std::string type; |
| 116 if (!message_dict->GetString("type", &type)) { | 116 if (!message_dict->GetString("type", &type)) { |
| 117 OnError("'type' not found"); | 117 OnError("'type' not found"); |
| 118 return; | 118 return; |
| 119 } | 119 } |
| 120 | 120 |
| 121 response->SetString("type", type + "Response"); | 121 response->SetString("type", type + "Response"); |
| 122 | 122 |
| 123 if (type == "hello") { | 123 if (type == "hello") { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 void Me2MeNativeMessagingHost::ProcessHello( | 174 void Me2MeNativeMessagingHost::ProcessHello( |
| 175 std::unique_ptr<base::DictionaryValue> message, | 175 std::unique_ptr<base::DictionaryValue> message, |
| 176 std::unique_ptr<base::DictionaryValue> response) { | 176 std::unique_ptr<base::DictionaryValue> response) { |
| 177 DCHECK(task_runner()->BelongsToCurrentThread()); | 177 DCHECK(task_runner()->BelongsToCurrentThread()); |
| 178 | 178 |
| 179 response->SetString("version", STRINGIZE(VERSION)); | 179 response->SetString("version", STRINGIZE(VERSION)); |
| 180 std::unique_ptr<base::ListValue> supported_features_list( | 180 std::unique_ptr<base::ListValue> supported_features_list( |
| 181 new base::ListValue()); | 181 new base::ListValue()); |
| 182 supported_features_list->AppendStrings(std::vector<std::string>( | 182 supported_features_list->AppendStrings(std::vector<std::string>( |
| 183 kSupportedFeatures, kSupportedFeatures + arraysize(kSupportedFeatures))); | 183 kSupportedFeatures, kSupportedFeatures + arraysize(kSupportedFeatures))); |
| 184 response->Set("supportedFeatures", supported_features_list.release()); | 184 response->Set("supportedFeatures", std::move(supported_features_list)); |
| 185 SendMessageToClient(std::move(response)); | 185 SendMessageToClient(std::move(response)); |
| 186 } | 186 } |
| 187 | 187 |
| 188 void Me2MeNativeMessagingHost::ProcessClearPairedClients( | 188 void Me2MeNativeMessagingHost::ProcessClearPairedClients( |
| 189 std::unique_ptr<base::DictionaryValue> message, | 189 std::unique_ptr<base::DictionaryValue> message, |
| 190 std::unique_ptr<base::DictionaryValue> response) { | 190 std::unique_ptr<base::DictionaryValue> response) { |
| 191 DCHECK(task_runner()->BelongsToCurrentThread()); | 191 DCHECK(task_runner()->BelongsToCurrentThread()); |
| 192 | 192 |
| 193 if (needs_elevation_) { | 193 if (needs_elevation_) { |
| 194 if (!DelegateToElevatedHost(std::move(message))) { | 194 if (!DelegateToElevatedHost(std::move(message))) { |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 &Me2MeNativeMessagingHost::SendCredentialsResponse, weak_ptr_, | 449 &Me2MeNativeMessagingHost::SendCredentialsResponse, weak_ptr_, |
| 450 base::Passed(&response))); | 450 base::Passed(&response))); |
| 451 } | 451 } |
| 452 | 452 |
| 453 void Me2MeNativeMessagingHost::SendConfigResponse( | 453 void Me2MeNativeMessagingHost::SendConfigResponse( |
| 454 std::unique_ptr<base::DictionaryValue> response, | 454 std::unique_ptr<base::DictionaryValue> response, |
| 455 std::unique_ptr<base::DictionaryValue> config) { | 455 std::unique_ptr<base::DictionaryValue> config) { |
| 456 DCHECK(task_runner()->BelongsToCurrentThread()); | 456 DCHECK(task_runner()->BelongsToCurrentThread()); |
| 457 | 457 |
| 458 if (config) { | 458 if (config) { |
| 459 response->Set("config", config.release()); | 459 response->Set("config", std::move(config)); |
| 460 } else { | 460 } else { |
| 461 response->Set("config", base::MakeUnique<base::Value>()); | 461 response->Set("config", base::MakeUnique<base::Value>()); |
| 462 } | 462 } |
| 463 SendMessageToClient(std::move(response)); | 463 SendMessageToClient(std::move(response)); |
| 464 } | 464 } |
| 465 | 465 |
| 466 void Me2MeNativeMessagingHost::SendPairedClientsResponse( | 466 void Me2MeNativeMessagingHost::SendPairedClientsResponse( |
| 467 std::unique_ptr<base::DictionaryValue> response, | 467 std::unique_ptr<base::DictionaryValue> response, |
| 468 std::unique_ptr<base::ListValue> pairings) { | 468 std::unique_ptr<base::ListValue> pairings) { |
| 469 DCHECK(task_runner()->BelongsToCurrentThread()); | 469 DCHECK(task_runner()->BelongsToCurrentThread()); |
| 470 | 470 |
| 471 response->Set("pairedClients", pairings.release()); | 471 response->Set("pairedClients", std::move(pairings)); |
| 472 SendMessageToClient(std::move(response)); | 472 SendMessageToClient(std::move(response)); |
| 473 } | 473 } |
| 474 | 474 |
| 475 void Me2MeNativeMessagingHost::SendUsageStatsConsentResponse( | 475 void Me2MeNativeMessagingHost::SendUsageStatsConsentResponse( |
| 476 std::unique_ptr<base::DictionaryValue> response, | 476 std::unique_ptr<base::DictionaryValue> response, |
| 477 const DaemonController::UsageStatsConsent& consent) { | 477 const DaemonController::UsageStatsConsent& consent) { |
| 478 DCHECK(task_runner()->BelongsToCurrentThread()); | 478 DCHECK(task_runner()->BelongsToCurrentThread()); |
| 479 | 479 |
| 480 response->SetBoolean("supported", consent.supported); | 480 response->SetBoolean("supported", consent.supported); |
| 481 response->SetBoolean("allowed", consent.allowed); | 481 response->SetBoolean("allowed", consent.allowed); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 | 571 |
| 572 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( | 572 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( |
| 573 std::unique_ptr<base::DictionaryValue> message) { | 573 std::unique_ptr<base::DictionaryValue> message) { |
| 574 NOTREACHED(); | 574 NOTREACHED(); |
| 575 return false; | 575 return false; |
| 576 } | 576 } |
| 577 | 577 |
| 578 #endif // !defined(OS_WIN) | 578 #endif // !defined(OS_WIN) |
| 579 | 579 |
| 580 } // namespace remoting | 580 } // namespace remoting |
| OLD | NEW |