OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/login/managed/locally_managed_user_login_flow.
h" | 5 #include "chrome/browser/chromeos/login/managed/supervised_user_login_flow.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/chromeos/login/login_display_host_impl.h" | 14 #include "chrome/browser/chromeos/login/login_display_host_impl.h" |
15 #include "chrome/browser/chromeos/login/login_utils.h" | 15 #include "chrome/browser/chromeos/login/login_utils.h" |
16 #include "chrome/browser/chromeos/login/managed/locally_managed_user_constants.h
" | 16 #include "chrome/browser/chromeos/login/managed/locally_managed_user_constants.h
" |
17 #include "chrome/browser/chromeos/login/managed/locally_managed_user_creation_sc
reen.h" | 17 #include "chrome/browser/chromeos/login/managed/locally_managed_user_creation_sc
reen.h" |
| 18 #include "chrome/browser/chromeos/login/user_manager.h" |
18 #include "chrome/browser/chromeos/login/wizard_controller.h" | 19 #include "chrome/browser/chromeos/login/wizard_controller.h" |
19 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
20 #include "chrome/browser/managed_mode/managed_user_service.h" | 21 #include "chrome/browser/managed_mode/managed_user_service.h" |
21 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | 22 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
23 | 24 |
24 using content::BrowserThread; | 25 using content::BrowserThread; |
25 | 26 |
26 namespace chromeos { | 27 namespace chromeos { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 std::string LoadSyncToken(base::FilePath profile_dir) { | 31 std::string LoadSyncToken(base::FilePath profile_dir) { |
31 std::string token; | 32 std::string token; |
32 base::FilePath token_file = | 33 base::FilePath token_file = |
33 profile_dir.Append(kManagedUserTokenFilename); | 34 profile_dir.Append(kManagedUserTokenFilename); |
34 LOG(INFO) << "Loading" << token_file.value(); | 35 VLOG(1) << "Loading" << token_file.value(); |
35 if (!base::ReadFileToString(token_file, &token)) { | 36 if (!base::ReadFileToString(token_file, &token)) { |
36 return std::string(); | 37 return std::string(); |
37 } | 38 } |
38 return token; | 39 return token; |
39 } | 40 } |
40 | 41 |
41 } // namespace | 42 } // namespace |
42 | 43 |
43 LocallyManagedUserLoginFlow::LocallyManagedUserLoginFlow( | 44 SupervisedUserLoginFlow::SupervisedUserLoginFlow( |
44 const std::string& user_id) | 45 const std::string& user_id) |
45 : ExtendedUserFlow(user_id), | 46 : ExtendedUserFlow(user_id), |
46 data_loaded_(false), | 47 data_loaded_(false), |
47 weak_factory_(this) { | 48 weak_factory_(this) { |
48 } | 49 } |
49 | 50 |
50 LocallyManagedUserLoginFlow::~LocallyManagedUserLoginFlow() {} | 51 SupervisedUserLoginFlow::~SupervisedUserLoginFlow() {} |
51 | 52 |
52 bool LocallyManagedUserLoginFlow::ShouldLaunchBrowser() { | 53 bool SupervisedUserLoginFlow::ShouldLaunchBrowser() { |
53 return data_loaded_; | 54 return data_loaded_; |
54 } | 55 } |
55 | 56 |
56 bool LocallyManagedUserLoginFlow::ShouldSkipPostLoginScreens() { | 57 bool SupervisedUserLoginFlow::ShouldSkipPostLoginScreens() { |
57 return true; | 58 return true; |
58 } | 59 } |
59 | 60 |
60 bool LocallyManagedUserLoginFlow::HandleLoginFailure( | 61 bool SupervisedUserLoginFlow::HandleLoginFailure( |
61 const LoginFailure& failure) { | 62 const LoginFailure& failure) { |
62 return false; | 63 return false; |
63 } | 64 } |
64 | 65 |
65 bool LocallyManagedUserLoginFlow::HandlePasswordChangeDetected() { | 66 bool SupervisedUserLoginFlow::HandlePasswordChangeDetected() { |
66 return false; | 67 return false; |
67 } | 68 } |
68 | 69 |
69 void LocallyManagedUserLoginFlow::HandleOAuthTokenStatusChange( | 70 void SupervisedUserLoginFlow::HandleOAuthTokenStatusChange( |
70 User::OAuthTokenStatus status) { | 71 User::OAuthTokenStatus status) { |
71 } | 72 } |
72 | 73 |
73 void LocallyManagedUserLoginFlow::OnSyncSetupDataLoaded( | 74 void SupervisedUserLoginFlow::OnSyncSetupDataLoaded( |
74 const std::string& token) { | 75 const std::string& token) { |
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
76 ConfigureSync(token); | 77 ConfigureSync(token); |
77 } | 78 } |
78 | 79 |
79 void LocallyManagedUserLoginFlow::ConfigureSync(const std::string& token) { | 80 void SupervisedUserLoginFlow::ConfigureSync(const std::string& token) { |
80 data_loaded_ = true; | 81 data_loaded_ = true; |
81 // TODO(antrim): add error handling (no token loaded). | 82 // TODO(antrim): add error handling (no token loaded). |
82 // See also: http://crbug.com/312751 | 83 // See also: http://crbug.com/312751 |
83 if (!token.empty()) | 84 if (!token.empty()) |
84 ManagedUserServiceFactory::GetForProfile(profile_)->InitSync(token); | 85 ManagedUserServiceFactory::GetForProfile(profile_)->InitSync(token); |
85 | 86 |
86 LoginUtils::Get()->DoBrowserLaunch(profile_, host()); | 87 LoginUtils::Get()->DoBrowserLaunch(profile_, host()); |
87 profile_ = NULL; | 88 profile_ = NULL; |
88 UnregisterFlowSoon(); | 89 UnregisterFlowSoon(); |
89 } | 90 } |
90 | 91 |
91 void LocallyManagedUserLoginFlow::LaunchExtraSteps( | 92 void SupervisedUserLoginFlow::LaunchExtraSteps( |
92 Profile* profile) { | 93 Profile* profile) { |
93 profile_ = profile; | 94 profile_ = profile; |
94 base::FilePath profile_dir = ProfileHelper::GetProfilePathByUserIdHash( | 95 base::FilePath profile_dir = ProfileHelper::GetProfilePathByUserIdHash( |
95 UserManager::Get()->GetUserByProfile(profile)->username_hash()); | 96 UserManager::Get()->GetUserByProfile(profile)->username_hash()); |
96 PostTaskAndReplyWithResult( | 97 PostTaskAndReplyWithResult( |
97 content::BrowserThread::GetBlockingPool(), | 98 content::BrowserThread::GetBlockingPool(), |
98 FROM_HERE, | 99 FROM_HERE, |
99 base::Bind(&LoadSyncToken, profile_dir), | 100 base::Bind(&LoadSyncToken, profile_dir), |
100 base::Bind( | 101 base::Bind( |
101 &LocallyManagedUserLoginFlow::OnSyncSetupDataLoaded, | 102 &SupervisedUserLoginFlow::OnSyncSetupDataLoaded, |
102 weak_factory_.GetWeakPtr())); | 103 weak_factory_.GetWeakPtr())); |
103 } | 104 } |
104 | 105 |
105 } // namespace chromeos | 106 } // namespace chromeos |
OLD | NEW |