Upstream version 5.34.104.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/logging.h"
8 #include "base/prefs/pref_registry_simple.h"
9 #include "base/prefs/pref_service.h"
10 #include "base/values.h"
11 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
12 #include "chrome/browser/chromeos/login/login_utils.h"
13 #include "chrome/browser/chromeos/login/managed/locally_managed_user_constants.h"
14 #include "chrome/browser/chromeos/login/managed/locally_managed_user_creation_screen.h"
15 #include "chrome/browser/chromeos/login/supervised_user_manager.h"
16 #include "chrome/browser/chromeos/login/user_manager.h"
17 #include "chrome/browser/chromeos/login/wizard_controller.h"
18 #include "content/public/browser/browser_thread.h"
19
20 using content::BrowserThread;
21
22 namespace chromeos {
23
24 SupervisedUserLoginFlow::SupervisedUserLoginFlow(
25     const std::string& user_id)
26     : ExtendedUserFlow(user_id),
27       data_loaded_(false),
28       weak_factory_(this) {
29 }
30
31 SupervisedUserLoginFlow::~SupervisedUserLoginFlow() {}
32
33 bool SupervisedUserLoginFlow::CanLockScreen() {
34   return true;
35 }
36
37 bool SupervisedUserLoginFlow::ShouldLaunchBrowser() {
38   return data_loaded_;
39 }
40
41 bool SupervisedUserLoginFlow::ShouldSkipPostLoginScreens() {
42   return true;
43 }
44
45 bool SupervisedUserLoginFlow::HandleLoginFailure(
46     const LoginFailure& failure) {
47   return false;
48 }
49
50 bool SupervisedUserLoginFlow::HandlePasswordChangeDetected() {
51   return false;
52 }
53
54 void SupervisedUserLoginFlow::HandleOAuthTokenStatusChange(
55     User::OAuthTokenStatus status) {
56 }
57
58 void SupervisedUserLoginFlow::OnSyncSetupDataLoaded(
59     const std::string& token) {
60   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
61   ConfigureSync(token);
62 }
63
64 void SupervisedUserLoginFlow::ConfigureSync(const std::string& token) {
65   data_loaded_ = true;
66
67   // TODO(antrim): add error handling (no token loaded).
68   // See also: http://crbug.com/312751
69   UserManager::Get()->GetSupervisedUserManager()->ConfigureSyncWithToken(
70       profile_, token);
71
72   LoginUtils::Get()->DoBrowserLaunch(profile_, host());
73   profile_ = NULL;
74   UnregisterFlowSoon();
75 }
76
77 void SupervisedUserLoginFlow::LaunchExtraSteps(
78     Profile* profile) {
79   profile_ = profile;
80   UserManager::Get()->GetSupervisedUserManager()->LoadSupervisedUserToken(
81       profile,
82       base::Bind(
83            &SupervisedUserLoginFlow::OnSyncSetupDataLoaded,
84            weak_factory_.GetWeakPtr()));
85 }
86
87 }  // namespace chromeos