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

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

Issue 12189011: Split up chrome/browser/policy subdirectory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, add chrome/browser/chromeos/policy/OWNERS Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_AUTO_ENROLLMENT_CLIENT_H_
6 #define CHROME_BROWSER_POLICY_AUTO_ENROLLMENT_CLIENT_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/time.h"
15 #include "chrome/browser/policy/cloud_policy_constants.h"
16 #include "third_party/protobuf/src/google/protobuf/repeated_field.h"
17
18 class PrefService;
19 class PrefRegistrySimple;
20
21 namespace enterprise_management {
22 class DeviceManagementResponse;
23 }
24
25 namespace policy {
26
27 class DeviceManagementRequestJob;
28 class DeviceManagementService;
29
30 // Interacts with the device management service and determines whether this
31 // machine should automatically enter the Enterprise Enrollment screen during
32 // OOBE.
33 class AutoEnrollmentClient {
34 public:
35 // |completion_callback| will be invoked on completion of the protocol, after
36 // Start() is invoked.
37 // Takes ownership of |device_management_service|.
38 // The result of the protocol will be cached in |local_state|.
39 // |power_initial| and |power_limit| are exponents of power-of-2 values which
40 // will be the initial modulus and the maximum modulus used by this client.
41 AutoEnrollmentClient(const base::Closure& completion_callback,
42 DeviceManagementService* device_management_service,
43 PrefService* local_state,
44 const std::string& serial_number,
45 int power_initial,
46 int power_limit);
47 virtual ~AutoEnrollmentClient();
48
49 // Registers preferences in local state.
50 static void RegisterPrefs(PrefRegistrySimple* registry);
51
52 // Returns true if auto-enrollment is disabled in this device. In that case,
53 // instances returned by Create() fail immediately once Start() is invoked.
54 static bool IsDisabled();
55
56 // Convenience method to create instances of this class.
57 static AutoEnrollmentClient* Create(const base::Closure& completion_callback);
58
59 // Cancels auto-enrollment.
60 // This function does not interrupt a running auto-enrollment check. It only
61 // stores a pref in |local_state| that prevents the client from entering
62 // auto-enrollment mode for the future.
63 static void CancelAutoEnrollment();
64
65 // Starts the auto-enrollment check protocol with the device management
66 // service. Subsequent calls drop any previous requests. Notice that this
67 // call can invoke the |completion_callback_| if errors occur.
68 void Start();
69
70 // Cancels any pending requests. |completion_callback_| will not be invoked.
71 // |this| will delete itself.
72 void CancelAndDeleteSoon();
73
74 // Returns true if the protocol completed successfully and determined that
75 // this device should do enterprise enrollment.
76 bool should_auto_enroll() const { return should_auto_enroll_; }
77
78 // Returns the device_id randomly generated for the auto-enrollment requests.
79 // It can be reused for subsequent requests to the device management service.
80 std::string device_id() const { return device_id_; }
81
82 private:
83 // Tries to load the result of a previous execution of the protocol from
84 // local state. Returns true if that decision has been made and is valid.
85 bool GetCachedDecision();
86
87 // Sends an auto-enrollment check request to the device management service.
88 // |power| is the power of the power-of-2 to use as a modulus for this
89 // request.
90 void SendRequest(int power);
91
92 // Handles auto-enrollment request completion.
93 void OnRequestCompletion(
94 DeviceManagementStatus status,
95 const enterprise_management::DeviceManagementResponse& response);
96
97 // Returns true if |serial_number_hash_| is contained in |hashes|.
98 bool IsSerialInProtobuf(
99 const google::protobuf::RepeatedPtrField<std::string>& hashes);
100
101 // Invoked when the protocol completes. This invokes the callback and records
102 // some UMA metrics.
103 void OnProtocolDone();
104
105 // Callback to invoke when the protocol completes.
106 base::Closure completion_callback_;
107
108 // Whether to auto-enroll or not. This is reset by calls to Start(), and only
109 // turns true if the protocol and the serial number check succeed.
110 bool should_auto_enroll_;
111
112 // Randomly generated device id for the auto-enrollment requests.
113 std::string device_id_;
114
115 // SHA256 hash of the device's serial number. Empty if the serial couldn't be
116 // retrieved.
117 std::string serial_number_hash_;
118
119 // Power of the power-of-2 modulus used in the initial auto-enrollment
120 // request.
121 int power_initial_;
122
123 // Power of the maximum power-of-2 modulus that this client will accept from
124 // a retry response from the server.
125 int power_limit_;
126
127 // Number of requests sent to the server so far.
128 // Used to determine if the server keeps asking for different moduli.
129 int requests_sent_;
130
131 // Used to communicate with the device management service.
132 scoped_ptr<DeviceManagementService> device_management_service_;
133 scoped_ptr<DeviceManagementRequestJob> request_job_;
134
135 // PrefService where the protocol's results are cached.
136 PrefService* local_state_;
137
138 // Times used to determine the duration of the protocol, and the extra time
139 // needed to complete after the signin was complete.
140 // If |time_start_| is not null, the protocol is still running.
141 // If |time_extra_start_| is not null, the protocol is still running but our
142 // owner has relinquished ownership.
143 base::Time time_start_;
144 base::Time time_extra_start_;
145
146 DISALLOW_COPY_AND_ASSIGN(AutoEnrollmentClient);
147 };
148
149 } // namespace policy
150
151 #endif // CHROME_BROWSER_POLICY_AUTO_ENROLLMENT_CLIENT_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/app_pack_updater.cc ('k') | chrome/browser/policy/auto_enrollment_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698