Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / chromeos / login / enrollment / auto_enrollment_controller.h
blobcb87758d04241fe7c4c5dbcfc6d2252a8af92911
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 forced re-enrollment check (for historical reasons called
26 // auto-enrollment check), running an AutoEnrollmentClient if appropriate to
27 // make a decision.
28 class AutoEnrollmentController {
29 public:
30 typedef base::CallbackList<void(policy::AutoEnrollmentState)>
31 ProgressCallbackList;
33 // Parameter values for the kEnterpriseEnableForcedReEnrollment flag.
34 static const char kForcedReEnrollmentAlways[];
35 static const char kForcedReEnrollmentNever[];
36 static const char kForcedReEnrollmentOfficialBuild[];
38 // Auto-enrollment modes.
39 enum Mode {
40 // No automatic enrollment.
41 MODE_NONE,
42 // Forced re-enrollment.
43 MODE_FORCED_RE_ENROLLMENT,
46 // Gets the auto-enrollment mode based on command-line flags and official
47 // build status.
48 static Mode GetMode();
50 AutoEnrollmentController();
51 ~AutoEnrollmentController();
53 // Starts the auto-enrollment check.
54 void Start();
56 // Stops any pending auto-enrollment checking.
57 void Cancel();
59 // Retry checking.
60 void Retry();
62 // Registers a callback to invoke on state changes.
63 scoped_ptr<ProgressCallbackList::Subscription> RegisterProgressCallback(
64 const ProgressCallbackList::CallbackType& callback);
66 policy::AutoEnrollmentState state() const { return state_; }
68 private:
69 // Callback for the ownership status check.
70 void OnOwnershipStatusCheckDone(
71 DeviceSettingsService::OwnershipStatus status);
73 // Starts the auto-enrollment client.
74 void StartClient(const std::vector<std::string>& state_keys);
76 // Sets |state_| and notifies |progress_callbacks_|.
77 void UpdateState(policy::AutoEnrollmentState state);
79 // Handles timeout of the safeguard timer and stops waiting for a result.
80 void Timeout();
82 policy::AutoEnrollmentState state_;
83 ProgressCallbackList progress_callbacks_;
85 scoped_ptr<policy::AutoEnrollmentClient> client_;
87 // This timer acts as a belt-and-suspenders safety for the case where one of
88 // the asynchronous steps required to make the auto-enrollment decision
89 // doesn't come back. Even though in theory they should all terminate, better
90 // safe than sorry: There are DBus interactions, an entire network stack etc.
91 // - just too many moving pieces to be confident there are no bugs. If
92 // something goes wrong, the timer will ensure that a decision gets made
93 // eventually, which is crucial to not block OOBE forever. See
94 // http://crbug.com/433634 for background.
95 base::Timer safeguard_timer_;
97 base::WeakPtrFactory<AutoEnrollmentController> client_start_weak_factory_;
99 DISALLOW_COPY_AND_ASSIGN(AutoEnrollmentController);
102 } // namespace chromeos
104 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_AUTO_ENROLLMENT_CONTROLLER_H_