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::ShouldLaunchBrowser() {
57 bool SupervisedUserLoginFlow::ShouldSkipPostLoginScreens() {
61 bool SupervisedUserLoginFlow::HandleLoginFailure(
62 const LoginFailure
& failure
) {
66 bool SupervisedUserLoginFlow::HandlePasswordChangeDetected() {
70 void SupervisedUserLoginFlow::HandleOAuthTokenStatusChange(
71 User::OAuthTokenStatus status
) {
74 void SupervisedUserLoginFlow::OnSyncSetupDataLoaded(
75 const std::string
& token
) {
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
80 void SupervisedUserLoginFlow::ConfigureSync(const std::string
& token
) {
82 // TODO(antrim): add error handling (no token loaded).
83 // See also: http://crbug.com/312751
85 ManagedUserServiceFactory::GetForProfile(profile_
)->InitSync(token
);
87 LoginUtils::Get()->DoBrowserLaunch(profile_
, host());
92 void SupervisedUserLoginFlow::LaunchExtraSteps(
95 base::FilePath profile_dir
= ProfileHelper::GetProfilePathByUserIdHash(
96 UserManager::Get()->GetUserByProfile(profile
)->username_hash());
97 PostTaskAndReplyWithResult(
98 content::BrowserThread::GetBlockingPool(),
100 base::Bind(&LoadSyncToken
, profile_dir
),
102 &SupervisedUserLoginFlow::OnSyncSetupDataLoaded
,
103 weak_factory_
.GetWeakPtr()));
106 } // namespace chromeos