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

Side by Side Diff: chromeos/dbus/shill_third_party_vpn_driver_client.cc

Issue 820673004: json_schema_compiler: Use std::vector<char> for binary values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simplify_json_schema
Patch Set: Fix merge error. Created 5 years, 11 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 "chromeos/dbus/shill_third_party_vpn_driver_client.h" 5 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h"
6 6
7 #include <string>
8
9 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h"
10 #include "chromeos/dbus/shill_third_party_vpn_observer.h" 9 #include "chromeos/dbus/shill_third_party_vpn_observer.h"
11 #include "dbus/bus.h" 10 #include "dbus/bus.h"
12 #include "dbus/message.h" 11 #include "dbus/message.h"
13 #include "dbus/object_proxy.h" 12 #include "dbus/object_proxy.h"
14 #include "third_party/cros_system_api/dbus/service_constants.h" 13 #include "third_party/cros_system_api/dbus/service_constants.h"
15 14
16 namespace chromeos { 15 namespace chromeos {
17 16
18 namespace { 17 namespace {
19 18
(...skipping 29 matching lines...) Expand all
49 const ShillClientHelper::ErrorCallback& error_callback) override; 48 const ShillClientHelper::ErrorCallback& error_callback) override;
50 49
51 void UpdateConnectionState( 50 void UpdateConnectionState(
52 const std::string& object_path_value, 51 const std::string& object_path_value,
53 const uint32_t connection_state, 52 const uint32_t connection_state,
54 const base::Closure& callback, 53 const base::Closure& callback,
55 const ShillClientHelper::ErrorCallback& error_callback) override; 54 const ShillClientHelper::ErrorCallback& error_callback) override;
56 55
57 void SendPacket( 56 void SendPacket(
58 const std::string& object_path_value, 57 const std::string& object_path_value,
59 const std::string& ip_packet, 58 const std::vector<char>& ip_packet,
60 const base::Closure& callback, 59 const base::Closure& callback,
61 const ShillClientHelper::ErrorCallback& error_callback) override; 60 const ShillClientHelper::ErrorCallback& error_callback) override;
62 61
63 protected: 62 protected:
64 void Init(dbus::Bus* bus) override { bus_ = bus; } 63 void Init(dbus::Bus* bus) override { bus_ = bus; }
65 64
66 ShillThirdPartyVpnDriverClient::TestInterface* GetTestInterface() override { 65 ShillThirdPartyVpnDriverClient::TestInterface* GetTestInterface() override {
67 return nullptr; 66 return nullptr;
68 } 67 }
69 68
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 dbus::MethodCall method_call(shill::kFlimflamThirdPartyVpnInterface, 237 dbus::MethodCall method_call(shill::kFlimflamThirdPartyVpnInterface,
239 shill::kUpdateConnectionStateFunction); 238 shill::kUpdateConnectionStateFunction);
240 dbus::MessageWriter writer(&method_call); 239 dbus::MessageWriter writer(&method_call);
241 writer.AppendUint32(connection_state); 240 writer.AppendUint32(connection_state);
242 GetHelper(object_path_value) 241 GetHelper(object_path_value)
243 ->CallVoidMethodWithErrorCallback(&method_call, callback, error_callback); 242 ->CallVoidMethodWithErrorCallback(&method_call, callback, error_callback);
244 } 243 }
245 244
246 void ShillThirdPartyVpnDriverClientImpl::SendPacket( 245 void ShillThirdPartyVpnDriverClientImpl::SendPacket(
247 const std::string& object_path_value, 246 const std::string& object_path_value,
248 const std::string& ip_packet, 247 const std::vector<char>& ip_packet,
249 const base::Closure& callback, 248 const base::Closure& callback,
250 const ShillClientHelper::ErrorCallback& error_callback) { 249 const ShillClientHelper::ErrorCallback& error_callback) {
251 dbus::MethodCall method_call(shill::kFlimflamThirdPartyVpnInterface, 250 dbus::MethodCall method_call(shill::kFlimflamThirdPartyVpnInterface,
252 shill::kSendPacketFunction); 251 shill::kSendPacketFunction);
253 dbus::MessageWriter writer(&method_call); 252 dbus::MessageWriter writer(&method_call);
254 writer.AppendArrayOfBytes(reinterpret_cast<const uint8_t*>(ip_packet.data()), 253 static_assert(sizeof(uint8_t) == sizeof(char),
255 ip_packet.size()); 254 "Can't reinterpret ip_packet if char is not 8 bit large.");
255 writer.AppendArrayOfBytes(
256 reinterpret_cast<const uint8_t*>(vector_as_array(&ip_packet)),
257 ip_packet.size());
256 GetHelper(object_path_value) 258 GetHelper(object_path_value)
257 ->CallVoidMethodWithErrorCallback(&method_call, callback, error_callback); 259 ->CallVoidMethodWithErrorCallback(&method_call, callback, error_callback);
258 } 260 }
259 261
260 // static 262 // static
261 void ShillThirdPartyVpnDriverClientImpl::OnPacketReceived( 263 void ShillThirdPartyVpnDriverClientImpl::OnPacketReceived(
262 base::WeakPtr<HelperInfo> helper_info, 264 base::WeakPtr<HelperInfo> helper_info,
263 dbus::Signal* signal) { 265 dbus::Signal* signal) {
264 if (!helper_info || !helper_info->observer()) 266 if (!helper_info || !helper_info->observer())
265 return; 267 return;
266 268
267 dbus::MessageReader reader(signal); 269 dbus::MessageReader reader(signal);
268 const uint8_t* data = nullptr; 270 const uint8_t* data = nullptr;
269 size_t length = 0; 271 size_t length = 0;
270 if (reader.PopArrayOfBytes(&data, &length)) { 272 if (reader.PopArrayOfBytes(&data, &length)) {
271 helper_info->observer()->OnPacketReceived( 273 helper_info->observer()->OnPacketReceived(
272 std::string(reinterpret_cast<const char*>(data), length)); 274 std::vector<char>(data, data + length));
273 } 275 }
274 } 276 }
275 277
276 // static 278 // static
277 void ShillThirdPartyVpnDriverClientImpl::OnPlatformMessage( 279 void ShillThirdPartyVpnDriverClientImpl::OnPlatformMessage(
278 base::WeakPtr<HelperInfo> helper_info, 280 base::WeakPtr<HelperInfo> helper_info,
279 dbus::Signal* signal) { 281 dbus::Signal* signal) {
280 if (!helper_info || !helper_info->observer()) 282 if (!helper_info || !helper_info->observer())
281 return; 283 return;
282 284
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 332
331 ShillThirdPartyVpnDriverClient::~ShillThirdPartyVpnDriverClient() { 333 ShillThirdPartyVpnDriverClient::~ShillThirdPartyVpnDriverClient() {
332 } 334 }
333 335
334 // static 336 // static
335 ShillThirdPartyVpnDriverClient* ShillThirdPartyVpnDriverClient::Create() { 337 ShillThirdPartyVpnDriverClient* ShillThirdPartyVpnDriverClient::Create() {
336 return new ShillThirdPartyVpnDriverClientImpl(); 338 return new ShillThirdPartyVpnDriverClientImpl();
337 } 339 }
338 340
339 } // namespace chromeos 341 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/shill_third_party_vpn_driver_client.h ('k') | chromeos/dbus/shill_third_party_vpn_driver_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698