OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_POLICY_CORE_BROWSER_BROWSER_POLICY_CONNECTOR_H_ | 5 #ifndef COMPONENTS_POLICY_CORE_BROWSER_BROWSER_POLICY_CONNECTOR_H_ |
6 #define COMPONENTS_POLICY_CORE_BROWSER_BROWSER_POLICY_CONNECTOR_H_ | 6 #define COMPONENTS_POLICY_CORE_BROWSER_BROWSER_POLICY_CONNECTOR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 class DeviceManagementService; | 29 class DeviceManagementService; |
30 class PolicyService; | 30 class PolicyService; |
31 class PolicyStatisticsCollector; | 31 class PolicyStatisticsCollector; |
32 | 32 |
33 // The BrowserPolicyConnector keeps the browser-global (non Profile-specific) | 33 // The BrowserPolicyConnector keeps the browser-global (non Profile-specific) |
34 // policy providers, and some shared components of the policy system. | 34 // policy providers, and some shared components of the policy system. |
35 // This is a basic implementation that gets extended by platform-specific | 35 // This is a basic implementation that gets extended by platform-specific |
36 // subclasses. | 36 // subclasses. |
37 class POLICY_EXPORT BrowserPolicyConnector { | 37 class POLICY_EXPORT BrowserPolicyConnector { |
38 public: | 38 public: |
| 39 enum ManagementMode { |
| 40 NOT_MANAGED, |
| 41 ENTERPRISE_MANAGED, |
| 42 CONSUMER_MANAGED |
| 43 }; |
| 44 |
39 // Invoke Shutdown() before deleting, see below. | 45 // Invoke Shutdown() before deleting, see below. |
40 virtual ~BrowserPolicyConnector(); | 46 virtual ~BrowserPolicyConnector(); |
41 | 47 |
42 // Finalizes the initialization of the connector. This call can be skipped on | 48 // Finalizes the initialization of the connector. This call can be skipped on |
43 // tests that don't require the full policy system running. | 49 // tests that don't require the full policy system running. |
44 virtual void Init( | 50 virtual void Init( |
45 PrefService* local_state, | 51 PrefService* local_state, |
46 scoped_refptr<net::URLRequestContextGetter> request_context) = 0; | 52 scoped_refptr<net::URLRequestContextGetter> request_context) = 0; |
47 | 53 |
48 // Stops the policy providers and cleans up the connector before it can be | 54 // Stops the policy providers and cleans up the connector before it can be |
(...skipping 19 matching lines...) Expand all Loading... |
68 | 74 |
69 // Returns the platform-specific policy provider, if there is one. | 75 // Returns the platform-specific policy provider, if there is one. |
70 ConfigurationPolicyProvider* GetPlatformProvider(); | 76 ConfigurationPolicyProvider* GetPlatformProvider(); |
71 | 77 |
72 // Schedules initialization of the cloud policy backend services, if the | 78 // Schedules initialization of the cloud policy backend services, if the |
73 // services are already constructed. | 79 // services are already constructed. |
74 void ScheduleServiceInitialization(int64 delay_milliseconds); | 80 void ScheduleServiceInitialization(int64 delay_milliseconds); |
75 | 81 |
76 const ConfigurationPolicyHandlerList* GetHandlerList() const; | 82 const ConfigurationPolicyHandlerList* GetHandlerList() const; |
77 | 83 |
| 84 // TODO(davidyu): migrate all callers to use GetDeviceManagementService() |
| 85 // instead. http://crbug.com/366085. |
78 DeviceManagementService* device_management_service() { | 86 DeviceManagementService* device_management_service() { |
79 return device_management_service_.get(); | 87 return GetDeviceManagementService(ENTERPRISE_MANAGED); |
80 } | 88 } |
81 | 89 |
| 90 // Returns the device management service based on the management mode. |
| 91 // |management_mode| must not be NOT_MANAGED. |
| 92 DeviceManagementService* GetDeviceManagementService( |
| 93 ManagementMode management_mode); |
| 94 |
82 // Sets a |provider| that will be included in PolicyServices returned by | 95 // Sets a |provider| that will be included in PolicyServices returned by |
83 // GetPolicyService. This is a static method because local state is | 96 // GetPolicyService. This is a static method because local state is |
84 // created immediately after the connector, and tests don't have a chance to | 97 // created immediately after the connector, and tests don't have a chance to |
85 // inject the provider otherwise. |provider| must outlive the connector, and | 98 // inject the provider otherwise. |provider| must outlive the connector, and |
86 // its ownership is not taken though the connector will initialize and shut it | 99 // its ownership is not taken though the connector will initialize and shut it |
87 // down. | 100 // down. |
88 static void SetPolicyProviderForTesting( | 101 static void SetPolicyProviderForTesting( |
89 ConfigurationPolicyProvider* provider); | 102 ConfigurationPolicyProvider* provider); |
90 | 103 |
91 // Check whether a user is known to be non-enterprise. Domains such as | 104 // Check whether a user is known to be non-enterprise. Domains such as |
92 // gmail.com and googlemail.com are known to not be managed. Also returns | 105 // gmail.com and googlemail.com are known to not be managed. Also returns |
93 // false if the username is empty. | 106 // false if the username is empty. |
94 static bool IsNonEnterpriseUser(const std::string& username); | 107 static bool IsNonEnterpriseUser(const std::string& username); |
95 | 108 |
96 // Returns the URL for the device management service endpoint. | 109 // Returns the URL for the device management service endpoint. |
97 static std::string GetDeviceManagementUrl(); | 110 // |management_mode| must not be NOT_MANAGED. |
| 111 static std::string GetDeviceManagementUrl(ManagementMode management_mode); |
98 | 112 |
99 // Registers refresh rate prefs. | 113 // Registers refresh rate prefs. |
100 static void RegisterPrefs(PrefRegistrySimple* registry); | 114 static void RegisterPrefs(PrefRegistrySimple* registry); |
101 | 115 |
102 protected: | 116 protected: |
103 // Builds an uninitialized BrowserPolicyConnector. | 117 // Builds an uninitialized BrowserPolicyConnector. |
104 // Init() should be called to create and start the policy components. | 118 // Init() should be called to create and start the policy components. |
105 explicit BrowserPolicyConnector( | 119 explicit BrowserPolicyConnector( |
106 const HandlerListFactory& handler_list_factory); | 120 const HandlerListFactory& handler_list_factory); |
107 | 121 |
108 // Helper for the public Init() that must be called by subclasses. | 122 // Helper for the public Init() that must be called by subclasses. |
109 void Init(PrefService* local_state, | 123 void Init(PrefService* local_state, |
110 scoped_refptr<net::URLRequestContextGetter> request_context, | 124 scoped_refptr<net::URLRequestContextGetter> request_context, |
111 scoped_ptr<DeviceManagementService> device_management_service); | 125 scoped_ptr<DeviceManagementService> |
| 126 enterprise_device_management_services, |
| 127 scoped_ptr<DeviceManagementService> |
| 128 consumer_device_management_services); |
112 | 129 |
113 // Adds |provider| to the list of |policy_providers_|. Providers should | 130 // Adds |provider| to the list of |policy_providers_|. Providers should |
114 // be added in decreasing order of priority. | 131 // be added in decreasing order of priority. |
115 void AddPolicyProvider(scoped_ptr<ConfigurationPolicyProvider> provider); | 132 void AddPolicyProvider(scoped_ptr<ConfigurationPolicyProvider> provider); |
116 | 133 |
117 // Same as AddPolicyProvider(), but |provider| becomes the platform provider | 134 // Same as AddPolicyProvider(), but |provider| becomes the platform provider |
118 // which can be retrieved by GetPlatformProvider(). This can be called at | 135 // which can be retrieved by GetPlatformProvider(). This can be called at |
119 // most once, and uses the same priority order as AddPolicyProvider(). | 136 // most once, and uses the same priority order as AddPolicyProvider(). |
120 void SetPlatformPolicyProvider( | 137 void SetPlatformPolicyProvider( |
121 scoped_ptr<ConfigurationPolicyProvider> provider); | 138 scoped_ptr<ConfigurationPolicyProvider> provider); |
(...skipping 17 matching lines...) Expand all Loading... |
139 | 156 |
140 // The browser-global policy providers, in decreasing order of priority. | 157 // The browser-global policy providers, in decreasing order of priority. |
141 ScopedVector<ConfigurationPolicyProvider> policy_providers_; | 158 ScopedVector<ConfigurationPolicyProvider> policy_providers_; |
142 ConfigurationPolicyProvider* platform_policy_provider_; | 159 ConfigurationPolicyProvider* platform_policy_provider_; |
143 | 160 |
144 // Must be deleted before all the policy providers. | 161 // Must be deleted before all the policy providers. |
145 scoped_ptr<PolicyService> policy_service_; | 162 scoped_ptr<PolicyService> policy_service_; |
146 | 163 |
147 scoped_ptr<PolicyStatisticsCollector> policy_statistics_collector_; | 164 scoped_ptr<PolicyStatisticsCollector> policy_statistics_collector_; |
148 | 165 |
149 scoped_ptr<DeviceManagementService> device_management_service_; | 166 scoped_ptr<DeviceManagementService> enterprise_device_management_service_; |
| 167 scoped_ptr<DeviceManagementService> consumer_device_management_service_; |
150 | 168 |
151 DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnector); | 169 DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnector); |
152 }; | 170 }; |
153 | 171 |
154 } // namespace policy | 172 } // namespace policy |
155 | 173 |
156 #endif // COMPONENTS_POLICY_CORE_BROWSER_BROWSER_POLICY_CONNECTOR_H_ | 174 #endif // COMPONENTS_POLICY_CORE_BROWSER_BROWSER_POLICY_CONNECTOR_H_ |
OLD | NEW |