blob: 02c087055c91db7259e084cb90f533f722867f8f [file] [log] [blame]
Darin Petkov33af05c2012-02-28 10:10:30 +01001// Copyright (c) 2012 The Chromium OS 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
Ben Chanc45688b2014-07-02 23:50:45 -07005#ifndef SHILL_VPN_SERVICE_H_
6#define SHILL_VPN_SERVICE_H_
Darin Petkov33af05c2012-02-28 10:10:30 +01007
Alex Vakulenko8a532292014-06-16 17:18:44 -07008#include <string>
9
Darin Petkov33af05c2012-02-28 10:10:30 +010010#include <base/memory/scoped_ptr.h>
11#include <gtest/gtest_prod.h> // for FRIEND_TEST
12
Darin Petkov5eb05422012-05-11 15:45:25 +020013#include "shill/connection.h"
Darin Petkov33af05c2012-02-28 10:10:30 +010014#include "shill/service.h"
15
16namespace shill {
17
Darin Petkov02867712012-03-12 14:25:05 +010018class KeyValueStore;
Darin Petkov33af05c2012-02-28 10:10:30 +010019class VPNDriver;
20
21class VPNService : public Service {
22 public:
Darin Petkov79d74c92012-03-07 17:20:32 +010023 VPNService(ControlInterface *control,
Darin Petkov33af05c2012-02-28 10:10:30 +010024 EventDispatcher *dispatcher,
25 Metrics *metrics,
26 Manager *manager,
27 VPNDriver *driver); // Takes ownership of |driver|.
Ben Chan5ea763b2014-08-13 11:07:54 -070028 ~VPNService() override;
Darin Petkov33af05c2012-02-28 10:10:30 +010029
30 // Inherited from Service.
mukesh agrawaldc7b8442012-09-27 13:48:14 -070031 virtual void Connect(Error *error, const char *reason);
Samuel Tan0d061192014-07-07 15:45:15 -070032 virtual void Disconnect(Error *error, const char *reason);
Darin Petkov33af05c2012-02-28 10:10:30 +010033 virtual std::string GetStorageIdentifier() const;
Darin Petkovf3c71d72012-03-21 12:32:15 +010034 virtual bool Load(StoreInterface *storage);
35 virtual bool Save(StoreInterface *storage);
Paul Stewart65512e12012-03-26 18:01:08 -070036 virtual bool Unload();
Paul Stewart2da34c02013-10-17 15:28:56 -070037 virtual void EnableAndRetainAutoConnect();
Darin Petkov5eb05422012-05-11 15:45:25 +020038 virtual void SetConnection(const ConnectionRefPtr &connection);
mukesh agrawalbebf1b82013-04-23 15:06:33 -070039 virtual bool SetNameProperty(const std::string &name, Error *error);
Darin Petkov6aa21872012-03-09 16:10:19 +010040
Paul Stewartebd38562012-03-23 13:06:40 -070041 virtual void InitDriverPropertyStore();
42
Darin Petkov6aa21872012-03-09 16:10:19 +010043 VPNDriver *driver() const { return driver_.get(); }
Darin Petkov33af05c2012-02-28 10:10:30 +010044
Darin Petkov02867712012-03-12 14:25:05 +010045 static std::string CreateStorageIdentifier(const KeyValueStore &args,
46 Error *error);
47 void set_storage_id(const std::string &id) { storage_id_ = id; }
48
Darin Petkov79349f02013-01-24 16:18:26 +010049 protected:
50 // Inherited from Service.
Alex Vakulenko016fa0e2014-08-11 15:59:58 -070051 bool IsAutoConnectable(const char **reason) const override;
52 std::string GetTethering(Error *error) const override;
Darin Petkov79349f02013-01-24 16:18:26 +010053
Darin Petkov33af05c2012-02-28 10:10:30 +010054 private:
Darin Petkov4cbff5b2013-01-29 16:29:05 +010055 friend class VPNServiceTest;
Darin Petkov33af05c2012-02-28 10:10:30 +010056 FRIEND_TEST(VPNServiceTest, GetDeviceRpcId);
Darin Petkov5eb05422012-05-11 15:45:25 +020057 FRIEND_TEST(VPNServiceTest, SetConnection);
Alex Deymofddc09a2013-07-03 18:41:31 -070058 FRIEND_TEST(VPNServiceTest, GetPhysicalTechologyPropertyFailsIfNoCarrier);
59 FRIEND_TEST(VPNServiceTest, GetPhysicalTechologyPropertyOverWifi);
Paul Stewart7f5d9c02013-12-03 18:26:00 -080060 FRIEND_TEST(VPNServiceTest, GetTethering);
Darin Petkov33af05c2012-02-28 10:10:30 +010061
Darin Petkov79349f02013-01-24 16:18:26 +010062 static const char kAutoConnNeverConnected[];
Darin Petkov4cbff5b2013-01-29 16:29:05 +010063 static const char kAutoConnVPNAlreadyActive[];
Darin Petkov79349f02013-01-24 16:18:26 +010064
Paul Stewart1cf7eb82013-12-03 19:34:36 -080065 virtual std::string GetDeviceRpcId(Error *error) const;
Darin Petkov33af05c2012-02-28 10:10:30 +010066
Alex Deymofddc09a2013-07-03 18:41:31 -070067 // Returns the Type name of the lowest connection (presumably the "physical"
68 // connection) that this service depends on.
69 std::string GetPhysicalTechologyProperty(Error *error);
70
Darin Petkov02867712012-03-12 14:25:05 +010071 std::string storage_id_;
Darin Petkov33af05c2012-02-28 10:10:30 +010072 scoped_ptr<VPNDriver> driver_;
Darin Petkov5eb05422012-05-11 15:45:25 +020073 scoped_ptr<Connection::Binder> connection_binder_;
Darin Petkov33af05c2012-02-28 10:10:30 +010074
Paul Stewartee6b3d72013-07-12 16:07:51 -070075 // Provided only for compatibility. crbug.com/211858
Paul Stewart22807992012-04-11 08:48:31 -070076 std::string vpn_domain_;
77
Darin Petkov33af05c2012-02-28 10:10:30 +010078 DISALLOW_COPY_AND_ASSIGN(VPNService);
79};
80
81} // namespace shill
82
Ben Chanc45688b2014-07-02 23:50:45 -070083#endif // SHILL_VPN_SERVICE_H_