OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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_POLICY_USER_CLOUD_POLICY_MANAGER_CHROMEOS_H_ | |
6 #define CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_CHROMEOS_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/compiler_specific.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "chrome/browser/policy/cloud_policy_client.h" | |
15 #include "chrome/browser/policy/cloud_policy_constants.h" | |
16 #include "chrome/browser/policy/cloud_policy_manager.h" | |
17 #include "chrome/browser/policy/component_cloud_policy_service.h" | |
18 | |
19 class PrefService; | |
20 | |
21 namespace net { | |
22 class URLRequestContextGetter; | |
23 } | |
24 | |
25 namespace policy { | |
26 | |
27 class DeviceManagementService; | |
28 class ResourceCache; | |
29 | |
30 // UserCloudPolicyManagerChromeOS implements logic for initializing user policy | |
31 // on Chrome OS. | |
32 class UserCloudPolicyManagerChromeOS | |
33 : public CloudPolicyManager, | |
34 public CloudPolicyClient::Observer, | |
35 public ComponentCloudPolicyService::Delegate { | |
36 public: | |
37 // If |wait_for_policy_fetch| is true, IsInitializationComplete() will return | |
38 // false as long as there hasn't been a successful policy fetch. | |
39 UserCloudPolicyManagerChromeOS( | |
40 scoped_ptr<CloudPolicyStore> store, | |
41 scoped_ptr<ResourceCache> resource_cache, | |
42 bool wait_for_policy_fetch); | |
43 virtual ~UserCloudPolicyManagerChromeOS(); | |
44 | |
45 // Initializes the cloud connection. |local_state| and | |
46 // |device_management_service| must stay valid until this object is deleted. | |
47 void Connect(PrefService* local_state, | |
48 DeviceManagementService* device_management_service, | |
49 scoped_refptr<net::URLRequestContextGetter> request_context, | |
50 UserAffiliation user_affiliation); | |
51 | |
52 // Cancels waiting for the policy fetch and flags the | |
53 // ConfigurationPolicyProvider ready (assuming all other initialization tasks | |
54 // have completed). | |
55 void CancelWaitForPolicyFetch(); | |
56 | |
57 // Register the CloudPolicyClient using the passed OAuth token. | |
58 void RegisterClient(const std::string& access_token); | |
59 | |
60 // Returns true if the underlying CloudPolicyClient is already registered. | |
61 bool IsClientRegistered() const; | |
62 | |
63 // ConfigurationPolicyProvider: | |
64 virtual void Shutdown() OVERRIDE; | |
65 virtual bool IsInitializationComplete(PolicyDomain domain) const OVERRIDE; | |
66 virtual void RegisterPolicyDomain( | |
67 PolicyDomain domain, | |
68 const std::set<std::string>& component_ids) OVERRIDE; | |
69 | |
70 // CloudPolicyManager: | |
71 virtual scoped_ptr<PolicyBundle> CreatePolicyBundle() OVERRIDE; | |
72 | |
73 // CloudPolicyClient::Observer: | |
74 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; | |
75 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; | |
76 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; | |
77 | |
78 // ComponentCloudPolicyService::Observer: | |
79 virtual void OnComponentCloudPolicyRefreshNeeded() OVERRIDE; | |
80 virtual void OnComponentCloudPolicyUpdated() OVERRIDE; | |
81 | |
82 private: | |
83 // Completion handler for the explicit policy fetch triggered on startup in | |
84 // case |wait_for_policy_fetch_| is true. |success| is true if the fetch was | |
85 // successful. | |
86 void OnInitialPolicyFetchComplete(bool success); | |
87 | |
88 void StartRefreshScheduler(); | |
89 | |
90 // Owns the store, note that CloudPolicyManager just keeps a plain pointer. | |
91 scoped_ptr<CloudPolicyStore> store_; | |
92 | |
93 // Handles fetching and storing cloud policy for components. It uses the | |
94 // |store_|, so destroy it first. | |
95 scoped_ptr<ComponentCloudPolicyService> component_policy_service_; | |
96 | |
97 // Whether to wait for a policy fetch to complete before reporting | |
98 // IsInitializationComplete(). | |
99 bool wait_for_policy_fetch_; | |
100 | |
101 // The pref service to pass to the refresh scheduler on initialization. | |
102 PrefService* local_state_; | |
103 | |
104 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerChromeOS); | |
105 }; | |
106 | |
107 } // namespace policy | |
108 | |
109 #endif // CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_CHROMEOS_H_ | |
OLD | NEW |