Chromium Code Reviews| 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" | 13 #include "chrome/browser/policy/cloud_policy_client.h" |
|
Joao da Silva
2012/11/21 17:06:34
This can be forward declared
Mattias Nissler (ping if slow)
2012/11/22 20:51:59
Done.
| |
| 14 #include "chrome/browser/policy/cloud_policy_constants.h" | 14 #include "chrome/browser/policy/cloud_policy_constants.h" |
| 15 #include "chrome/browser/policy/cloud_policy_manager.h" | 15 #include "chrome/browser/policy/cloud_policy_manager.h" |
| 16 | 16 |
| 17 class PrefService; | 17 class PrefService; |
| 18 class Profile; | 18 class Profile; |
|
Joao da Silva
2012/11/21 17:06:34
nit: not used
Mattias Nissler (ping if slow)
2012/11/22 20:51:59
Done.
| |
| 19 | 19 |
| 20 namespace policy { | 20 namespace policy { |
| 21 | 21 |
| 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. |
|
Andrew T Wilson (Slow)
2012/11/21 17:34:24
Careful about saying "desktop platforms" as we wil
Mattias Nissler (ping if slow)
2012/11/22 20:51:59
For now, it's correct. It's unclear at this point
| |
| 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 // If |wait_for_policy_fetch| is true, IsInitializationComplete() will return |
| 31 // false as long as there hasn't been a successful policy fetch. | 30 // false as long as there hasn't been a successful policy fetch. |
|
Joao da Silva
2012/11/21 17:06:34
Update comment.
This is dropping support to wait
Andrew T Wilson (Slow)
2012/11/21 17:34:24
BTW, I'm fine with that for now. We might need to
Mattias Nissler (ping if slow)
2012/11/22 20:51:59
Done.
Mattias Nissler (ping if slow)
2012/11/22 20:51:59
Once we need it on desktop too, we can see what th
| |
| 32 UserCloudPolicyManager(scoped_ptr<CloudPolicyStore> store, | 31 explicit UserCloudPolicyManager(scoped_ptr<UserCloudPolicyStore> store); |
| 33 bool wait_for_policy_fetch); | |
| 34 virtual ~UserCloudPolicyManager(); | 32 virtual ~UserCloudPolicyManager(); |
| 35 | 33 |
| 36 // Enumeration describing how to initialize the UserCloudPolicyManager. | 34 // Initializes the cloud connection. |local_state| and |
| 37 enum PolicyInit { | 35 // |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 | 36 // 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, | 37 virtual void Initialize(PrefService* local_state, |
| 67 DeviceManagementService* device_management_service, | 38 DeviceManagementService* device_management_service); |
| 68 UserAffiliation user_affiliation); | |
| 69 | 39 |
| 70 // Shuts down the UserCloudPolicyManager (removes and stops refreshing the | 40 // Shuts down the UserCloudPolicyManager (removes and stops refreshing the |
| 71 // cached cloud policy). This is typically called when a profile is being | 41 // 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 | 42 // 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. | 43 // provided by this object until the next time Initialize() is invoked. |
| 74 void ShutdownAndRemovePolicy(); | 44 void ShutdownAndRemovePolicy(); |
| 75 | 45 |
| 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. | 46 // Returns true if the underlying CloudPolicyClient is already registered. |
| 82 // Virtual for mocking. | 47 // Virtual for mocking. |
| 83 virtual bool IsClientRegistered() const; | 48 virtual bool IsClientRegistered() const; |
| 84 | 49 |
| 85 // Register the CloudPolicyClient using the passed OAuth token. | 50 // Register the CloudPolicyClient using the passed OAuth token. |
| 86 void RegisterClient(const std::string& access_token); | 51 void RegisterClient(const std::string& access_token); |
| 87 | 52 |
| 88 // ConfigurationPolicyProvider: | |
| 89 virtual void Shutdown() OVERRIDE; | |
| 90 virtual bool IsInitializationComplete() const OVERRIDE; | |
| 91 | |
| 92 // CloudPolicyClient::Observer: | |
| 93 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; | |
| 94 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; | |
| 95 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; | |
| 96 | |
| 97 private: | 53 private: |
| 98 // Completion handler for the explicit policy fetch triggered on startup in | 54 // Typed pointer to the store owned by UserCloudPolicyManager. Note that |
| 99 // case |wait_for_policy_fetch_| is true. | 55 // CloudPolicyManager only keeps a plain CloudPolicyStore pointer. |
| 100 void OnInitialPolicyFetchComplete(); | 56 scoped_ptr<UserCloudPolicyStore> store_; |
| 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 | 57 |
| 109 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManager); | 58 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManager); |
| 110 }; | 59 }; |
| 111 | 60 |
| 112 } // namespace policy | 61 } // namespace policy |
| 113 | 62 |
| 114 #endif // CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_H_ | 63 #endif // CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_H_ |
| OLD | NEW |