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_
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"
20 class ServerBackedStateKeysBroker
;
25 // Drives the auto-enrollment check, running an AutoEnrollmentClient if
26 // appropriate to make a decision.
27 class AutoEnrollmentController
{
29 typedef base::CallbackList
<void(policy::AutoEnrollmentState
)>
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.
39 // No automatic enrollment.
41 // Forced re-enrollment.
42 MODE_FORCED_RE_ENROLLMENT
,
45 // Gets the auto-enrollment mode based on command-line flags and official
47 static Mode
GetMode();
49 AutoEnrollmentController();
50 ~AutoEnrollmentController();
52 // Starts the auto-enrollment check.
55 // Stops any pending auto-enrollment checking.
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_
; }
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.
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_