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

Side by Side Diff: chrome/browser/policy/auto_enrollment_client.h

Issue 8872032: Added the AutoEnrollmentClient and unit tests for it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use callback instead of Delegate, using InSequence, renamed switches, cleanups Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/callback.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "chrome/browser/policy/device_management_backend.h"
16 #include "third_party/protobuf/src/google/protobuf/repeated_field.h"
17
18 namespace policy {
19
20 class DeviceManagementService;
21
22 // Interacts with the device management service and determines whether this
23 // machine should automatically enter the Enterprise Enrollment screen during
24 // OOBE.
25 class AutoEnrollmentClient
26 : public DeviceManagementBackend::DeviceAutoEnrollmentResponseDelegate {
27 public:
28 // |completion_callback| will be invoked on completion of the protocol, after
29 // Start() is invoked.
30 // Takes ownership of |device_management_service|.
31 // |power_initial| and |power_limit| are exponents of power-of-2 values which
32 // will be the initial modulus and the maximum modulus used by this client.
33 AutoEnrollmentClient(const base::Closure& completion_callback,
34 DeviceManagementService* device_management_service,
35 const std::string& serial_number,
36 int power_initial,
37 int power_limit);
38 virtual ~AutoEnrollmentClient();
39
40 // Convenience method to create instances of this class.
41 static AutoEnrollmentClient* Create(const base::Closure& completion_callback);
42
43 // Starts the auto-enrollment check protocol with the device management
44 // service. Subsequent calls drop any previous requests. Notice that this
45 // call can invoke the |completion_callback_| if errors occur.
46 void Start();
47
48 // Returns true if the protocol completed successfully and determined that
49 // this device should do enterprise enrollment.
50 bool should_auto_enroll() const { return should_auto_enroll_; }
51
52 // Returns the device_id randomly generated for the auto-enrollment requests.
53 // It can be reused for subsequent requests to the device management service.
54 std::string device_id() const { return device_id_; }
55
56 private:
57 // Sends an auto-enrollment check request to the device management service.
58 // |power| is the power of the power-of-2 to use as a modulus for this
59 // request.
60 void SendRequest(int power);
61
62 // Implementation of DeviceAutoEnrollmentResponseDelegate:
63 virtual void HandleAutoEnrollmentResponse(
64 const em::DeviceAutoEnrollmentResponse& response) OVERRIDE;
65 virtual void OnError(DeviceManagementBackend::ErrorCode code) OVERRIDE;
66
67 // Returns true if |serial_number_hash_| is contained in |hashes|.
68 bool IsSerialInProtobuf(
69 const google::protobuf::RepeatedPtrField<std::string>& hashes);
70
71 // Callback to invoke when the protocol completes.
72 base::Closure completion_callback_;
73
74 // Whether to auto-enroll or not. This is reset by calls to Start(), and only
75 // turns true if the protocol and the serial number check succeed.
76 bool should_auto_enroll_;
77
78 // Randomly generated device id for the auto-enrollment requests.
79 std::string device_id_;
80
81 // SHA256 hash of the device's serial number. Empty if the serial couldn't be
82 // retrieved.
83 std::string serial_number_hash_;
84
85 // Power of the power-of-2 modulus used in the initial auto-enrollment
86 // request.
87 int power_initial_;
88
89 // Power of the maximum power-of-2 modulus that this client will accept from
90 // a retry response from the server.
91 int power_limit_;
92
93 // Modulus used in the last request sent to the server.
94 // Used to determine if the server is asking for the same modulus.
95 int last_power_used_;
96
97 // Used to communicate with the device management service.
98 scoped_ptr<DeviceManagementService> device_management_service_;
99 scoped_ptr<DeviceManagementBackend> device_management_backend_;
100
101 DISALLOW_COPY_AND_ASSIGN(AutoEnrollmentClient);
102 };
103
104 } // namespace policy
105
106 #endif // CHROME_BROWSER_POLICY_AUTO_ENROLLMENT_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698