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