Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / managed / supervised_user_login_flow.cc
blob27c81e260f8b40a5e8019d677100e2f7169ae665
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;
27 namespace chromeos {
29 namespace {
31 std::string LoadSyncToken(base::FilePath profile_dir) {
32 std::string token;
33 base::FilePath token_file =
34 profile_dir.Append(kManagedUserTokenFilename);
35 VLOG(1) << "Loading" << token_file.value();
36 if (!base::ReadFileToString(token_file, &token)) {
37 return std::string();
39 return token;
42 } // namespace
44 SupervisedUserLoginFlow::SupervisedUserLoginFlow(
45 const std::string& user_id)
46 : ExtendedUserFlow(user_id),
47 data_loaded_(false),
48 weak_factory_(this) {
51 SupervisedUserLoginFlow::~SupervisedUserLoginFlow() {}
53 bool SupervisedUserLoginFlow::ShouldLaunchBrowser() {
54 return data_loaded_;
57 bool SupervisedUserLoginFlow::ShouldSkipPostLoginScreens() {
58 return true;
61 bool SupervisedUserLoginFlow::HandleLoginFailure(
62 const LoginFailure& failure) {
63 return false;
66 bool SupervisedUserLoginFlow::HandlePasswordChangeDetected() {
67 return false;
70 void SupervisedUserLoginFlow::HandleOAuthTokenStatusChange(
71 User::OAuthTokenStatus status) {
74 void SupervisedUserLoginFlow::OnSyncSetupDataLoaded(
75 const std::string& token) {
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
77 ConfigureSync(token);
80 void SupervisedUserLoginFlow::ConfigureSync(const std::string& token) {
81 data_loaded_ = true;
82 // TODO(antrim): add error handling (no token loaded).
83 // See also: http://crbug.com/312751
84 if (!token.empty())
85 ManagedUserServiceFactory::GetForProfile(profile_)->InitSync(token);
87 LoginUtils::Get()->DoBrowserLaunch(profile_, host());
88 profile_ = NULL;
89 UnregisterFlowSoon();
92 void SupervisedUserLoginFlow::LaunchExtraSteps(
93 Profile* profile) {
94 profile_ = profile;
95 base::FilePath profile_dir = ProfileHelper::GetProfilePathByUserIdHash(
96 UserManager::Get()->GetUserByProfile(profile)->username_hash());
97 PostTaskAndReplyWithResult(
98 content::BrowserThread::GetBlockingPool(),
99 FROM_HERE,
100 base::Bind(&LoadSyncToken, profile_dir),
101 base::Bind(
102 &SupervisedUserLoginFlow::OnSyncSetupDataLoaded,
103 weak_factory_.GetWeakPtr()));
106 } // namespace chromeos