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.
5 #ifndef COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_CLOUD_POLICY_MANAGER_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_CLOUD_POLICY_MANAGER_H_
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"
21 class SequencedTaskRunner;
25 class URLRequestContextGetter;
30 class CloudExternalDataManager;
31 class DeviceManagementService;
32 class UserCloudPolicyStore;
34 // UserCloudPolicyManager handles initialization of user policy.
35 class POLICY_EXPORT UserCloudPolicyManager : public CloudPolicyManager {
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
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();
51 // ConfigurationPolicyProvider overrides:
52 virtual void Shutdown() OVERRIDE;
54 void SetSigninUsername(const std::string& username);
56 // Initializes the cloud connection. |local_state| must stay valid until this
57 // object is deleted or DisconnectAndRemovePolicy() gets called. Virtual for
60 PrefService* local_state,
61 scoped_refptr<net::URLRequestContextGetter> request_context,
62 scoped_ptr<CloudPolicyClient> client);
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();
70 // Returns true if the underlying CloudPolicyClient is already registered.
71 // Virtual for mocking.
72 virtual bool IsClientRegistered() const;
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);
83 // Typed pointer to the store owned by UserCloudPolicyManager. Note that
84 // CloudPolicyManager only keeps a plain CloudPolicyStore pointer.
85 scoped_ptr<UserCloudPolicyStore> store_;
87 // Path where policy for components will be cached.
88 base::FilePath component_policy_cache_path_;
90 // Manages external data referenced by policies.
91 scoped_ptr<CloudExternalDataManager> external_data_manager_;
93 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManager);
98 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_CLOUD_POLICY_MANAGER_H_