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

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

Issue 1012083002: Resolve new GAIA flow's infinite loop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move to anonymous namespace. Created 5 years, 9 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
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/signin/oauth2_login_manager_factory.h" 11 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/profiles/profiles_state.h" 14 #include "chrome/browser/profiles/profiles_state.h"
15 #include "chrome/common/chrome_constants.h" 15 #include "chrome/common/chrome_constants.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chromeos/chromeos_switches.h" 17 #include "chromeos/chromeos_switches.h"
18 #include "components/user_manager/user.h" 18 #include "components/user_manager/user.h"
19 #include "components/user_manager/user_manager.h" 19 #include "components/user_manager/user_manager.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/storage_partition.h"
22 #include "content/public/browser/web_contents.h"
23 #include "extensions/browser/guest_view/guest_view_manager.h"
24 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
21 25
22 namespace chromeos { 26 namespace chromeos {
23 27
24 namespace { 28 namespace {
25 29
26 // As defined in /chromeos/dbus/cryptohome_client.cc. 30 // As defined in /chromeos/dbus/cryptohome_client.cc.
27 static const char kUserIdHashSuffix[] = "-hash"; 31 static const char kUserIdHashSuffix[] = "-hash";
28 32
29 bool ShouldAddProfileDirPrefix(const std::string& user_id_hash) { 33 bool ShouldAddProfileDirPrefix(const std::string& user_id_hash) {
30 // Do not add profile dir prefix for legacy profile dir and test 34 // Do not add profile dir prefix for legacy profile dir and test
(...skipping 10 matching lines...) Expand all
41 public: 45 public:
42 explicit UsernameHashMatcher(const std::string& h) : username_hash(h) {} 46 explicit UsernameHashMatcher(const std::string& h) : username_hash(h) {}
43 bool operator()(const user_manager::User* user) const { 47 bool operator()(const user_manager::User* user) const {
44 return user->username_hash() == username_hash; 48 return user->username_hash() == username_hash;
45 } 49 }
46 50
47 private: 51 private:
48 const std::string& username_hash; 52 const std::string& username_hash;
49 }; 53 };
50 54
55 bool ClearWebViewData(const base::Closure& on_clear_callback,
56 content::WebContents* web_contents) {
57 extensions::WebViewGuest* view_guest =
58 extensions::WebViewGuest::FromWebContents(web_contents);
59 if (!view_guest)
60 return false;
61 return view_guest->ClearData(base::Time(),
62 content::StoragePartition::REMOVE_DATA_MASK_ALL,
63 on_clear_callback);
64 }
65
66 void ClearContentsData(content::WebContents* web_contents,
67 const base::Closure& on_clear_callback) {
68 content::BrowserContext* context = web_contents->GetBrowserContext();
69 extensions::GuestViewManager* manager =
70 extensions::GuestViewManager::FromBrowserContext(context);
71 if (!manager->ForEachGuest(
72 web_contents, base::Bind(&ClearWebViewData, on_clear_callback))) {
xiyuan 2015/03/19 16:33:31 This could cause the |on_clear_callback| be called
Ivan Podogov 2015/03/19 16:59:06 In fact, it cannot: ForEachGuest will stop iterati
xiyuan 2015/03/19 18:22:19 You are right about the callback is invoked just o
Ivan Podogov 2015/03/19 18:42:43 It is correct as long as ClearSigninProfile is cal
xiyuan 2015/03/19 19:49:28 It will not be correct when we add webviews for en
73 on_clear_callback.Run();
74 }
75 }
76
51 } // anonymous namespace 77 } // anonymous namespace
52 78
53 // static 79 // static
54 bool ProfileHelper::enable_profile_to_user_testing = false; 80 bool ProfileHelper::enable_profile_to_user_testing = false;
55 bool ProfileHelper::always_return_primary_user_for_testing = false; 81 bool ProfileHelper::always_return_primary_user_for_testing = false;
56 82
57 //////////////////////////////////////////////////////////////////////////////// 83 ////////////////////////////////////////////////////////////////////////////////
58 // ProfileHelper, public 84 // ProfileHelper, public
59 85
60 ProfileHelper::ProfileHelper() 86 ProfileHelper::ProfileHelper()
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 216 }
191 217
192 base::FilePath ProfileHelper::GetActiveUserProfileDir() { 218 base::FilePath ProfileHelper::GetActiveUserProfileDir() {
193 return ProfileHelper::GetUserProfileDir(active_user_id_hash_); 219 return ProfileHelper::GetUserProfileDir(active_user_id_hash_);
194 } 220 }
195 221
196 void ProfileHelper::Initialize() { 222 void ProfileHelper::Initialize() {
197 user_manager::UserManager::Get()->AddSessionStateObserver(this); 223 user_manager::UserManager::Get()->AddSessionStateObserver(this);
198 } 224 }
199 225
200 void ProfileHelper::ClearSigninProfile(const base::Closure& on_clear_callback) { 226 void ProfileHelper::ClearSigninProfile(const base::Closure& on_clear_callback,
201 on_clear_callbacks_.push_back(on_clear_callback); 227 content::WebContents* webview_contents) {
228 on_clear_callbacks_.push_back(
229 webview_contents
230 ? base::Bind(&ClearContentsData, webview_contents, on_clear_callback)
231 : on_clear_callback);
202 if (signin_profile_clear_requested_) 232 if (signin_profile_clear_requested_)
203 return; 233 return;
204 ProfileManager* profile_manager = g_browser_process->profile_manager(); 234 ProfileManager* profile_manager = g_browser_process->profile_manager();
205 // Check if signin profile was loaded. 235 // Check if signin profile was loaded.
206 if (!profile_manager->GetProfileByPath(GetSigninProfileDir())) { 236 if (!profile_manager->GetProfileByPath(GetSigninProfileDir())) {
207 OnBrowsingDataRemoverDone(); 237 OnBrowsingDataRemoverDone();
208 return; 238 return;
209 } 239 }
210 signin_profile_clear_requested_ = true; 240 signin_profile_clear_requested_ = true;
211 BrowsingDataRemover* remover = 241 BrowsingDataRemover* remover =
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 void ProfileHelper::OnSessionRestoreStateChanged( 373 void ProfileHelper::OnSessionRestoreStateChanged(
344 Profile* user_profile, 374 Profile* user_profile,
345 OAuth2LoginManager::SessionRestoreState state) { 375 OAuth2LoginManager::SessionRestoreState state) {
346 if (state == OAuth2LoginManager::SESSION_RESTORE_DONE || 376 if (state == OAuth2LoginManager::SESSION_RESTORE_DONE ||
347 state == OAuth2LoginManager::SESSION_RESTORE_FAILED || 377 state == OAuth2LoginManager::SESSION_RESTORE_FAILED ||
348 state == OAuth2LoginManager::SESSION_RESTORE_CONNECTION_FAILED) { 378 state == OAuth2LoginManager::SESSION_RESTORE_CONNECTION_FAILED) {
349 chromeos::OAuth2LoginManager* login_manager = 379 chromeos::OAuth2LoginManager* login_manager =
350 chromeos::OAuth2LoginManagerFactory::GetInstance()-> 380 chromeos::OAuth2LoginManagerFactory::GetInstance()->
351 GetForProfile(user_profile); 381 GetForProfile(user_profile);
352 login_manager->RemoveObserver(this); 382 login_manager->RemoveObserver(this);
353 ClearSigninProfile(base::Closure()); 383 ClearSigninProfile(base::Closure(), nullptr);
xiyuan 2015/03/19 16:33:31 Could you double check whether passing nullptr is
Ivan Podogov 2015/03/19 16:59:06 I'm afraid that I see no easy way to do it: it wou
xiyuan 2015/03/19 18:22:19 I was asking to verify this is only called on brow
354 } 384 }
355 } 385 }
356 386
357 //////////////////////////////////////////////////////////////////////////////// 387 ////////////////////////////////////////////////////////////////////////////////
358 // ProfileHelper, UserManager::UserSessionStateObserver implementation: 388 // ProfileHelper, UserManager::UserSessionStateObserver implementation:
359 389
360 void ProfileHelper::ActiveUserHashChanged(const std::string& hash) { 390 void ProfileHelper::ActiveUserHashChanged(const std::string& hash) {
361 active_user_id_hash_ = hash; 391 active_user_id_hash_ = hash;
362 } 392 }
363 393
(...skipping 19 matching lines...) Expand all
383 user_to_profile_for_testing_[user] = profile; 413 user_to_profile_for_testing_[user] = profile;
384 } 414 }
385 415
386 // static 416 // static
387 std::string ProfileHelper::GetUserIdHashByUserIdForTesting( 417 std::string ProfileHelper::GetUserIdHashByUserIdForTesting(
388 const std::string& user_id) { 418 const std::string& user_id) {
389 return user_id + kUserIdHashSuffix; 419 return user_id + kUserIdHashSuffix;
390 } 420 }
391 421
392 } // namespace chromeos 422 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/profiles/profile_helper.h ('k') | chrome/browser/resources/gaia_auth_host/authenticator.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698