Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: chrome/browser/policy/user_cloud_policy_manager.h

Issue 11415094: Split UserCloudPolicyManager implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebae Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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" 13 #include "chrome/browser/policy/cloud_policy_constants.h"
15 #include "chrome/browser/policy/cloud_policy_manager.h" 14 #include "chrome/browser/policy/cloud_policy_manager.h"
16 15
17 class PrefService; 16 class PrefService;
18 class Profile; 17 class Profile;
19 18
20 namespace policy { 19 namespace policy {
21 20
21 class CloudPolicyClient;
22 class DeviceManagementService; 22 class DeviceManagementService;
23 class UserCloudPolicyStore;
23 24
24 // UserCloudPolicyManager keeps track of all things user policy, drives the 25 // UserCloudPolicyManager handles initialization of user policy for Chrome
25 // corresponding cloud policy service and publishes policy through the 26 // Profiles on the desktop platforms.
26 // ConfigurationPolicyProvider interface. 27 class UserCloudPolicyManager : public CloudPolicyManager {
27 class UserCloudPolicyManager : public CloudPolicyManager,
28 public CloudPolicyClient::Observer {
29 public: 28 public:
30 // If |wait_for_policy_fetch| is true, IsInitializationComplete() will return 29 UserCloudPolicyManager(Profile* profile,
31 // false as long as there hasn't been a successful policy fetch. 30 scoped_ptr<UserCloudPolicyStore> store);
32 UserCloudPolicyManager(scoped_ptr<CloudPolicyStore> store,
33 bool wait_for_policy_fetch);
34 virtual ~UserCloudPolicyManager(); 31 virtual ~UserCloudPolicyManager();
35 32
36 // Enumeration describing how to initialize the UserCloudPolicyManager. 33 // Creates a new instance for use with |profile|. If |force_immediate_load| is
37 enum PolicyInit { 34 // true, policy is loaded synchronously from UserCloudPolicyStore at startup.
38 // Forces policy to be loaded immediately (as part of the constructor). This 35 static scoped_ptr<UserCloudPolicyManager> Create(Profile* profile,
39 // will block the caller while file I/O happens, and the resulting object 36 bool force_immediate_load);
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 37
47 // Loads policy via a background task. UserCloudPolicyManager will mark 38 // Initializes the cloud connection. |local_state| and
48 // itself as initialized once the policy has finished loading. 39 // |device_management_service| must stay valid until this object is deleted or
49 POLICY_INIT_IN_BACKGROUND, 40 // ShutdownAndRemovePolicy() gets called. Virtual for mocking.
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, 41 virtual void Initialize(PrefService* local_state,
67 DeviceManagementService* device_management_service, 42 DeviceManagementService* device_management_service);
68 UserAffiliation user_affiliation);
69 43
70 // Shuts down the UserCloudPolicyManager (removes and stops refreshing the 44 // Shuts down the UserCloudPolicyManager (removes and stops refreshing the
71 // cached cloud policy). This is typically called when a profile is being 45 // 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 46 // 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. 47 // provided by this object until the next time Initialize() is invoked.
74 void ShutdownAndRemovePolicy(); 48 void ShutdownAndRemovePolicy();
75 49
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. 50 // Returns true if the underlying CloudPolicyClient is already registered.
82 // Virtual for mocking. 51 // Virtual for mocking.
83 virtual bool IsClientRegistered() const; 52 virtual bool IsClientRegistered() const;
84 53
85 // Register the CloudPolicyClient using the passed OAuth token. 54 // Register the CloudPolicyClient using the passed OAuth token.
86 void RegisterClient(const std::string& access_token); 55 void RegisterClient(const std::string& access_token);
87 56
88 // ConfigurationPolicyProvider: 57 private:
89 virtual void Shutdown() OVERRIDE; 58 // The profile this instance belongs to.
90 virtual bool IsInitializationComplete() const OVERRIDE; 59 Profile* profile_;
91 60
92 // CloudPolicyClient::Observer: 61 // Typed pointer to the store owned by UserCloudPolicyManager. Note that
93 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; 62 // CloudPolicyManager only keeps a plain CloudPolicyStore pointer.
94 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; 63 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 64
109 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManager); 65 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManager);
110 }; 66 };
111 67
112 } // namespace policy 68 } // namespace policy
113 69
114 #endif // CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_H_ 70 #endif // CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698