OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_H_ |
6 #define CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_H_ | 6 #define CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "chrome/browser/policy/cloud_policy_client.h" | |
14 #include "chrome/browser/policy/cloud_policy_constants.h" | |
15 #include "chrome/browser/policy/cloud_policy_manager.h" | 13 #include "chrome/browser/policy/cloud_policy_manager.h" |
16 | 14 |
17 class PrefService; | 15 class PrefService; |
18 class Profile; | 16 class Profile; |
19 | 17 |
20 namespace policy { | 18 namespace policy { |
21 | 19 |
| 20 class CloudPolicyClient; |
22 class DeviceManagementService; | 21 class DeviceManagementService; |
| 22 class UserCloudPolicyStore; |
23 | 23 |
24 // UserCloudPolicyManager keeps track of all things user policy, drives the | 24 // UserCloudPolicyManager handles initialization of user policy for Chrome |
25 // corresponding cloud policy service and publishes policy through the | 25 // Profiles on the desktop platforms. |
26 // ConfigurationPolicyProvider interface. | 26 class UserCloudPolicyManager : public CloudPolicyManager { |
27 class UserCloudPolicyManager : public CloudPolicyManager, | |
28 public CloudPolicyClient::Observer { | |
29 public: | 27 public: |
30 // If |wait_for_policy_fetch| is true, IsInitializationComplete() will return | 28 UserCloudPolicyManager(Profile* profile, |
31 // false as long as there hasn't been a successful policy fetch. | 29 scoped_ptr<UserCloudPolicyStore> store); |
32 UserCloudPolicyManager(scoped_ptr<CloudPolicyStore> store, | |
33 bool wait_for_policy_fetch); | |
34 virtual ~UserCloudPolicyManager(); | 30 virtual ~UserCloudPolicyManager(); |
35 | 31 |
36 // Enumeration describing how to initialize the UserCloudPolicyManager. | 32 // Initializes the cloud connection. |local_state| and |
37 enum PolicyInit { | 33 // |device_management_service| must stay valid until this object is deleted or |
38 // Forces policy to be loaded immediately (as part of the constructor). This | 34 // ShutdownAndRemovePolicy() gets called. Virtual for mocking. |
39 // will block the caller while file I/O happens, and the resulting object | |
40 // will start in an initialized state. This is only supported on desktop | |
41 // platforms, as those platforms are the only ones that initialize Profile | |
42 // objects synchronously (on ChromeOS, Profiles are initialized | |
43 // asynchronously, and the underlying policy mechanism is also | |
44 // asynchronous). | |
45 POLICY_INIT_IMMEDIATELY, | |
46 | |
47 // Loads policy via a background task. UserCloudPolicyManager will mark | |
48 // itself as initialized once the policy has finished loading. | |
49 POLICY_INIT_IN_BACKGROUND, | |
50 | |
51 // Attempts to download the latest policy from the server, and if the | |
52 // request fails, just uses the existing cached policy. The object will | |
53 // mark itself as initialized once the request is complete. | |
54 POLICY_INIT_REFRESH_FROM_SERVER | |
55 }; | |
56 | |
57 // Creates a UserCloudPolicyManager instance associated with the passed | |
58 // |profile|. If |policy_init| is passed as POLICY_INIT_IMMEDIATELY, then | |
59 // the CloudPolicyStore will be fully initialized before this call returns. | |
60 static scoped_ptr<UserCloudPolicyManager> Create(Profile* profile, | |
61 PolicyInit policy_init); | |
62 | |
63 // Initializes the cloud connection. |local_state| and |service| must stay | |
64 // valid until this object is deleted or ShutdownAndRemovePolicy() gets | |
65 // called. Virtual for mocking. | |
66 virtual void Initialize(PrefService* local_state, | 35 virtual void Initialize(PrefService* local_state, |
67 DeviceManagementService* device_management_service, | 36 DeviceManagementService* device_management_service); |
68 UserAffiliation user_affiliation); | |
69 | 37 |
70 // Shuts down the UserCloudPolicyManager (removes and stops refreshing the | 38 // Shuts down the UserCloudPolicyManager (removes and stops refreshing the |
71 // cached cloud policy). This is typically called when a profile is being | 39 // cached cloud policy). This is typically called when a profile is being |
72 // disassociated from a given user (e.g. during signout). No policy will be | 40 // disassociated from a given user (e.g. during signout). No policy will be |
73 // provided by this object until the next time Initialize() is invoked. | 41 // provided by this object until the next time Initialize() is invoked. |
74 void ShutdownAndRemovePolicy(); | 42 void ShutdownAndRemovePolicy(); |
75 | 43 |
76 // Cancels waiting for the policy fetch and flags the | |
77 // ConfigurationPolicyProvider ready (assuming all other initialization tasks | |
78 // have completed). | |
79 void CancelWaitForPolicyFetch(); | |
80 | |
81 // Returns true if the underlying CloudPolicyClient is already registered. | 44 // Returns true if the underlying CloudPolicyClient is already registered. |
82 // Virtual for mocking. | 45 // Virtual for mocking. |
83 virtual bool IsClientRegistered() const; | 46 virtual bool IsClientRegistered() const; |
84 | 47 |
85 // Register the CloudPolicyClient using the passed OAuth token. | 48 // Register the CloudPolicyClient using the passed OAuth token. |
86 void RegisterClient(const std::string& access_token); | 49 void RegisterClient(const std::string& access_token); |
87 | 50 |
88 // ConfigurationPolicyProvider: | 51 private: |
89 virtual void Shutdown() OVERRIDE; | 52 // The profile this instance belongs to. |
90 virtual bool IsInitializationComplete() const OVERRIDE; | 53 Profile* profile_; |
91 | 54 |
92 // CloudPolicyClient::Observer: | 55 // Typed pointer to the store owned by UserCloudPolicyManager. Note that |
93 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; | 56 // CloudPolicyManager only keeps a plain CloudPolicyStore pointer. |
94 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; | 57 scoped_ptr<UserCloudPolicyStore> store_; |
95 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; | |
96 | |
97 private: | |
98 // Completion handler for the explicit policy fetch triggered on startup in | |
99 // case |wait_for_policy_fetch_| is true. | |
100 void OnInitialPolicyFetchComplete(); | |
101 | |
102 // Whether to wait for a policy fetch to complete before reporting | |
103 // IsInitializationComplete(). | |
104 bool wait_for_policy_fetch_; | |
105 | |
106 // The pref service to pass to the refresh scheduler on initialization. | |
107 PrefService* local_state_; | |
108 | 58 |
109 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManager); | 59 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManager); |
110 }; | 60 }; |
111 | 61 |
112 } // namespace policy | 62 } // namespace policy |
113 | 63 |
114 #endif // CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_H_ | 64 #endif // CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_H_ |
OLD | NEW |