1 // Copyright 2013 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 #include "chrome/browser/chromeos/login/managed/supervised_user_login_flow.h"
7 #include "base/file_util.h"
8 #include "base/files/file_path.h"
9 #include "base/logging.h"
10 #include "base/prefs/pref_registry_simple.h"
11 #include "base/prefs/pref_service.h"
12 #include "base/threading/sequenced_worker_pool.h"
13 #include "base/values.h"
14 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
15 #include "chrome/browser/chromeos/login/login_utils.h"
16 #include "chrome/browser/chromeos/login/managed/locally_managed_user_constants.h"
17 #include "chrome/browser/chromeos/login/managed/locally_managed_user_creation_screen.h"
18 #include "chrome/browser/chromeos/login/user_manager.h"
19 #include "chrome/browser/chromeos/login/wizard_controller.h"
20 #include "chrome/browser/chromeos/profiles/profile_helper.h"
21 #include "chrome/browser/managed_mode/managed_user_service.h"
22 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
23 #include "content/public/browser/browser_thread.h"
25 using content::BrowserThread;
31 std::string LoadSyncToken(base::FilePath profile_dir) {
33 base::FilePath token_file =
34 profile_dir.Append(kManagedUserTokenFilename);
35 VLOG(1) << "Loading" << token_file.value();
36 if (!base::ReadFileToString(token_file, &token)) {
44 SupervisedUserLoginFlow::SupervisedUserLoginFlow(
45 const std::string& user_id)
46 : ExtendedUserFlow(user_id),
51 SupervisedUserLoginFlow::~SupervisedUserLoginFlow() {}
53 bool SupervisedUserLoginFlow::CanLockScreen() {
57 bool SupervisedUserLoginFlow::ShouldLaunchBrowser() {
61 bool SupervisedUserLoginFlow::ShouldSkipPostLoginScreens() {
65 bool SupervisedUserLoginFlow::HandleLoginFailure(
66 const LoginFailure& failure) {
70 bool SupervisedUserLoginFlow::HandlePasswordChangeDetected() {
74 void SupervisedUserLoginFlow::HandleOAuthTokenStatusChange(
75 User::OAuthTokenStatus status) {
78 void SupervisedUserLoginFlow::OnSyncSetupDataLoaded(
79 const std::string& token) {
80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
84 void SupervisedUserLoginFlow::ConfigureSync(const std::string& token) {
86 // TODO(antrim): add error handling (no token loaded).
87 // See also: http://crbug.com/312751
89 ManagedUserServiceFactory::GetForProfile(profile_)->InitSync(token);
91 LoginUtils::Get()->DoBrowserLaunch(profile_, host());
96 void SupervisedUserLoginFlow::LaunchExtraSteps(
99 base::FilePath profile_dir = ProfileHelper::GetProfilePathByUserIdHash(
100 UserManager::Get()->GetUserByProfile(profile)->username_hash());
101 PostTaskAndReplyWithResult(
102 content::BrowserThread::GetBlockingPool(),
104 base::Bind(&LoadSyncToken, profile_dir),
106 &SupervisedUserLoginFlow::OnSyncSetupDataLoaded,
107 weak_factory_.GetWeakPtr()));
110 } // namespace chromeos