Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / managed / supervised_user_login_flow.cc
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.
4
5 #include "chrome/browser/chromeos/login/managed/supervised_user_login_flow.h"
6
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"
24
25 using content::BrowserThread;
26
27 namespace chromeos {
28
29 namespace {
30
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();
38   }
39   return token;
40 }
41
42 } // namespace
43
44 SupervisedUserLoginFlow::SupervisedUserLoginFlow(
45     const std::string& user_id)
46     : ExtendedUserFlow(user_id),
47       data_loaded_(false),
48       weak_factory_(this) {
49 }
50
51 SupervisedUserLoginFlow::~SupervisedUserLoginFlow() {}
52
53 bool SupervisedUserLoginFlow::CanLockScreen() {
54   return true;
55 }
56
57 bool SupervisedUserLoginFlow::ShouldLaunchBrowser() {
58   return data_loaded_;
59 }
60
61 bool SupervisedUserLoginFlow::ShouldSkipPostLoginScreens() {
62   return true;
63 }
64
65 bool SupervisedUserLoginFlow::HandleLoginFailure(
66     const LoginFailure& failure) {
67   return false;
68 }
69
70 bool SupervisedUserLoginFlow::HandlePasswordChangeDetected() {
71   return false;
72 }
73
74 void SupervisedUserLoginFlow::HandleOAuthTokenStatusChange(
75     User::OAuthTokenStatus status) {
76 }
77
78 void SupervisedUserLoginFlow::OnSyncSetupDataLoaded(
79     const std::string& token) {
80   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
81   ConfigureSync(token);
82 }
83
84 void SupervisedUserLoginFlow::ConfigureSync(const std::string& token) {
85   data_loaded_ = true;
86   // TODO(antrim): add error handling (no token loaded).
87   // See also: http://crbug.com/312751
88   if (!token.empty())
89     ManagedUserServiceFactory::GetForProfile(profile_)->InitSync(token);
90
91   LoginUtils::Get()->DoBrowserLaunch(profile_, host());
92   profile_ = NULL;
93   UnregisterFlowSoon();
94 }
95
96 void SupervisedUserLoginFlow::LaunchExtraSteps(
97     Profile* profile) {
98   profile_ = profile;
99   base::FilePath profile_dir = ProfileHelper::GetProfilePathByUserIdHash(
100       UserManager::Get()->GetUserByProfile(profile)->username_hash());
101   PostTaskAndReplyWithResult(
102       content::BrowserThread::GetBlockingPool(),
103       FROM_HERE,
104       base::Bind(&LoadSyncToken, profile_dir),
105       base::Bind(
106            &SupervisedUserLoginFlow::OnSyncSetupDataLoaded,
107            weak_factory_.GetWeakPtr()));
108 }
109
110 }  // namespace chromeos