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_DEFAULT_PROFILE_H_
18 #define SHILL_DEFAULT_PROFILE_H_
19 
20 #include <random>
21 #include <string>
22 #include <vector>
23 
24 #include <gtest/gtest_prod.h>  // for FRIEND_TEST
25 
26 #include "shill/event_dispatcher.h"
27 #include "shill/manager.h"
28 #include "shill/profile.h"
29 #include "shill/property_store.h"
30 #include "shill/refptr_types.h"
31 
32 namespace shill {
33 
34 class ControlInterface;
35 #if !defined(DISABLE_WIFI)
36 class WiFiProvider;
37 #endif  // DISABLE_WIFI
38 
39 class DefaultProfile : public Profile {
40  public:
41   static const char kDefaultId[];
42 
43   DefaultProfile(ControlInterface* control,
44                  Metrics* metrics,
45                  Manager* manager,
46                  const base::FilePath& storage_directory,
47                  const std::string& profile_id,
48                  const Manager::Properties& manager_props);
49   ~DefaultProfile() override;
50 
51   // Loads global configuration into manager properties.  This should
52   // only be called by the Manager.
53   virtual void LoadManagerProperties(Manager::Properties* manager_props,
54                                      DhcpProperties* dhcp_properties);
55 
56   // Override the Profile superclass implementation to accept all Ethernet
57   // services, since these should have an affinity for the default profile.
58   bool ConfigureService(const ServiceRefPtr& service) override;
59 
60   // Persists profile information, as well as that of discovered devices
61   // and bound services, to disk.
62   // Returns true on success, false on failure.
63   bool Save() override;
64 
65   // Inherited from Profile.
66   bool UpdateDevice(const DeviceRefPtr& device) override;
67 
68 #if !defined(DISABLE_WIFI)
69   // Inherited from Profile.
70   bool UpdateWiFiProvider(const WiFiProvider& wifi_provider) override;
71 #endif  // DISABLE_WIFI
72 
IsDefault()73   bool IsDefault() const override { return true; }
74 
75  private:
76   friend class DefaultProfileTest;
77   FRIEND_TEST(DefaultProfileTest, GetStoragePath);
78   FRIEND_TEST(DefaultProfileTest, LoadManagerDefaultProperties);
79   FRIEND_TEST(DefaultProfileTest, LoadManagerProperties);
80   FRIEND_TEST(DefaultProfileTest, Save);
81 
82   static const char kStorageId[];
83   static const char kStorageArpGateway[];
84   static const char kStorageCheckPortalList[];
85   static const char kStorageConnectionIdSalt[];
86   static const char kStorageHostName[];
87   static const char kStorageIgnoredDNSSearchPaths[];
88   static const char kStorageLinkMonitorTechnologies[];
89   static const char kStorageName[];
90   static const char kStorageNoAutoConnectTechnologies[];
91   static const char kStorageOfflineMode[];
92   static const char kStoragePortalCheckInterval[];
93   static const char kStoragePortalURL[];
94   static const char kStorageProhibitedTechnologies[];
95 
96   const std::string profile_id_;
97   const Manager::Properties& props_;
98   std::default_random_engine random_engine_;
99 
100   DISALLOW_COPY_AND_ASSIGN(DefaultProfile);
101 };
102 
103 }  // namespace shill
104 
105 #endif  // SHILL_DEFAULT_PROFILE_H_
106