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
3 // found in the LICENSE file.
4 
5 #include "chromeos/dbus/shill/fake_shill_third_party_vpn_driver_client.h"
6 
7 #include <stdint.h>
8 
9 #include "base/bind.h"
10 #include "base/location.h"
11 #include "base/logging.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/threading/thread_task_runner_handle.h"
14 #include "chromeos/dbus/shill/shill_third_party_vpn_observer.h"
15 #include "dbus/object_proxy.h"
16 
17 namespace chromeos {
18 
19 FakeShillThirdPartyVpnDriverClient::FakeShillThirdPartyVpnDriverClient() =
20     default;
21 
22 FakeShillThirdPartyVpnDriverClient::~FakeShillThirdPartyVpnDriverClient() =
23     default;
24 
AddShillThirdPartyVpnObserver(const std::string & object_path_value,ShillThirdPartyVpnObserver * observer)25 void FakeShillThirdPartyVpnDriverClient::AddShillThirdPartyVpnObserver(
26     const std::string& object_path_value,
27     ShillThirdPartyVpnObserver* observer) {
28   if (observer_map_.find(object_path_value) != observer_map_.end()) {
29     VLOG(2) << "Observer exists.";
30     return;
31   }
32   observer_map_[object_path_value] = observer;
33 }
34 
RemoveShillThirdPartyVpnObserver(const std::string & object_path_value)35 void FakeShillThirdPartyVpnDriverClient::RemoveShillThirdPartyVpnObserver(
36     const std::string& object_path_value) {
37   if (observer_map_.find(object_path_value) == observer_map_.end()) {
38     VLOG(2) << "Observer does not exist.";
39     return;
40   }
41   observer_map_.erase(object_path_value);
42 }
43 
SetParameters(const std::string & object_path_value,const base::Value & parameters,StringCallback callback,ErrorCallback error_callback)44 void FakeShillThirdPartyVpnDriverClient::SetParameters(
45     const std::string& object_path_value,
46     const base::Value& parameters,
47     StringCallback callback,
48     ErrorCallback error_callback) {
49   base::ThreadTaskRunnerHandle::Get()->PostTask(
50       FROM_HERE, base::BindOnce(std::move(callback), std::string()));
51 }
52 
UpdateConnectionState(const std::string & object_path_value,const uint32_t connection_state,base::OnceClosure callback,ErrorCallback error_callback)53 void FakeShillThirdPartyVpnDriverClient::UpdateConnectionState(
54     const std::string& object_path_value,
55     const uint32_t connection_state,
56     base::OnceClosure callback,
57     ErrorCallback error_callback) {
58   base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, std::move(callback));
59 }
60 
SendPacket(const std::string & object_path_value,const std::vector<char> & ip_packet,base::OnceClosure callback,ErrorCallback error_callback)61 void FakeShillThirdPartyVpnDriverClient::SendPacket(
62     const std::string& object_path_value,
63     const std::vector<char>& ip_packet,
64     base::OnceClosure callback,
65     ErrorCallback error_callback) {
66   base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, std::move(callback));
67 }
68 
OnPacketReceived(const std::string & object_path_value,const std::vector<char> & packet)69 void FakeShillThirdPartyVpnDriverClient::OnPacketReceived(
70     const std::string& object_path_value,
71     const std::vector<char>& packet) {
72   ObserverMap::iterator it = observer_map_.find(object_path_value);
73   if (it == observer_map_.end()) {
74     LOG(ERROR) << "Unexpected OnPacketReceived for " << object_path_value;
75     return;
76   }
77 
78   it->second->OnPacketReceived(packet);
79 }
80 
OnPlatformMessage(const std::string & object_path_value,uint32_t message)81 void FakeShillThirdPartyVpnDriverClient::OnPlatformMessage(
82     const std::string& object_path_value,
83     uint32_t message) {
84   ObserverMap::iterator it = observer_map_.find(object_path_value);
85   if (it == observer_map_.end()) {
86     LOG(ERROR) << "Unexpected OnPlatformMessage for " << object_path_value;
87     return;
88   }
89 
90   it->second->OnPlatformMessage(message);
91 }
92 
93 ShillThirdPartyVpnDriverClient::TestInterface*
GetTestInterface()94 FakeShillThirdPartyVpnDriverClient::GetTestInterface() {
95   return this;
96 }
97 
98 }  // namespace chromeos
99