Chromium Code Reviews| 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_CLOUD_POLICY_CLIENT_H_ | |
| 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_CLIENT_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/observer_list.h" | |
| 14 #include "base/time.h" | |
| 15 #include "chrome/browser/policy/cloud_policy_constants.h" | |
| 16 | |
| 17 namespace enterprise_management { | |
| 18 class DeviceManagementResponse; | |
| 19 class DeviceRegisterRequest; | |
| 20 class DeviceStatusReportRequest; | |
| 21 class PolicyFetchRequest; | |
| 22 class PolicyFetchResponse; | |
| 23 class SessionStatusReportRequest; | |
| 24 } | |
| 25 | |
| 26 namespace policy { | |
| 27 | |
| 28 class DeviceManagementRequestJob; | |
| 29 class DeviceManagementService; | |
| 30 | |
| 31 // Implements the core logic required to talk to the device management service. | |
| 32 // Also keeps track of the current state of the association with the service, | |
| 33 // such as whether there is a valid registration (DMToken is present in that | |
| 34 // case) and whether and what errors occurred in the latest request. | |
| 35 // | |
| 36 // Note that CloudPolicyClient doesn't do any validation of policy responses | |
| 37 // such as signature and time stamp checks. These happen once the policy gets | |
| 38 // installed in the cloud policy cache. | |
| 39 class CloudPolicyClient { | |
| 40 public: | |
| 41 // Indicates whether to register for user or device policy. | |
| 42 enum PolicyScope { | |
| 43 POLICY_SCOPE_USER, | |
| 44 POLICY_SCOPE_DEVICE, | |
| 45 }; | |
| 46 | |
| 47 // Container for public key version and validity flag. | |
| 48 class PublicKeyVersion { | |
| 49 public: | |
| 50 // Constructs and invalid public key version. | |
| 51 PublicKeyVersion(); | |
| 52 // Create a valid public key version object. | |
| 53 explicit PublicKeyVersion(int version); | |
| 54 | |
| 55 // Copy constructor and assignment operator so this can be passed by value. | |
| 56 explicit PublicKeyVersion(const PublicKeyVersion& other); | |
| 57 const PublicKeyVersion& operator=(const PublicKeyVersion& other); | |
| 58 | |
| 59 bool valid() { return valid_; } | |
| 60 int version() { return version_; } | |
|
Joao da Silva
2012/01/05 15:35:01
Nit: const
Mattias Nissler (ping if slow)
2012/04/16 14:28:38
Done.
| |
| 61 | |
| 62 private: | |
| 63 bool valid_; | |
| 64 int version_; | |
| 65 }; | |
| 66 | |
| 67 // Observer interface for state and policy changes. | |
| 68 class Observer { | |
| 69 public: | |
| 70 virtual ~Observer(); | |
| 71 | |
| 72 // Called when an updated policy is available. | |
| 73 virtual void OnPolicyChanged() = 0; | |
| 74 | |
| 75 // Called upon registration state changes. | |
| 76 virtual void OnRegistrationStateChanged() = 0; | |
| 77 | |
| 78 // Indicates there's been an error. | |
| 79 virtual void OnError() = 0; | |
|
Joao da Silva
2012/01/05 15:35:01
This is great for the CloudPolicyProvider::FetchPo
| |
| 80 }; | |
| 81 | |
| 82 // Delegate interface for supplying status information to upload to the server | |
| 83 // as part of the policy fetch request. | |
| 84 class StatusProvider { | |
| 85 public: | |
| 86 virtual ~StatusProvider(); | |
| 87 | |
| 88 // Retrieves in status information to send with the next policy fetch. | |
|
Joao da Silva
2012/01/05 15:35:01
Document what the bool return value is used for. R
Mattias Nissler (ping if slow)
2012/04/16 14:28:38
Done.
| |
| 89 virtual bool GetDeviceStatus( | |
| 90 enterprise_management::DeviceStatusReportRequest* status) = 0; | |
| 91 virtual bool GetSessionStatus( | |
| 92 enterprise_management::SessionStatusReportRequest* status) = 0; | |
| 93 | |
| 94 // Called after the status information has successfully been submitted to | |
| 95 // the server. | |
| 96 virtual void OnSubmittedSuccessfully() = 0; | |
|
Joao da Silva
2012/01/05 15:35:01
Didn't find any calls to this.
Mattias Nissler (ping if slow)
2012/04/16 14:28:38
True. I had missed to implement this properly. Upd
| |
| 97 }; | |
| 98 | |
| 99 // |provider| and |service| are weak pointers and it's the caller's | |
| 100 // responsibility to keep them valid for the lifetime of CloudPolicyClient. | |
| 101 CloudPolicyClient(const std::string& machine_id, | |
| 102 const std::string& machine_model, | |
| 103 UserAffiliation user_affiliation, | |
| 104 PolicyScope scope, | |
| 105 StatusProvider* provider, | |
| 106 DeviceManagementService* service); | |
| 107 ~CloudPolicyClient(); | |
| 108 | |
| 109 // Sets the DMToken, thereby establishing a registration with the server. A | |
| 110 // policy fetch is not automatically issued but can be requested by calling | |
| 111 // FetchPolicy(). | |
| 112 void SetupRegistration(const std::string& dm_token, | |
| 113 const std::string& client_id); | |
|
Joao da Silva
2012/01/05 15:35:01
Where is |dm_token| supposed to come from? I guess
Mattias Nissler (ping if slow)
2012/04/16 14:28:38
Yes, the intention is to make the owner of the cli
| |
| 114 | |
| 115 // Attempts to register with the device management service. Results in a | |
| 116 // registration change or error notification. | |
| 117 void Register(const std::string& auth_token); | |
| 118 | |
| 119 // Requests a policy fetch. The client being registered is a prerequisite to | |
| 120 // this operation and false is returned without further action if that is not | |
| 121 // the case. If FetchPolicy() returns true, a policy change notification is | |
| 122 // reported to the observers and the new policy blob can be retrieved once the | |
| 123 // policy fetch operation completes. In case of multiple requests to fetch | |
| 124 // policy, new requests will cancel any pending requests and the latest | |
| 125 // request will eventually trigger notifications. | |
| 126 bool FetchPolicy(); | |
|
Joao da Silva
2012/01/05 15:35:01
The part about canceling previous requests turned
| |
| 127 | |
| 128 // Sends an unregistration request to the server. | |
| 129 void Unregister(); | |
| 130 | |
| 131 // Adds an observer to be called back upon policy and state changes. | |
| 132 void AddObserver(Observer* observer); | |
| 133 | |
| 134 // Removes the specified observer. | |
| 135 void RemoveObserver(Observer* observer); | |
| 136 | |
| 137 void set_submit_machine_id(bool submit_machine_id) { | |
| 138 submit_machine_id_ = submit_machine_id; | |
| 139 } | |
| 140 | |
| 141 void set_last_fetch_timestamp(const base::Time& timestamp) { | |
| 142 last_fetch_timestamp_ = timestamp; | |
| 143 } | |
| 144 | |
| 145 void set_public_key_version(const PublicKeyVersion& public_key_version) { | |
| 146 public_key_version_ = public_key_version; | |
| 147 } | |
| 148 | |
| 149 // Whether the client is registered with the device management service. | |
| 150 bool is_registered() const { return !dm_token_.empty(); } | |
| 151 | |
| 152 const enterprise_management::PolicyFetchResponse* policy() const { | |
| 153 return policy_.get(); | |
| 154 } | |
| 155 | |
| 156 DeviceManagementStatus status() const { | |
| 157 return status_; | |
| 158 } | |
| 159 | |
| 160 private: | |
| 161 // Sets the registration type suitable for the policy scope used. | |
| 162 void SetRegistrationType( | |
| 163 enterprise_management::DeviceRegisterRequest* request) const; | |
| 164 | |
| 165 // Sets the appropriate policy type in the fetch request. | |
| 166 void SetPolicyType(enterprise_management::PolicyFetchRequest* request) const; | |
| 167 | |
| 168 // Callback for registration requests. | |
| 169 void OnRegisterCompleted( | |
| 170 DeviceManagementStatus status, | |
| 171 const enterprise_management::DeviceManagementResponse& response); | |
| 172 | |
| 173 // Callback for policy fetch requests. | |
| 174 void OnPolicyFetchCompleted( | |
| 175 DeviceManagementStatus status, | |
| 176 const enterprise_management::DeviceManagementResponse& response); | |
| 177 | |
| 178 // Callback for unregistration requests. | |
| 179 void OnUnregisterCompleted( | |
| 180 DeviceManagementStatus status, | |
| 181 const enterprise_management::DeviceManagementResponse& response); | |
| 182 | |
| 183 // Data necessary for constructing policy requests. | |
| 184 const std::string machine_id_; | |
| 185 const std::string machine_model_; | |
| 186 const UserAffiliation user_affiliation_; | |
| 187 const PolicyScope scope_; | |
| 188 | |
| 189 std::string dm_token_; | |
| 190 std::string client_id_; | |
| 191 bool submit_machine_id_; | |
| 192 base::Time last_fetch_timestamp_; | |
| 193 PublicKeyVersion public_key_version_; | |
| 194 | |
| 195 // Used for issuing requests to the device management service. | |
| 196 DeviceManagementService* service_; | |
| 197 scoped_ptr<DeviceManagementRequestJob> request_job_; | |
| 198 | |
| 199 // Status upload data is produced by |status_provider_|. | |
| 200 StatusProvider* status_provider_; | |
| 201 | |
| 202 // The policy blob returned by the last policy fetch operation. | |
| 203 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_; | |
| 204 DeviceManagementStatus status_; | |
| 205 | |
| 206 ObserverList<Observer, true> observers_; | |
| 207 | |
| 208 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient); | |
| 209 }; | |
| 210 | |
| 211 } // namespace policy | |
| 212 | |
| 213 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CLIENT_H_ | |
| OLD | NEW |