Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: chrome/browser/chromeos/profiles/profile_helper.cc

Issue 23678007: OAuth2LoginManager+MergeSessionThrottle hardening, multi-profle support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/profiles/profile_helper.h" 5 #include "chrome/browser/chromeos/profiles/profile_helper.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/browsing_data/browsing_data_helper.h" 10 #include "chrome/browser/browsing_data/browsing_data_helper.h"
11 #include "chrome/browser/chromeos/login/oauth2_login_manager_factory.h"
11 #include "chrome/browser/chromeos/login/user_manager.h" 12 #include "chrome/browser/chromeos/login/user_manager.h"
12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/common/chrome_constants.h" 15 #include "chrome/common/chrome_constants.h"
15 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
16 17
17 namespace chromeos { 18 namespace chromeos {
18 19
19 namespace { 20 namespace {
20 21
21 base::FilePath GetSigninProfileDir() { 22 base::FilePath GetSigninProfileDir() {
22 ProfileManager* profile_manager = g_browser_process->profile_manager(); 23 ProfileManager* profile_manager = g_browser_process->profile_manager();
23 base::FilePath user_data_dir = profile_manager->user_data_dir(); 24 base::FilePath user_data_dir = profile_manager->user_data_dir();
24 return user_data_dir.AppendASCII(chrome::kInitialProfile); 25 return user_data_dir.AppendASCII(chrome::kInitialProfile);
25 } 26 }
26 27
27 } // anonymous namespace 28 } // anonymous namespace
28 29
29 //////////////////////////////////////////////////////////////////////////////// 30 ////////////////////////////////////////////////////////////////////////////////
30 // ProfileHelper, public 31 // ProfileHelper, public
31 32
32 ProfileHelper::ProfileHelper() 33 ProfileHelper::ProfileHelper()
33 : signin_profile_clear_requested_(false) { 34 : signin_profile_clear_requested_(false) {
34 } 35 }
35 36
36 ProfileHelper::~ProfileHelper() { 37 ProfileHelper::~ProfileHelper() {
37 // Checking whether UserManager is initialized covers case 38 // Checking whether UserManager is initialized covers case
38 // when ScopedTestUserManager is used. 39 // when ScopedTestUserManager is used.
39 if (UserManager::IsInitialized()) { 40 if (UserManager::IsInitialized())
40 UserManager::Get()->RemoveObserver(this);
41 UserManager::Get()->RemoveSessionStateObserver(this); 41 UserManager::Get()->RemoveSessionStateObserver(this);
42 }
43 } 42 }
44 43
45 // static 44 // static
46 Profile* ProfileHelper::GetProfileByUserIdHash( 45 Profile* ProfileHelper::GetProfileByUserIdHash(
47 const std::string& user_id_hash) { 46 const std::string& user_id_hash) {
48 ProfileManager* profile_manager = g_browser_process->profile_manager(); 47 ProfileManager* profile_manager = g_browser_process->profile_manager();
49 return profile_manager->GetProfile(GetProfilePathByUserIdHash(user_id_hash)); 48 return profile_manager->GetProfile(GetProfilePathByUserIdHash(user_id_hash));
50 } 49 }
51 50
52 // static 51 // static
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 86
88 return profile_dir.substr(prefix.length(), 87 return profile_dir.substr(prefix.length(),
89 profile_dir.length() - prefix.length()); 88 profile_dir.length() - prefix.length());
90 } 89 }
91 90
92 // static 91 // static
93 bool ProfileHelper::IsSigninProfile(Profile* profile) { 92 bool ProfileHelper::IsSigninProfile(Profile* profile) {
94 return profile->GetPath().BaseName().value() == chrome::kInitialProfile; 93 return profile->GetPath().BaseName().value() == chrome::kInitialProfile;
95 } 94 }
96 95
97 // static
98 void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) { 96 void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) {
99 // Initialize Chrome OS preferences like touch pad sensitivity. For the 97 // Initialize Chrome OS preferences like touch pad sensitivity. For the
100 // preferences to work in the guest mode, the initialization has to be 98 // preferences to work in the guest mode, the initialization has to be
101 // done after |profile| is switched to the incognito profile (which 99 // done after |profile| is switched to the incognito profile (which
102 // is actually GuestSessionProfile in the guest mode). See the 100 // is actually GuestSessionProfile in the guest mode). See the
103 // GetOffTheRecordProfile() call above. 101 // GetOffTheRecordProfile() call above.
104 profile->InitChromeOSPreferences(); 102 profile->InitChromeOSPreferences();
105 103
106 if (process_startup) { 104 if (process_startup)
107 profile->SetupChromeOSEnterpriseExtensionObserver(); 105 profile->SetupChromeOSEnterpriseExtensionObserver();
106
107 // Add observer so we can see when the first profile's session restore is
108 // completed. After that, we won't need the default profile anymore.
109 if (!IsSigninProfile(profile) &&
110 UserManager::Get()->IsLoggedInAsRegularUser() &&
111 !UserManager::Get()->IsLoggedInAsStub()) {
112 chromeos::OAuth2LoginManager* login_manager =
113 chromeos::OAuth2LoginManagerFactory::GetInstance()->GetForProfile(
114 profile);
115 if (login_manager)
116 login_manager->AddObserver(this);
108 } 117 }
109 } 118 }
110 119
111 base::FilePath ProfileHelper::GetActiveUserProfileDir() { 120 base::FilePath ProfileHelper::GetActiveUserProfileDir() {
112 DCHECK(!active_user_id_hash_.empty()); 121 DCHECK(!active_user_id_hash_.empty());
113 return base::FilePath(chrome::kProfileDirPrefix + active_user_id_hash_); 122 return base::FilePath(chrome::kProfileDirPrefix + active_user_id_hash_);
114 } 123 }
115 124
116 void ProfileHelper::Initialize() { 125 void ProfileHelper::Initialize() {
117 UserManager::Get()->AddObserver(this);
118 UserManager::Get()->AddSessionStateObserver(this); 126 UserManager::Get()->AddSessionStateObserver(this);
119 } 127 }
120 128
121 void ProfileHelper::ClearSigninProfile(const base::Closure& on_clear_callback) { 129 void ProfileHelper::ClearSigninProfile(const base::Closure& on_clear_callback) {
122 on_clear_callbacks_.push_back(on_clear_callback); 130 on_clear_callbacks_.push_back(on_clear_callback);
123 if (signin_profile_clear_requested_) 131 if (signin_profile_clear_requested_)
124 return; 132 return;
125 ProfileManager* profile_manager = g_browser_process->profile_manager(); 133 ProfileManager* profile_manager = g_browser_process->profile_manager();
126 // Check if signin profile was loaded. 134 // Check if signin profile was loaded.
127 if (!profile_manager->GetProfileByPath(GetSigninProfileDir())) { 135 if (!profile_manager->GetProfileByPath(GetSigninProfileDir())) {
(...skipping 14 matching lines...) Expand all
142 void ProfileHelper::OnBrowsingDataRemoverDone() { 150 void ProfileHelper::OnBrowsingDataRemoverDone() {
143 signin_profile_clear_requested_ = false; 151 signin_profile_clear_requested_ = false;
144 for (size_t i = 0; i < on_clear_callbacks_.size(); ++i) { 152 for (size_t i = 0; i < on_clear_callbacks_.size(); ++i) {
145 if (!on_clear_callbacks_[i].is_null()) 153 if (!on_clear_callbacks_[i].is_null())
146 on_clear_callbacks_[i].Run(); 154 on_clear_callbacks_[i].Run();
147 } 155 }
148 on_clear_callbacks_.clear(); 156 on_clear_callbacks_.clear();
149 } 157 }
150 158
151 //////////////////////////////////////////////////////////////////////////////// 159 ////////////////////////////////////////////////////////////////////////////////
152 // ProfileHelper, UserManager::Observer implementation: 160 // ProfileHelper, OAuth2LoginManager::Observer implementation:
153 161
154 void ProfileHelper::MergeSessionStateChanged( 162 void ProfileHelper::OnSessionRestoreStateChanged(
155 UserManager::MergeSessionState state) { 163 Profile* user_profile,
156 if (state == UserManager:: MERGE_STATUS_DONE) 164 OAuth2LoginManager::SessionRestoreState state) {
165 if (state == OAuth2LoginManager::SESSION_RESTORE_DONE ||
166 state == OAuth2LoginManager::SESSION_RESTORE_FAILED) {
167 chromeos::OAuth2LoginManager* login_manager =
168 chromeos::OAuth2LoginManagerFactory::GetInstance()->GetForProfile(
169 user_profile);
170 login_manager->RemoveObserver(this);
157 ClearSigninProfile(base::Closure()); 171 ClearSigninProfile(base::Closure());
172 }
158 } 173 }
159 174
160 //////////////////////////////////////////////////////////////////////////////// 175 ////////////////////////////////////////////////////////////////////////////////
161 // ProfileHelper, UserManager::UserSessionStateObserver implementation: 176 // ProfileHelper, UserManager::UserSessionStateObserver implementation:
162 177
163 void ProfileHelper::ActiveUserHashChanged(const std::string& hash) { 178 void ProfileHelper::ActiveUserHashChanged(const std::string& hash) {
164 active_user_id_hash_ = hash; 179 active_user_id_hash_ = hash;
165 base::FilePath profile_path = GetProfilePathByUserIdHash(hash); 180 base::FilePath profile_path = GetProfilePathByUserIdHash(hash);
166 LOG(INFO) << "Switching to profile path: " << profile_path.value(); 181 LOG(INFO) << "Switching to profile path: " << profile_path.value();
167 } 182 }
168 183
169 } // namespace chromeos 184 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698