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 "chrome/browser/chromeos/policy/auto_enrollment_client.h"
16 #include "chrome/browser/chromeos/settings/device_settings_service.h"
19 class ServerBackedStateKeysBroker;
24 // Drives the auto-enrollment check, running an AutoEnrollmentClient if
25 // appropriate to make a decision.
26 class AutoEnrollmentController {
28 typedef base::CallbackList<void(policy::AutoEnrollmentState)>
31 // Parameter values for the kEnterpriseEnableForcedReEnrollment flag.
32 static const char kForcedReEnrollmentAlways[];
33 static const char kForcedReEnrollmentLegacy[];
34 static const char kForcedReEnrollmentNever[];
35 static const char kForcedReEnrollmentOfficialBuild[];
37 // Auto-enrollment modes.
39 // No automatic enrollment.
41 // Legacy auto-enrollment.
42 MODE_LEGACY_AUTO_ENROLLMENT,
43 // Forced re-enrollment.
44 MODE_FORCED_RE_ENROLLMENT,
47 // Gets the auto-enrollment mode based on command-line flags and official
49 static Mode GetMode();
51 AutoEnrollmentController();
52 ~AutoEnrollmentController();
54 // Starts the auto-enrollment check.
57 // Stops any pending auto-enrollment checking.
63 // Registers a callback to invoke on state changes.
64 scoped_ptr<ProgressCallbackList::Subscription> RegisterProgressCallback(
65 const ProgressCallbackList::CallbackType& callback);
67 // Checks whether legacy auto-enrollment should be performed.
68 bool ShouldEnrollSilently();
70 policy::AutoEnrollmentState state() const { return state_; }
73 // Callback for the ownership status check.
74 void OnOwnershipStatusCheckDone(
75 DeviceSettingsService::OwnershipStatus status);
77 // Starts the auto-enrollment client.
78 void StartClient(const std::vector<std::string>& state_keys);
80 // Sets |state_| and notifies |progress_callbacks_|.
81 void UpdateState(policy::AutoEnrollmentState state);
83 policy::AutoEnrollmentState state_;
84 ProgressCallbackList progress_callbacks_;
86 base::WeakPtrFactory<AutoEnrollmentController> client_start_weak_factory_;
88 scoped_ptr<policy::AutoEnrollmentClient> client_;
90 DISALLOW_COPY_AND_ASSIGN(AutoEnrollmentController);
93 } // namespace chromeos
95 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_AUTO_ENROLLMENT_CONTROLLER_H_