Home | History | Annotate | Download | only in cloud
      1 // Copyright 2013 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 COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_CLOUD_POLICY_MANAGER_H_
      6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_CLOUD_POLICY_MANAGER_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/compiler_specific.h"
     12 #include "base/files/file_path.h"
     13 #include "base/memory/ref_counted.h"
     14 #include "base/memory/scoped_ptr.h"
     15 #include "components/policy/core/common/cloud/cloud_policy_manager.h"
     16 #include "components/policy/policy_export.h"
     17 
     18 class PrefService;
     19 
     20 namespace base {
     21 class SequencedTaskRunner;
     22 }
     23 
     24 namespace net {
     25 class URLRequestContextGetter;
     26 }
     27 
     28 namespace policy {
     29 
     30 class CloudExternalDataManager;
     31 class DeviceManagementService;
     32 class UserCloudPolicyStore;
     33 
     34 // UserCloudPolicyManager handles initialization of user policy.
     35 class POLICY_EXPORT UserCloudPolicyManager : public CloudPolicyManager {
     36  public:
     37   // |task_runner| is the runner for policy refresh tasks.
     38   // |file_task_runner| is used for file operations. Currently this must be
     39   // the FILE BrowserThread.
     40   // |io_task_runner| is used for network IO. Currently this must be the IO
     41   // BrowserThread.
     42   UserCloudPolicyManager(
     43       scoped_ptr<UserCloudPolicyStore> store,
     44       const base::FilePath& component_policy_cache_path,
     45       scoped_ptr<CloudExternalDataManager> external_data_manager,
     46       const scoped_refptr<base::SequencedTaskRunner>& task_runner,
     47       const scoped_refptr<base::SequencedTaskRunner>& file_task_runner,
     48       const scoped_refptr<base::SequencedTaskRunner>& io_task_runner);
     49   virtual ~UserCloudPolicyManager();
     50 
     51   // ConfigurationPolicyProvider overrides:
     52   virtual void Shutdown() OVERRIDE;
     53 
     54   void SetSigninUsername(const std::string& username);
     55 
     56   // Initializes the cloud connection. |local_state| must stay valid until this
     57   // object is deleted or DisconnectAndRemovePolicy() gets called. Virtual for
     58   // mocking.
     59   virtual void Connect(
     60       PrefService* local_state,
     61       scoped_refptr<net::URLRequestContextGetter> request_context,
     62       scoped_ptr<CloudPolicyClient> client);
     63 
     64   // Shuts down the UserCloudPolicyManager (removes and stops refreshing the
     65   // cached cloud policy). This is typically called when a profile is being
     66   // disassociated from a given user (e.g. during signout). No policy will be
     67   // provided by this object until the next time Initialize() is invoked.
     68   void DisconnectAndRemovePolicy();
     69 
     70   // Returns true if the underlying CloudPolicyClient is already registered.
     71   // Virtual for mocking.
     72   virtual bool IsClientRegistered() const;
     73 
     74   // Creates a CloudPolicyClient for this client. Used in situations where
     75   // callers want to create a DMToken without actually initializing the
     76   // profile's policy infrastructure (for example, during signin when we
     77   // want to check if the user's domain requires policy).
     78   static scoped_ptr<CloudPolicyClient> CreateCloudPolicyClient(
     79       DeviceManagementService* device_management_service,
     80       scoped_refptr<net::URLRequestContextGetter> request_context);
     81 
     82  private:
     83   // Typed pointer to the store owned by UserCloudPolicyManager. Note that
     84   // CloudPolicyManager only keeps a plain CloudPolicyStore pointer.
     85   scoped_ptr<UserCloudPolicyStore> store_;
     86 
     87   // Path where policy for components will be cached.
     88   base::FilePath component_policy_cache_path_;
     89 
     90   // Manages external data referenced by policies.
     91   scoped_ptr<CloudExternalDataManager> external_data_manager_;
     92 
     93   DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManager);
     94 };
     95 
     96 }  // namespace policy
     97 
     98 #endif  // COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_CLOUD_POLICY_MANAGER_H_
     99