OLD | NEW |
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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 const std::string& extension_id() const { return extension_id_; } | 64 const std::string& extension_id() const { return extension_id_; } |
65 const std::string& configuration_name() const { return configuration_name_; } | 65 const std::string& configuration_name() const { return configuration_name_; } |
66 const std::string& key() const { return key_; } | 66 const std::string& key() const { return key_; } |
67 const std::string& service_path() const { return service_path_; } | 67 const std::string& service_path() const { return service_path_; } |
68 void set_service_path(const std::string& service_path) { | 68 void set_service_path(const std::string& service_path) { |
69 service_path_ = service_path; | 69 service_path_ = service_path; |
70 } | 70 } |
71 const std::string& object_path() const { return object_path_; } | 71 const std::string& object_path() const { return object_path_; } |
72 | 72 |
73 // ShillThirdPartyVpnObserver: | 73 // ShillThirdPartyVpnObserver: |
74 void OnPacketReceived(const std::string& data) override; | 74 void OnPacketReceived(const std::vector<char>& data) override; |
75 void OnPlatformMessage(uint32_t message) override; | 75 void OnPlatformMessage(uint32_t message) override; |
76 | 76 |
77 private: | 77 private: |
78 const std::string extension_id_; | 78 const std::string extension_id_; |
79 const std::string configuration_name_; | 79 const std::string configuration_name_; |
80 const std::string key_; | 80 const std::string key_; |
81 const std::string object_path_; | 81 const std::string object_path_; |
82 | 82 |
83 std::string service_path_; | 83 std::string service_path_; |
84 | 84 |
(...skipping 10 matching lines...) Expand all Loading... |
95 : extension_id_(extension_id), | 95 : extension_id_(extension_id), |
96 configuration_name_(configuration_name), | 96 configuration_name_(configuration_name), |
97 key_(key), | 97 key_(key), |
98 object_path_(shill::kObjectPathBase + key_), | 98 object_path_(shill::kObjectPathBase + key_), |
99 vpn_service_(vpn_service) { | 99 vpn_service_(vpn_service) { |
100 } | 100 } |
101 | 101 |
102 VpnService::VpnConfiguration::~VpnConfiguration() { | 102 VpnService::VpnConfiguration::~VpnConfiguration() { |
103 } | 103 } |
104 | 104 |
105 void VpnService::VpnConfiguration::OnPacketReceived(const std::string& data) { | 105 void VpnService::VpnConfiguration::OnPacketReceived( |
| 106 const std::vector<char>& data) { |
106 if (!vpn_service_) { | 107 if (!vpn_service_) { |
107 return; | 108 return; |
108 } | 109 } |
109 scoped_ptr<base::ListValue> event_args = | 110 scoped_ptr<base::ListValue> event_args = |
110 api_vpn::OnPacketReceived::Create(data); | 111 api_vpn::OnPacketReceived::Create(data); |
111 vpn_service_->SendSignalToExtension( | 112 vpn_service_->SendSignalToExtension( |
112 extension_id_, api_vpn::OnPacketReceived::kEventName, event_args.Pass()); | 113 extension_id_, api_vpn::OnPacketReceived::kEventName, event_args.Pass()); |
113 } | 114 } |
114 | 115 |
115 void VpnService::VpnConfiguration::OnPlatformMessage(uint32_t message) { | 116 void VpnService::VpnConfiguration::OnPlatformMessage(uint32_t message) { |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 if (!DoesActiveConfigurationExistAndIsAccessAuthorized(extension_id)) { | 353 if (!DoesActiveConfigurationExistAndIsAccessAuthorized(extension_id)) { |
353 failure.Run(std::string(), std::string("Unauthorized access.")); | 354 failure.Run(std::string(), std::string("Unauthorized access.")); |
354 return; | 355 return; |
355 } | 356 } |
356 | 357 |
357 shill_client_->SetParameters(active_configuration_->object_path(), parameters, | 358 shill_client_->SetParameters(active_configuration_->object_path(), parameters, |
358 success, failure); | 359 success, failure); |
359 } | 360 } |
360 | 361 |
361 void VpnService::SendPacket(const std::string& extension_id, | 362 void VpnService::SendPacket(const std::string& extension_id, |
362 const std::string& data, | 363 const std::vector<char>& data, |
363 const SuccessCallback& success, | 364 const SuccessCallback& success, |
364 const FailureCallback& failure) { | 365 const FailureCallback& failure) { |
365 if (!DoesActiveConfigurationExistAndIsAccessAuthorized(extension_id)) { | 366 if (!DoesActiveConfigurationExistAndIsAccessAuthorized(extension_id)) { |
366 failure.Run(std::string(), std::string("Unauthorized access.")); | 367 failure.Run(std::string(), std::string("Unauthorized access.")); |
367 return; | 368 return; |
368 } | 369 } |
369 | 370 |
370 if (data.empty()) { | 371 if (data.empty()) { |
371 failure.Run(std::string(), std::string("Can't send an empty packet.")); | 372 failure.Run(std::string(), std::string("Can't send an empty packet.")); |
372 return; | 373 return; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 delete configuration; | 485 delete configuration; |
485 } | 486 } |
486 | 487 |
487 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( | 488 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( |
488 const std::string& extension_id) { | 489 const std::string& extension_id) { |
489 return active_configuration_ && | 490 return active_configuration_ && |
490 active_configuration_->extension_id() == extension_id; | 491 active_configuration_->extension_id() == extension_id; |
491 } | 492 } |
492 | 493 |
493 } // namespace chromeos | 494 } // namespace chromeos |
OLD | NEW |