ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / chromeos / login / enrollment / auto_enrollment_controller.h
blobe10100f72e7116099cdd8284f7ef76bf170b712c
1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_AUTO_ENROLLMENT_CONTROLLER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_AUTO_ENROLLMENT_CONTROLLER_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback_list.h"
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/timer/timer.h"
16 #include "chrome/browser/chromeos/policy/auto_enrollment_client.h"
17 #include "chrome/browser/chromeos/settings/device_settings_service.h"
19 namespace policy {
20 class ServerBackedStateKeysBroker;
23 namespace chromeos {
25 // Drives the auto-enrollment check, running an AutoEnrollmentClient if
26 // appropriate to make a decision.
27 class AutoEnrollmentController {
28 public:
29 typedef base::CallbackList<void(policy::AutoEnrollmentState)>
30 ProgressCallbackList;
32 // Parameter values for the kEnterpriseEnableForcedReEnrollment flag.
33 static const char kForcedReEnrollmentAlways[];
34 static const char kForcedReEnrollmentNever[];
35 static const char kForcedReEnrollmentOfficialBuild[];
37 // Auto-enrollment modes.
38 enum Mode {
39 // No automatic enrollment.
40 MODE_NONE,
41 // Forced re-enrollment.
42 MODE_FORCED_RE_ENROLLMENT,
45 // Gets the auto-enrollment mode based on command-line flags and official
46 // build status.
47 static Mode GetMode();
49 AutoEnrollmentController();
50 ~AutoEnrollmentController();
52 // Starts the auto-enrollment check.
53 void Start();
55 // Stops any pending auto-enrollment checking.
56 void Cancel();
58 // Retry checking.
59 void Retry();
61 // Registers a callback to invoke on state changes.
62 scoped_ptr<ProgressCallbackList::Subscription> RegisterProgressCallback(
63 const ProgressCallbackList::CallbackType& callback);
65 policy::AutoEnrollmentState state() const { return state_; }
67 private:
68 // Callback for the ownership status check.
69 void OnOwnershipStatusCheckDone(
70 DeviceSettingsService::OwnershipStatus status);
72 // Starts the auto-enrollment client.
73 void StartClient(const std::vector<std::string>& state_keys);
75 // Sets |state_| and notifies |progress_callbacks_|.
76 void UpdateState(policy::AutoEnrollmentState state);
78 // Handles timeout of the safeguard timer and stops waiting for a result.
79 void Timeout();
81 policy::AutoEnrollmentState state_;
82 ProgressCallbackList progress_callbacks_;
84 scoped_ptr<policy::AutoEnrollmentClient> client_;
86 // This timer acts as a belt-and-suspenders safety for the case where one of
87 // the asynchronous steps required to make the auto-enrollment decision
88 // doesn't come back. Even though in theory they should all terminate, better
89 // safe than sorry: There are DBus interactions, an entire network stack etc.
90 // - just too many moving pieces to be confident there are no bugs. If
91 // something goes wrong, the timer will ensure that a decision gets made
92 // eventually, which is crucial to not block OOBE forever. See
93 // http://crbug.com/433634 for background.
94 base::Timer safeguard_timer_;
96 base::WeakPtrFactory<AutoEnrollmentController> client_start_weak_factory_;
98 DISALLOW_COPY_AND_ASSIGN(AutoEnrollmentController);
101 } // namespace chromeos
103 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_AUTO_ENROLLMENT_CONTROLLER_H_