OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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_AUTO_ENROLLMENT_CLIENT_H_ | |
6 #define CHROME_BROWSER_POLICY_AUTO_ENROLLMENT_CLIENT_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/compiler_specific.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "chrome/browser/policy/device_management_backend.h" | |
15 #include "third_party/protobuf/src/google/protobuf/repeated_field.h" | |
16 | |
17 namespace policy { | |
18 | |
19 class DeviceManagementService; | |
20 | |
21 // 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).
| |
22 // automatically enter the Enterprise Enrollment screen during OOBE. | |
23 class AutoEnrollmentClient | |
24 : public DeviceManagementBackend::DeviceAutoEnrollmentResponseDelegate { | |
25 public: | |
26 class Delegate { | |
27 public: | |
28 virtual ~Delegate(); | |
29 // Invoked when the auto-enrollment protocol completes. It's safe to | |
30 // delete this object during this callback. | |
31 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
| |
32 }; | |
33 | |
34 // |delegate|, if not NULL, will be notified of completion of the protocol | |
35 // after Start() is invoked. It must outlive this object. | |
36 // Takes ownership of |device_management_service|. | |
37 // |power_initial| and |power_limit| are exponents of power-of-2 values which | |
38 // will be the initial modulus and the maximum modulus used by this client. | |
39 AutoEnrollmentClient(Delegate* delegate, | |
40 DeviceManagementService* device_management_service, | |
41 const std::string& serial_number, | |
42 int power_initial, | |
43 int power_limit); | |
44 virtual ~AutoEnrollmentClient(); | |
45 | |
46 // Convenience method to create instances of this class. | |
47 static AutoEnrollmentClient* Create(Delegate* delegate); | |
48 | |
49 // Starts the auto-enrollment check protocol with the DMServer. Subsequent | |
50 // calls drop any previous requests. Notice that this call can notify the | |
51 // delegate if errors occur. | |
52 void Start(); | |
53 | |
54 // Returns true if the protocol completed successfully and determined that | |
55 // this device should do enterprise enrollment. | |
56 bool should_auto_enroll() const { return should_auto_enroll_; } | |
57 | |
58 // Returns the device_id randomly generated for the auto-enrollment requests. | |
59 // It can be reused for subsequent DMServer requests. | |
60 std::string device_id() const { return device_id_; } | |
61 | |
62 private: | |
63 // Sends an auto-enrollment check request to the DMServer. |power| is the | |
64 // power of the power-of-2 to use as a modulus for this request. | |
65 void SendRequest(int power); | |
66 | |
67 // Implementation of DeviceAutoEnrollmentResponseDelegate: | |
68 virtual void HandleAutoEnrollmentResponse( | |
69 const em::DeviceAutoEnrollmentResponse& response) OVERRIDE; | |
70 virtual void OnError(DeviceManagementBackend::ErrorCode code) OVERRIDE; | |
71 | |
72 // Returns true if |serial_number_hash_| is contained in |hashes|. | |
73 bool IsSerialInProtobuf( | |
74 const google::protobuf::RepeatedPtrField<std::string>& hashes); | |
75 | |
76 // Delegate to notify. Weak pointer, and may be NULL. | |
77 Delegate* delegate_; | |
78 | |
79 // Whether to auto-enroll or not. This is reset by calls to Start(), and only | |
80 // turns true if the protocol and the serial number check succeed. | |
81 bool should_auto_enroll_; | |
82 | |
83 // Randomly generated device id for the auto-enrollment requests. | |
84 std::string device_id_; | |
85 | |
86 // SHA256 hash of the device's serial number. Empty if the serial couldn't be | |
87 // retrieved. | |
88 std::string serial_number_hash_; | |
89 | |
90 // Power of the power-of-2 modulus used in the initial auto-enrollment | |
91 // request. | |
92 int power_initial_; | |
93 | |
94 // Power of the maximum power-of-2 modulus that this client will accept from | |
95 // a retry response from the server. | |
96 int power_limit_; | |
97 | |
98 // Modulus used in the last request sent to the server. | |
99 // Used to determine if the server is asking for the same modulus. | |
100 int last_power_used_; | |
101 | |
102 // 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.
| |
103 scoped_ptr<DeviceManagementService> device_management_service_; | |
104 scoped_ptr<DeviceManagementBackend> device_management_backend_; | |
105 | |
106 DISALLOW_COPY_AND_ASSIGN(AutoEnrollmentClient); | |
107 }; | |
108 | |
109 } // namespace policy | |
110 | |
111 #endif // CHROME_BROWSER_POLICY_AUTO_ENROLLMENT_CLIENT_H_ | |
OLD | NEW |