Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / policy / browser_policy_connector_chromeos.h
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_BROWSER_POLICY_CONNECTOR_CHROMEOS_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_BROWSER_POLICY_CONNECTOR_CHROMEOS_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/policy/chrome_browser_policy_connector.h"
15 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
16
17 class PrefRegistrySimple;
18 class PrefService;
19
20 namespace net {
21 class URLRequestContextGetter;
22 }
23
24 namespace policy {
25
26 class AppPackUpdater;
27 class ConsumerEnrollmentHandler;
28 class ConsumerManagementService;
29 class DeviceCloudPolicyInitializer;
30 class DeviceCloudPolicyInvalidator;
31 class DeviceCloudPolicyManagerChromeOS;
32 class DeviceLocalAccountPolicyService;
33 class DeviceManagementService;
34 class EnterpriseInstallAttributes;
35 class NetworkConfigurationUpdater;
36 class ProxyPolicyProvider;
37 class ServerBackedStateKeysBroker;
38
39 // Extends ChromeBrowserPolicyConnector with the setup specific to ChromeOS.
40 class BrowserPolicyConnectorChromeOS : public ChromeBrowserPolicyConnector {
41  public:
42   BrowserPolicyConnectorChromeOS();
43
44   virtual ~BrowserPolicyConnectorChromeOS();
45
46   virtual void Init(
47       PrefService* local_state,
48       scoped_refptr<net::URLRequestContextGetter> request_context) override;
49
50   // Shutdown() is called from BrowserProcessImpl::StartTearDown() but |this|
51   // observes some objects that get destroyed earlier. PreShutdown() is called
52   // from ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun(), allowing the
53   // connection to these dependencies to be severed earlier.
54   void PreShutdown();
55
56   virtual void Shutdown() override;
57
58   // Returns true if this device is managed by an enterprise (as opposed to
59   // a local owner).
60   bool IsEnterpriseManaged();
61
62   // Returns the enterprise domain if device is managed.
63   std::string GetEnterpriseDomain();
64
65   // Returns the device mode. For ChromeOS this function will return the mode
66   // stored in the lockbox, or DEVICE_MODE_CONSUMER if the lockbox has been
67   // locked empty, or DEVICE_MODE_UNKNOWN if the device has not been owned yet.
68   // For other OSes the function will always return DEVICE_MODE_CONSUMER.
69   DeviceMode GetDeviceMode();
70
71   // Works out the user affiliation by checking the given |user_name| against
72   // the installation attributes.
73   UserAffiliation GetUserAffiliation(const std::string& user_name);
74
75   AppPackUpdater* GetAppPackUpdater();
76
77   DeviceCloudPolicyManagerChromeOS* GetDeviceCloudPolicyManager() {
78     return device_cloud_policy_manager_;
79   }
80
81   DeviceCloudPolicyInitializer* GetDeviceCloudPolicyInitializer() {
82     return device_cloud_policy_initializer_.get();
83   }
84
85   DeviceLocalAccountPolicyService* GetDeviceLocalAccountPolicyService() {
86     return device_local_account_policy_service_.get();
87   }
88
89   EnterpriseInstallAttributes* GetInstallAttributes() {
90     return install_attributes_.get();
91   }
92
93   ServerBackedStateKeysBroker* GetStateKeysBroker() {
94     return state_keys_broker_.get();
95   }
96
97   // The browser-global PolicyService is created before Profiles are ready, to
98   // provide managed values for the local state PrefService. It includes a
99   // policy provider that forwards policies from a delegate policy provider.
100   // This call can be used to set the user policy provider as that delegate
101   // once the Profile is ready, so that user policies can also affect local
102   // state preferences.
103   // Only one user policy provider can be set as a delegate at a time, and any
104   // previously set delegate is removed. Passing NULL removes the current
105   // delegate, if there is one.
106   void SetUserPolicyDelegate(ConfigurationPolicyProvider* user_policy_provider);
107
108   ConsumerManagementService* GetConsumerManagementService() const {
109     return consumer_management_service_.get();
110   }
111
112   // Sets the device cloud policy initializer for testing.
113   void SetDeviceCloudPolicyInitializerForTesting(
114       scoped_ptr<DeviceCloudPolicyInitializer> initializer);
115
116   // Sets the install attributes for testing. Must be called before the browser
117   // is created. RemoveInstallAttributesForTesting must be called after the test
118   // to free the attributes.
119   static void SetInstallAttributesForTesting(
120       EnterpriseInstallAttributes* attributes);
121   static void RemoveInstallAttributesForTesting();
122
123   // Registers device refresh rate pref.
124   static void RegisterPrefs(PrefRegistrySimple* registry);
125
126  private:
127   // Set the timezone as soon as the policies are available.
128   void SetTimezoneIfPolicyAvailable();
129
130   void OnDeviceCloudPolicyManagerConnected();
131
132   // Components of the device cloud policy implementation.
133   scoped_ptr<ServerBackedStateKeysBroker> state_keys_broker_;
134   scoped_ptr<EnterpriseInstallAttributes> install_attributes_;
135   scoped_ptr<ConsumerManagementService> consumer_management_service_;
136   DeviceCloudPolicyManagerChromeOS* device_cloud_policy_manager_;
137   scoped_ptr<DeviceManagementService> consumer_device_management_service_;
138   scoped_ptr<ConsumerEnrollmentHandler> consumer_enrollment_handler_;
139   scoped_ptr<DeviceCloudPolicyInitializer> device_cloud_policy_initializer_;
140   scoped_ptr<DeviceLocalAccountPolicyService>
141       device_local_account_policy_service_;
142   scoped_ptr<DeviceCloudPolicyInvalidator> device_cloud_policy_invalidator_;
143
144   // This policy provider is used on Chrome OS to feed user policy into the
145   // global PolicyService instance. This works by installing the cloud policy
146   // provider of the primary profile as the delegate of the ProxyPolicyProvider,
147   // after login.
148   // The provider is owned by the base class; this field is just a typed weak
149   // pointer to get to the ProxyPolicyProvider at SetUserPolicyDelegate().
150   ProxyPolicyProvider* global_user_cloud_policy_provider_;
151
152   scoped_ptr<AppPackUpdater> app_pack_updater_;
153   scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_;
154
155   base::WeakPtrFactory<BrowserPolicyConnectorChromeOS> weak_ptr_factory_;
156
157   DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnectorChromeOS);
158 };
159
160 }  // namespace policy
161
162 #endif  // CHROME_BROWSER_CHROMEOS_POLICY_BROWSER_POLICY_CONNECTOR_CHROMEOS_H_