blob: 76af372886071554ce397a0b0d945bb6cd3bec8b [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
5#ifndef SHILL_VPN_SERVICE_
6#define SHILL_VPN_SERVICE_
7
8#include <base/memory/scoped_ptr.h>
9#include <gtest/gtest_prod.h> // for FRIEND_TEST
10
Darin Petkov5eb05422012-05-11 15:45:25 +020011#include "shill/connection.h"
Darin Petkov33af05c2012-02-28 10:10:30 +010012#include "shill/service.h"
13
14namespace shill {
15
Darin Petkov02867712012-03-12 14:25:05 +010016class KeyValueStore;
Darin Petkov33af05c2012-02-28 10:10:30 +010017class VPNDriver;
18
19class VPNService : public Service {
20 public:
Darin Petkov79d74c92012-03-07 17:20:32 +010021 VPNService(ControlInterface *control,
Darin Petkov33af05c2012-02-28 10:10:30 +010022 EventDispatcher *dispatcher,
23 Metrics *metrics,
24 Manager *manager,
25 VPNDriver *driver); // Takes ownership of |driver|.
26 virtual ~VPNService();
27
28 // Inherited from Service.
mukesh agrawaldc7b8442012-09-27 13:48:14 -070029 virtual void Connect(Error *error, const char *reason);
Darin Petkov6aa21872012-03-09 16:10:19 +010030 virtual void Disconnect(Error *error);
Darin Petkov33af05c2012-02-28 10:10:30 +010031 virtual std::string GetStorageIdentifier() const;
Darin Petkovf3c71d72012-03-21 12:32:15 +010032 virtual bool Load(StoreInterface *storage);
33 virtual bool Save(StoreInterface *storage);
Paul Stewart65512e12012-03-26 18:01:08 -070034 virtual bool Unload();
Darin Petkov1d0080a2012-04-30 17:10:36 +020035 virtual void MakeFavorite();
Darin Petkov5eb05422012-05-11 15:45:25 +020036 virtual void SetConnection(const ConnectionRefPtr &connection);
mukesh agrawalbebf1b82013-04-23 15:06:33 -070037 virtual bool SetNameProperty(const std::string &name, Error *error);
Darin Petkov6aa21872012-03-09 16:10:19 +010038
Paul Stewartebd38562012-03-23 13:06:40 -070039 virtual void InitDriverPropertyStore();
40
Darin Petkov6aa21872012-03-09 16:10:19 +010041 VPNDriver *driver() const { return driver_.get(); }
Darin Petkov33af05c2012-02-28 10:10:30 +010042
Darin Petkov02867712012-03-12 14:25:05 +010043 static std::string CreateStorageIdentifier(const KeyValueStore &args,
44 Error *error);
45 void set_storage_id(const std::string &id) { storage_id_ = id; }
46
Darin Petkov79349f02013-01-24 16:18:26 +010047 protected:
48 // Inherited from Service.
49 virtual bool IsAutoConnectable(const char **reason) const;
50
Darin Petkov33af05c2012-02-28 10:10:30 +010051 private:
Darin Petkov4cbff5b2013-01-29 16:29:05 +010052 friend class VPNServiceTest;
Darin Petkov33af05c2012-02-28 10:10:30 +010053 FRIEND_TEST(VPNServiceTest, GetDeviceRpcId);
Darin Petkov5eb05422012-05-11 15:45:25 +020054 FRIEND_TEST(VPNServiceTest, SetConnection);
Alex Deymofddc09a2013-07-03 18:41:31 -070055 FRIEND_TEST(VPNServiceTest, GetPhysicalTechologyPropertyFailsIfNoCarrier);
56 FRIEND_TEST(VPNServiceTest, GetPhysicalTechologyPropertyOverWifi);
Darin Petkov33af05c2012-02-28 10:10:30 +010057
Darin Petkov79349f02013-01-24 16:18:26 +010058 static const char kAutoConnNeverConnected[];
Darin Petkov4cbff5b2013-01-29 16:29:05 +010059 static const char kAutoConnVPNAlreadyActive[];
Darin Petkov79349f02013-01-24 16:18:26 +010060
Darin Petkov33af05c2012-02-28 10:10:30 +010061 virtual std::string GetDeviceRpcId(Error *error);
62
Alex Deymofddc09a2013-07-03 18:41:31 -070063 // Returns the Type name of the lowest connection (presumably the "physical"
64 // connection) that this service depends on.
65 std::string GetPhysicalTechologyProperty(Error *error);
66
Darin Petkov02867712012-03-12 14:25:05 +010067 std::string storage_id_;
Darin Petkov33af05c2012-02-28 10:10:30 +010068 scoped_ptr<VPNDriver> driver_;
Darin Petkov5eb05422012-05-11 15:45:25 +020069 scoped_ptr<Connection::Binder> connection_binder_;
Darin Petkov33af05c2012-02-28 10:10:30 +010070
Paul Stewart22807992012-04-11 08:48:31 -070071 // Provided only for compatibility. crosbug.com/29286
72 std::string vpn_domain_;
73
Darin Petkov33af05c2012-02-28 10:10:30 +010074 DISALLOW_COPY_AND_ASSIGN(VPNService);
75};
76
77} // namespace shill
78
79#endif // SHILL_VPN_SERVICE_