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
17class PrefRegistrySimple;
18class PrefService;
19
20namespace net {
21class URLRequestContextGetter;
22}
23
24namespace policy {
25
26class AppPackUpdater;
27class DeviceCloudPolicyManagerChromeOS;
28class DeviceLocalAccountPolicyService;
29class DeviceManagementService;
30class EnterpriseInstallAttributes;
31class NetworkConfigurationUpdater;
32class ProxyPolicyProvider;
33class ServerBackedStateKeysBroker;
34
35// Extends ChromeBrowserPolicyConnector with the setup specific to ChromeOS.
36class BrowserPolicyConnectorChromeOS : public ChromeBrowserPolicyConnector {
37 public:
38  BrowserPolicyConnectorChromeOS();
39
40  virtual ~BrowserPolicyConnectorChromeOS();
41
42  virtual void Init(
43      PrefService* local_state,
44      scoped_refptr<net::URLRequestContextGetter> request_context) OVERRIDE;
45
46  virtual void Shutdown() OVERRIDE;
47
48  // Returns true if this device is managed by an enterprise (as opposed to
49  // a local owner).
50  bool IsEnterpriseManaged();
51
52  // Returns the enterprise domain if device is managed.
53  std::string GetEnterpriseDomain();
54
55  // Returns the device mode. For ChromeOS this function will return the mode
56  // stored in the lockbox, or DEVICE_MODE_CONSUMER if the lockbox has been
57  // locked empty, or DEVICE_MODE_UNKNOWN if the device has not been owned yet.
58  // For other OSes the function will always return DEVICE_MODE_CONSUMER.
59  DeviceMode GetDeviceMode();
60
61  // Works out the user affiliation by checking the given |user_name| against
62  // the installation attributes.
63  UserAffiliation GetUserAffiliation(const std::string& user_name);
64
65  AppPackUpdater* GetAppPackUpdater();
66
67  DeviceCloudPolicyManagerChromeOS* GetDeviceCloudPolicyManager() {
68    return device_cloud_policy_manager_;
69  }
70
71  DeviceLocalAccountPolicyService* GetDeviceLocalAccountPolicyService() {
72    return device_local_account_policy_service_.get();
73  }
74
75  EnterpriseInstallAttributes* GetInstallAttributes() {
76    return install_attributes_.get();
77  }
78
79  ServerBackedStateKeysBroker* GetStateKeysBroker() {
80    return state_keys_broker_.get();
81  }
82
83  // The browser-global PolicyService is created before Profiles are ready, to
84  // provide managed values for the local state PrefService. It includes a
85  // policy provider that forwards policies from a delegate policy provider.
86  // This call can be used to set the user policy provider as that delegate
87  // once the Profile is ready, so that user policies can also affect local
88  // state preferences.
89  // Only one user policy provider can be set as a delegate at a time, and any
90  // previously set delegate is removed. Passing NULL removes the current
91  // delegate, if there is one.
92  void SetUserPolicyDelegate(ConfigurationPolicyProvider* user_policy_provider);
93
94  // Returns the device management service for consumer management.
95  DeviceManagementService* consumer_device_management_service() const {
96    return consumer_device_management_service_.get();
97  }
98
99  // Sets the install attributes for testing. Must be called before the browser
100  // is created. RemoveInstallAttributesForTesting must be called after the test
101  // to free the attributes.
102  static void SetInstallAttributesForTesting(
103      EnterpriseInstallAttributes* attributes);
104  static void RemoveInstallAttributesForTesting();
105
106  // Registers device refresh rate pref.
107  static void RegisterPrefs(PrefRegistrySimple* registry);
108
109 private:
110  // Set the timezone as soon as the policies are available.
111  void SetTimezoneIfPolicyAvailable();
112
113  // Components of the device cloud policy implementation.
114  scoped_ptr<ServerBackedStateKeysBroker> state_keys_broker_;
115  scoped_ptr<EnterpriseInstallAttributes> install_attributes_;
116  DeviceCloudPolicyManagerChromeOS* device_cloud_policy_manager_;
117  scoped_ptr<DeviceLocalAccountPolicyService>
118      device_local_account_policy_service_;
119
120  // This policy provider is used on Chrome OS to feed user policy into the
121  // global PolicyService instance. This works by installing the cloud policy
122  // provider of the primary profile as the delegate of the ProxyPolicyProvider,
123  // after login.
124  // The provider is owned by the base class; this field is just a typed weak
125  // pointer to get to the ProxyPolicyProvider at SetUserPolicyDelegate().
126  ProxyPolicyProvider* global_user_cloud_policy_provider_;
127
128  scoped_ptr<AppPackUpdater> app_pack_updater_;
129  scoped_ptr<NetworkConfigurationUpdater> network_configuration_updater_;
130
131  scoped_ptr<DeviceManagementService> consumer_device_management_service_;
132
133  base::WeakPtrFactory<BrowserPolicyConnectorChromeOS> weak_ptr_factory_;
134
135  DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnectorChromeOS);
136};
137
138}  // namespace policy
139
140#endif  // CHROME_BROWSER_CHROMEOS_POLICY_BROWSER_POLICY_CONNECTOR_CHROMEOS_H_
141