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

Unified Diff: chrome/browser/policy/cloud_policy_client.h

Issue 9109009: Introduce CloudPolicyClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix clang build. Created 8 years, 12 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/cloud_policy_client.h
diff --git a/chrome/browser/policy/cloud_policy_client.h b/chrome/browser/policy/cloud_policy_client.h
new file mode 100644
index 0000000000000000000000000000000000000000..7f27c29e46edc024fa86b9ea81d62150bbdc3ea5
--- /dev/null
+++ b/chrome/browser/policy/cloud_policy_client.h
@@ -0,0 +1,213 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_CLIENT_H_
+#define CHROME_BROWSER_POLICY_CLOUD_POLICY_CLIENT_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/observer_list.h"
+#include "base/time.h"
+#include "chrome/browser/policy/cloud_policy_constants.h"
+
+namespace enterprise_management {
+class DeviceManagementResponse;
+class DeviceRegisterRequest;
+class DeviceStatusReportRequest;
+class PolicyFetchRequest;
+class PolicyFetchResponse;
+class SessionStatusReportRequest;
+}
+
+namespace policy {
+
+class DeviceManagementRequestJob;
+class DeviceManagementService;
+
+// Implements the core logic required to talk to the device management service.
+// Also keeps track of the current state of the association with the service,
+// such as whether there is a valid registration (DMToken is present in that
+// case) and whether and what errors occurred in the latest request.
+//
+// Note that CloudPolicyClient doesn't do any validation of policy responses
+// such as signature and time stamp checks. These happen once the policy gets
+// installed in the cloud policy cache.
+class CloudPolicyClient {
+ public:
+ // Indicates whether to register for user or device policy.
+ enum PolicyScope {
+ POLICY_SCOPE_USER,
+ POLICY_SCOPE_DEVICE,
+ };
+
+ // Container for public key version and validity flag.
+ class PublicKeyVersion {
+ public:
+ // Constructs and invalid public key version.
+ PublicKeyVersion();
+ // Create a valid public key version object.
+ explicit PublicKeyVersion(int version);
+
+ // Copy constructor and assignment operator so this can be passed by value.
+ explicit PublicKeyVersion(const PublicKeyVersion& other);
+ const PublicKeyVersion& operator=(const PublicKeyVersion& other);
+
+ bool valid() { return valid_; }
+ 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.
+
+ private:
+ bool valid_;
+ int version_;
+ };
+
+ // Observer interface for state and policy changes.
+ class Observer {
+ public:
+ virtual ~Observer();
+
+ // Called when an updated policy is available.
+ virtual void OnPolicyChanged() = 0;
+
+ // Called upon registration state changes.
+ virtual void OnRegistrationStateChanged() = 0;
+
+ // Indicates there's been an error.
+ virtual void OnError() = 0;
Joao da Silva 2012/01/05 15:35:01 This is great for the CloudPolicyProvider::FetchPo
+ };
+
+ // Delegate interface for supplying status information to upload to the server
+ // as part of the policy fetch request.
+ class StatusProvider {
+ public:
+ virtual ~StatusProvider();
+
+ // 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.
+ virtual bool GetDeviceStatus(
+ enterprise_management::DeviceStatusReportRequest* status) = 0;
+ virtual bool GetSessionStatus(
+ enterprise_management::SessionStatusReportRequest* status) = 0;
+
+ // Called after the status information has successfully been submitted to
+ // the server.
+ 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
+ };
+
+ // |provider| and |service| are weak pointers and it's the caller's
+ // responsibility to keep them valid for the lifetime of CloudPolicyClient.
+ CloudPolicyClient(const std::string& machine_id,
+ const std::string& machine_model,
+ UserAffiliation user_affiliation,
+ PolicyScope scope,
+ StatusProvider* provider,
+ DeviceManagementService* service);
+ ~CloudPolicyClient();
+
+ // Sets the DMToken, thereby establishing a registration with the server. A
+ // policy fetch is not automatically issued but can be requested by calling
+ // FetchPolicy().
+ void SetupRegistration(const std::string& dm_token,
+ 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
+
+ // Attempts to register with the device management service. Results in a
+ // registration change or error notification.
+ void Register(const std::string& auth_token);
+
+ // Requests a policy fetch. The client being registered is a prerequisite to
+ // this operation and false is returned without further action if that is not
+ // the case. If FetchPolicy() returns true, a policy change notification is
+ // reported to the observers and the new policy blob can be retrieved once the
+ // policy fetch operation completes. In case of multiple requests to fetch
+ // policy, new requests will cancel any pending requests and the latest
+ // request will eventually trigger notifications.
+ bool FetchPolicy();
Joao da Silva 2012/01/05 15:35:01 The part about canceling previous requests turned
+
+ // Sends an unregistration request to the server.
+ void Unregister();
+
+ // Adds an observer to be called back upon policy and state changes.
+ void AddObserver(Observer* observer);
+
+ // Removes the specified observer.
+ void RemoveObserver(Observer* observer);
+
+ void set_submit_machine_id(bool submit_machine_id) {
+ submit_machine_id_ = submit_machine_id;
+ }
+
+ void set_last_fetch_timestamp(const base::Time& timestamp) {
+ last_fetch_timestamp_ = timestamp;
+ }
+
+ void set_public_key_version(const PublicKeyVersion& public_key_version) {
+ public_key_version_ = public_key_version;
+ }
+
+ // Whether the client is registered with the device management service.
+ bool is_registered() const { return !dm_token_.empty(); }
+
+ const enterprise_management::PolicyFetchResponse* policy() const {
+ return policy_.get();
+ }
+
+ DeviceManagementStatus status() const {
+ return status_;
+ }
+
+ private:
+ // Sets the registration type suitable for the policy scope used.
+ void SetRegistrationType(
+ enterprise_management::DeviceRegisterRequest* request) const;
+
+ // Sets the appropriate policy type in the fetch request.
+ void SetPolicyType(enterprise_management::PolicyFetchRequest* request) const;
+
+ // Callback for registration requests.
+ void OnRegisterCompleted(
+ DeviceManagementStatus status,
+ const enterprise_management::DeviceManagementResponse& response);
+
+ // Callback for policy fetch requests.
+ void OnPolicyFetchCompleted(
+ DeviceManagementStatus status,
+ const enterprise_management::DeviceManagementResponse& response);
+
+ // Callback for unregistration requests.
+ void OnUnregisterCompleted(
+ DeviceManagementStatus status,
+ const enterprise_management::DeviceManagementResponse& response);
+
+ // Data necessary for constructing policy requests.
+ const std::string machine_id_;
+ const std::string machine_model_;
+ const UserAffiliation user_affiliation_;
+ const PolicyScope scope_;
+
+ std::string dm_token_;
+ std::string client_id_;
+ bool submit_machine_id_;
+ base::Time last_fetch_timestamp_;
+ PublicKeyVersion public_key_version_;
+
+ // Used for issuing requests to the device management service.
+ DeviceManagementService* service_;
+ scoped_ptr<DeviceManagementRequestJob> request_job_;
+
+ // Status upload data is produced by |status_provider_|.
+ StatusProvider* status_provider_;
+
+ // The policy blob returned by the last policy fetch operation.
+ scoped_ptr<enterprise_management::PolicyFetchResponse> policy_;
+ DeviceManagementStatus status_;
+
+ ObserverList<Observer, true> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient);
+};
+
+} // namespace policy
+
+#endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CLIENT_H_

Powered by Google App Engine
This is Rietveld 408576698