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

Side by Side Diff: extensions/browser/api/vpn_provider/vpn_service.cc

Issue 1902873002: Convert //extensions/browser/api from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/api/vpn_provider/vpn_service.h" 5 #include "extensions/browser/api/vpn_provider/vpn_service.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 92 }
93 93
94 VpnService::VpnConfiguration::~VpnConfiguration() { 94 VpnService::VpnConfiguration::~VpnConfiguration() {
95 } 95 }
96 96
97 void VpnService::VpnConfiguration::OnPacketReceived( 97 void VpnService::VpnConfiguration::OnPacketReceived(
98 const std::vector<char>& data) { 98 const std::vector<char>& data) {
99 if (!vpn_service_) { 99 if (!vpn_service_) {
100 return; 100 return;
101 } 101 }
102 scoped_ptr<base::ListValue> event_args = 102 std::unique_ptr<base::ListValue> event_args =
103 api_vpn::OnPacketReceived::Create(data); 103 api_vpn::OnPacketReceived::Create(data);
104 vpn_service_->SendSignalToExtension( 104 vpn_service_->SendSignalToExtension(
105 extension_id_, extensions::events::VPN_PROVIDER_ON_PACKET_RECEIVED, 105 extension_id_, extensions::events::VPN_PROVIDER_ON_PACKET_RECEIVED,
106 api_vpn::OnPacketReceived::kEventName, std::move(event_args)); 106 api_vpn::OnPacketReceived::kEventName, std::move(event_args));
107 } 107 }
108 108
109 void VpnService::VpnConfiguration::OnPlatformMessage(uint32_t message) { 109 void VpnService::VpnConfiguration::OnPlatformMessage(uint32_t message) {
110 if (!vpn_service_) { 110 if (!vpn_service_) {
111 return; 111 return;
112 } 112 }
113 DCHECK_GE(api_vpn::PLATFORM_MESSAGE_LAST, message); 113 DCHECK_GE(api_vpn::PLATFORM_MESSAGE_LAST, message);
114 114
115 api_vpn::PlatformMessage platform_message = 115 api_vpn::PlatformMessage platform_message =
116 static_cast<api_vpn::PlatformMessage>(message); 116 static_cast<api_vpn::PlatformMessage>(message);
117 117
118 if (platform_message == api_vpn::PLATFORM_MESSAGE_CONNECTED) { 118 if (platform_message == api_vpn::PLATFORM_MESSAGE_CONNECTED) {
119 vpn_service_->SetActiveConfiguration(this); 119 vpn_service_->SetActiveConfiguration(this);
120 } else if (platform_message == api_vpn::PLATFORM_MESSAGE_DISCONNECTED || 120 } else if (platform_message == api_vpn::PLATFORM_MESSAGE_DISCONNECTED ||
121 platform_message == api_vpn::PLATFORM_MESSAGE_ERROR) { 121 platform_message == api_vpn::PLATFORM_MESSAGE_ERROR) {
122 vpn_service_->SetActiveConfiguration(nullptr); 122 vpn_service_->SetActiveConfiguration(nullptr);
123 } 123 }
124 124
125 // TODO(kaliamoorthi): Update the lower layers to get the error message and 125 // TODO(kaliamoorthi): Update the lower layers to get the error message and
126 // pass in the error instead of std::string(). 126 // pass in the error instead of std::string().
127 scoped_ptr<base::ListValue> event_args = api_vpn::OnPlatformMessage::Create( 127 std::unique_ptr<base::ListValue> event_args =
128 configuration_name_, platform_message, std::string()); 128 api_vpn::OnPlatformMessage::Create(configuration_name_, platform_message,
129 std::string());
129 130
130 vpn_service_->SendSignalToExtension( 131 vpn_service_->SendSignalToExtension(
131 extension_id_, extensions::events::VPN_PROVIDER_ON_PLATFORM_MESSAGE, 132 extension_id_, extensions::events::VPN_PROVIDER_ON_PLATFORM_MESSAGE,
132 api_vpn::OnPlatformMessage::kEventName, std::move(event_args)); 133 api_vpn::OnPlatformMessage::kEventName, std::move(event_args));
133 } 134 }
134 135
135 VpnService::VpnService( 136 VpnService::VpnService(
136 content::BrowserContext* browser_context, 137 content::BrowserContext* browser_context,
137 const std::string& userid_hash, 138 const std::string& userid_hash,
138 extensions::ExtensionRegistry* extension_registry, 139 extensions::ExtensionRegistry* extension_registry,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 219
219 if (service_path_to_configuration_map_.find(service_path) == 220 if (service_path_to_configuration_map_.find(service_path) ==
220 service_path_to_configuration_map_.end()) { 221 service_path_to_configuration_map_.end()) {
221 // Ignore removal of a configuration unknown to VPN service, which means the 222 // Ignore removal of a configuration unknown to VPN service, which means the
222 // configuration was created internally by the platform. 223 // configuration was created internally by the platform.
223 return; 224 return;
224 } 225 }
225 226
226 VpnConfiguration* configuration = 227 VpnConfiguration* configuration =
227 service_path_to_configuration_map_[service_path]; 228 service_path_to_configuration_map_[service_path];
228 scoped_ptr<base::ListValue> event_args = 229 std::unique_ptr<base::ListValue> event_args =
229 api_vpn::OnConfigRemoved::Create(configuration->configuration_name()); 230 api_vpn::OnConfigRemoved::Create(configuration->configuration_name());
230 SendSignalToExtension(configuration->extension_id(), 231 SendSignalToExtension(configuration->extension_id(),
231 extensions::events::VPN_PROVIDER_ON_CONFIG_REMOVED, 232 extensions::events::VPN_PROVIDER_ON_CONFIG_REMOVED,
232 api_vpn::OnConfigRemoved::kEventName, 233 api_vpn::OnConfigRemoved::kEventName,
233 std::move(event_args)); 234 std::move(event_args));
234 235
235 DestroyConfigurationInternal(configuration); 236 DestroyConfigurationInternal(configuration);
236 } 237 }
237 238
238 void VpnService::OnPropertiesSet(const std::string& service_path, 239 void VpnService::OnPropertiesSet(const std::string& service_path,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 VpnConfiguration* configuration = 276 VpnConfiguration* configuration =
276 CreateConfigurationInternal(extension_id, configuration_name, key); 277 CreateConfigurationInternal(extension_id, configuration_name, key);
277 configuration->set_service_path(service_path); 278 configuration->set_service_path(service_path);
278 service_path_to_configuration_map_[service_path] = configuration; 279 service_path_to_configuration_map_[service_path] = configuration;
279 shill_client_->AddShillThirdPartyVpnObserver(configuration->object_path(), 280 shill_client_->AddShillThirdPartyVpnObserver(configuration->object_path(),
280 configuration); 281 configuration);
281 } 282 }
282 283
283 void VpnService::OnGetPropertiesFailure( 284 void VpnService::OnGetPropertiesFailure(
284 const std::string& error_name, 285 const std::string& error_name,
285 scoped_ptr<base::DictionaryValue> error_data) { 286 std::unique_ptr<base::DictionaryValue> error_data) {}
286 }
287 287
288 void VpnService::NetworkListChanged() { 288 void VpnService::NetworkListChanged() {
289 NetworkStateHandler::NetworkStateList network_list; 289 NetworkStateHandler::NetworkStateList network_list;
290 network_state_handler_->GetVisibleNetworkListByType(NetworkTypePattern::VPN(), 290 network_state_handler_->GetVisibleNetworkListByType(NetworkTypePattern::VPN(),
291 &network_list); 291 &network_list);
292 for (auto& iter : network_list) { 292 for (auto& iter : network_list) {
293 if (service_path_to_configuration_map_.find(iter->path()) != 293 if (service_path_to_configuration_map_.find(iter->path()) !=
294 service_path_to_configuration_map_.end()) { 294 service_path_to_configuration_map_.end()) {
295 continue; 295 continue;
296 } 296 }
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 service_path_to_configuration_map_[service_path] = configuration; 505 service_path_to_configuration_map_[service_path] = configuration;
506 shill_client_->AddShillThirdPartyVpnObserver(configuration->object_path(), 506 shill_client_->AddShillThirdPartyVpnObserver(configuration->object_path(),
507 configuration); 507 configuration);
508 callback.Run(); 508 callback.Run();
509 } 509 }
510 510
511 void VpnService::OnCreateConfigurationFailure( 511 void VpnService::OnCreateConfigurationFailure(
512 const VpnService::FailureCallback& callback, 512 const VpnService::FailureCallback& callback,
513 VpnConfiguration* configuration, 513 VpnConfiguration* configuration,
514 const std::string& error_name, 514 const std::string& error_name,
515 scoped_ptr<base::DictionaryValue> error_data) { 515 std::unique_ptr<base::DictionaryValue> error_data) {
516 DestroyConfigurationInternal(configuration); 516 DestroyConfigurationInternal(configuration);
517 callback.Run(error_name, std::string()); 517 callback.Run(error_name, std::string());
518 } 518 }
519 519
520 void VpnService::OnRemoveConfigurationSuccess( 520 void VpnService::OnRemoveConfigurationSuccess(
521 const VpnService::SuccessCallback& callback) { 521 const VpnService::SuccessCallback& callback) {
522 callback.Run(); 522 callback.Run();
523 } 523 }
524 524
525 void VpnService::OnRemoveConfigurationFailure( 525 void VpnService::OnRemoveConfigurationFailure(
526 const VpnService::FailureCallback& callback, 526 const VpnService::FailureCallback& callback,
527 const std::string& error_name, 527 const std::string& error_name,
528 scoped_ptr<base::DictionaryValue> error_data) { 528 std::unique_ptr<base::DictionaryValue> error_data) {
529 callback.Run(error_name, std::string()); 529 callback.Run(error_name, std::string());
530 } 530 }
531 531
532 void VpnService::SendSignalToExtension( 532 void VpnService::SendSignalToExtension(
533 const std::string& extension_id, 533 const std::string& extension_id,
534 extensions::events::HistogramValue histogram_value, 534 extensions::events::HistogramValue histogram_value,
535 const std::string& event_name, 535 const std::string& event_name,
536 scoped_ptr<base::ListValue> event_args) { 536 std::unique_ptr<base::ListValue> event_args) {
537 scoped_ptr<extensions::Event> event(new extensions::Event( 537 std::unique_ptr<extensions::Event> event(new extensions::Event(
538 histogram_value, event_name, std::move(event_args), browser_context_)); 538 histogram_value, event_name, std::move(event_args), browser_context_));
539 539
540 event_router_->DispatchEventToExtension(extension_id, std::move(event)); 540 event_router_->DispatchEventToExtension(extension_id, std::move(event));
541 } 541 }
542 542
543 void VpnService::SetActiveConfiguration( 543 void VpnService::SetActiveConfiguration(
544 VpnService::VpnConfiguration* configuration) { 544 VpnService::VpnConfiguration* configuration) {
545 active_configuration_ = configuration; 545 active_configuration_ = configuration;
546 } 546 }
547 547
(...skipping 21 matching lines...) Expand all
569 delete configuration; 569 delete configuration;
570 } 570 }
571 571
572 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( 572 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized(
573 const std::string& extension_id) { 573 const std::string& extension_id) {
574 return active_configuration_ && 574 return active_configuration_ &&
575 active_configuration_->extension_id() == extension_id; 575 active_configuration_->extension_id() == extension_id;
576 } 576 }
577 577
578 } // namespace chromeos 578 } // namespace chromeos
OLDNEW
« no previous file with comments | « extensions/browser/api/vpn_provider/vpn_service.h ('k') | extensions/browser/api/web_request/form_data_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698