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 "base/callback_list.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/chromeos/policy/auto_enrollment_client.h"
13 #include "chrome/browser/chromeos/settings/device_settings_service.h"
17 // Drives the auto-enrollment check, running an AutoEnrollmentClient if
18 // appropriate to make a decision.
19 class AutoEnrollmentController {
21 typedef base::CallbackList<void(policy::AutoEnrollmentState)>
24 // Parameter values for the kEnterpriseEnableForcedReEnrollment flag.
25 static const char kForcedReEnrollmentAlways[];
26 static const char kForcedReEnrollmentLegacy[];
27 static const char kForcedReEnrollmentNever[];
28 static const char kForcedReEnrollmentOfficialBuild[];
30 // Auto-enrollment modes.
32 // No automatic enrollment.
34 // Legacy auto-enrollment.
35 MODE_LEGACY_AUTO_ENROLLMENT,
36 // Forced re-enrollment.
37 MODE_FORCED_RE_ENROLLMENT,
40 // Gets the auto-enrollment mode based on command-line flags and official
42 static Mode GetMode();
44 AutoEnrollmentController();
45 ~AutoEnrollmentController();
47 // Starts the auto-enrollment check.
50 // Stops any pending auto-enrollment checking.
56 // Registers a callback to invoke on state changes.
57 scoped_ptr<ProgressCallbackList::Subscription> RegisterProgressCallback(
58 const ProgressCallbackList::CallbackType& callback);
60 // Checks whether legacy auto-enrollment should be performed.
61 bool ShouldEnrollSilently();
63 policy::AutoEnrollmentState state() const { return state_; }
66 // Callback for the ownership status check.
67 void OnOwnershipStatusCheckDone(
68 DeviceSettingsService::OwnershipStatus status);
70 // Sets |state_| and notifies |progress_callbacks_|.
71 void UpdateState(policy::AutoEnrollmentState state);
73 policy::AutoEnrollmentState state_;
74 ProgressCallbackList progress_callbacks_;
76 base::WeakPtrFactory<AutoEnrollmentController> weak_factory_;
78 scoped_ptr<policy::AutoEnrollmentClient> client_;
80 DISALLOW_COPY_AND_ASSIGN(AutoEnrollmentController);
83 } // namespace chromeos
85 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_ENROLLMENT_AUTO_ENROLLMENT_CONTROLLER_H_