Index: chrome/browser/policy/auto_enrollment_client.h |
diff --git a/chrome/browser/policy/auto_enrollment_client.h b/chrome/browser/policy/auto_enrollment_client.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cbf68db22c1a9a93527eac2aba2f7b2dadc74c76 |
--- /dev/null |
+++ b/chrome/browser/policy/auto_enrollment_client.h |
@@ -0,0 +1,111 @@ |
+// Copyright (c) 2011 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_AUTO_ENROLLMENT_CLIENT_H_ |
+#define CHROME_BROWSER_POLICY_AUTO_ENROLLMENT_CLIENT_H_ |
+#pragma once |
+ |
+#include <string> |
+ |
+#include "base/basictypes.h" |
+#include "base/compiler_specific.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "chrome/browser/policy/device_management_backend.h" |
+#include "third_party/protobuf/src/google/protobuf/repeated_field.h" |
+ |
+namespace policy { |
+ |
+class DeviceManagementService; |
+ |
+// Interacts with the DMServer and determines whether this machine should |
Mattias Nissler (ping if slow)
2011/12/09 15:40:52
nit: I prefer "device management service" over "DM
Joao da Silva
2011/12/09 17:26:06
Done (here and elsewhere too).
|
+// automatically enter the Enterprise Enrollment screen during OOBE. |
+class AutoEnrollmentClient |
+ : public DeviceManagementBackend::DeviceAutoEnrollmentResponseDelegate { |
+ public: |
+ class Delegate { |
+ public: |
+ virtual ~Delegate(); |
+ // Invoked when the auto-enrollment protocol completes. It's safe to |
+ // delete this object during this callback. |
+ virtual void OnAutoEnrollmentComplete(AutoEnrollmentClient* client) = 0; |
Mattias Nissler (ping if slow)
2011/12/09 15:40:52
Any reason you decided for a full-blown delegate i
Joao da Silva
2011/12/09 17:26:06
No particular reason. Changed to use a callback si
|
+ }; |
+ |
+ // |delegate|, if not NULL, will be notified of completion of the protocol |
+ // after Start() is invoked. It must outlive this object. |
+ // Takes ownership of |device_management_service|. |
+ // |power_initial| and |power_limit| are exponents of power-of-2 values which |
+ // will be the initial modulus and the maximum modulus used by this client. |
+ AutoEnrollmentClient(Delegate* delegate, |
+ DeviceManagementService* device_management_service, |
+ const std::string& serial_number, |
+ int power_initial, |
+ int power_limit); |
+ virtual ~AutoEnrollmentClient(); |
+ |
+ // Convenience method to create instances of this class. |
+ static AutoEnrollmentClient* Create(Delegate* delegate); |
+ |
+ // Starts the auto-enrollment check protocol with the DMServer. Subsequent |
+ // calls drop any previous requests. Notice that this call can notify the |
+ // delegate if errors occur. |
+ void Start(); |
+ |
+ // Returns true if the protocol completed successfully and determined that |
+ // this device should do enterprise enrollment. |
+ bool should_auto_enroll() const { return should_auto_enroll_; } |
+ |
+ // Returns the device_id randomly generated for the auto-enrollment requests. |
+ // It can be reused for subsequent DMServer requests. |
+ std::string device_id() const { return device_id_; } |
+ |
+ private: |
+ // Sends an auto-enrollment check request to the DMServer. |power| is the |
+ // power of the power-of-2 to use as a modulus for this request. |
+ void SendRequest(int power); |
+ |
+ // Implementation of DeviceAutoEnrollmentResponseDelegate: |
+ virtual void HandleAutoEnrollmentResponse( |
+ const em::DeviceAutoEnrollmentResponse& response) OVERRIDE; |
+ virtual void OnError(DeviceManagementBackend::ErrorCode code) OVERRIDE; |
+ |
+ // Returns true if |serial_number_hash_| is contained in |hashes|. |
+ bool IsSerialInProtobuf( |
+ const google::protobuf::RepeatedPtrField<std::string>& hashes); |
+ |
+ // Delegate to notify. Weak pointer, and may be NULL. |
+ Delegate* delegate_; |
+ |
+ // Whether to auto-enroll or not. This is reset by calls to Start(), and only |
+ // turns true if the protocol and the serial number check succeed. |
+ bool should_auto_enroll_; |
+ |
+ // Randomly generated device id for the auto-enrollment requests. |
+ std::string device_id_; |
+ |
+ // SHA256 hash of the device's serial number. Empty if the serial couldn't be |
+ // retrieved. |
+ std::string serial_number_hash_; |
+ |
+ // Power of the power-of-2 modulus used in the initial auto-enrollment |
+ // request. |
+ int power_initial_; |
+ |
+ // Power of the maximum power-of-2 modulus that this client will accept from |
+ // a retry response from the server. |
+ int power_limit_; |
+ |
+ // Modulus used in the last request sent to the server. |
+ // Used to determine if the server is asking for the same modulus. |
+ int last_power_used_; |
+ |
+ // Used to communicate with the DMServer. |
Mattias Nissler (ping if slow)
2011/12/09 15:40:52
nit: DMServer vs. device management service
Joao da Silva
2011/12/09 17:26:06
Done.
|
+ scoped_ptr<DeviceManagementService> device_management_service_; |
+ scoped_ptr<DeviceManagementBackend> device_management_backend_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AutoEnrollmentClient); |
+}; |
+ |
+} // namespace policy |
+ |
+#endif // CHROME_BROWSER_POLICY_AUTO_ENROLLMENT_CLIENT_H_ |