1 // 2 // Copyright (C) 2012 The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #ifndef SHILL_VPN_VPN_SERVICE_H_ 18 #define SHILL_VPN_VPN_SERVICE_H_ 19 20 #include <memory> 21 #include <string> 22 23 #include <gtest/gtest_prod.h> // for FRIEND_TEST 24 25 #include "shill/connection.h" 26 #include "shill/service.h" 27 28 namespace shill { 29 30 class KeyValueStore; 31 class VPNDriver; 32 33 class VPNService : public Service { 34 public: 35 VPNService(ControlInterface* control, 36 EventDispatcher* dispatcher, 37 Metrics* metrics, 38 Manager* manager, 39 VPNDriver* driver); // Takes ownership of |driver|. 40 ~VPNService() override; 41 42 // Inherited from Service. 43 void Connect(Error* error, const char* reason) override; 44 void Disconnect(Error* error, const char* reason) override; 45 std::string GetStorageIdentifier() const override; 46 bool Load(StoreInterface* storage) override; 47 bool Save(StoreInterface* storage) override; 48 bool Unload() override; 49 void EnableAndRetainAutoConnect() override; 50 void SetConnection(const ConnectionRefPtr& connection) override; 51 bool SetNameProperty(const std::string& name, Error* error) override; 52 53 virtual void InitDriverPropertyStore(); 54 driver()55 VPNDriver* driver() const { return driver_.get(); } 56 57 static std::string CreateStorageIdentifier(const KeyValueStore& args, 58 Error* error); set_storage_id(const std::string & id)59 void set_storage_id(const std::string& id) { storage_id_ = id; } 60 61 protected: 62 // Inherited from Service. 63 bool IsAutoConnectable(const char** reason) const override; 64 std::string GetTethering(Error* error) const override; 65 66 private: 67 friend class VPNServiceTest; 68 FRIEND_TEST(VPNServiceTest, GetDeviceRpcId); 69 FRIEND_TEST(VPNServiceTest, SetConnection); 70 FRIEND_TEST(VPNServiceTest, GetPhysicalTechnologyPropertyFailsIfNoCarrier); 71 FRIEND_TEST(VPNServiceTest, GetPhysicalTechnologyPropertyOverWifi); 72 FRIEND_TEST(VPNServiceTest, GetTethering); 73 74 static const char kAutoConnNeverConnected[]; 75 static const char kAutoConnVPNAlreadyActive[]; 76 77 std::string GetDeviceRpcId(Error* error) const override; 78 79 // Returns the Type name of the lowest connection (presumably the "physical" 80 // connection) that this service depends on. 81 std::string GetPhysicalTechnologyProperty(Error* error); 82 83 std::string storage_id_; 84 std::unique_ptr<VPNDriver> driver_; 85 std::unique_ptr<Connection::Binder> connection_binder_; 86 87 // Provided only for compatibility. crbug.com/211858 88 std::string vpn_domain_; 89 90 DISALLOW_COPY_AND_ASSIGN(VPNService); 91 }; 92 93 } // namespace shill 94 95 #endif // SHILL_VPN_VPN_SERVICE_H_ 96