| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/signin/merge_session_throttling_utils.h" | 5 #include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 DVLOG(1) << "Unblocking profile " << profile; | 91 DVLOG(1) << "Unblocking profile " << profile; |
| 92 ProfileSet::Get()->erase(profile); | 92 ProfileSet::Get()->erase(profile); |
| 93 | 93 |
| 94 // Check if there is any other profile to block on. | 94 // Check if there is any other profile to block on. |
| 95 if (ProfileSet::Get()->size() == 0) { | 95 if (ProfileSet::Get()->size() == 0) { |
| 96 base::AtomicRefCountInc(&g_all_profiles_restored_); | 96 base::AtomicRefCountInc(&g_all_profiles_restored_); |
| 97 DVLOG(1) << "All profiles merged " << g_all_profiles_restored_; | 97 DVLOG(1) << "All profiles merged " << g_all_profiles_restored_; |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 bool ShouldDelayRequest(content::WebContents* web_contents) { | 101 bool ShouldDelayRequest(Profile* profile) { |
| 102 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 102 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 103 | 103 |
| 104 if (!user_manager::UserManager::Get()->IsUserLoggedIn()) { | 104 if (!user_manager::UserManager::Get()->IsUserLoggedIn()) { |
| 105 return false; | 105 return false; |
| 106 } else if (!user_manager::UserManager::Get() | 106 } else if (!user_manager::UserManager::Get() |
| 107 ->IsLoggedInAsUserWithGaiaAccount()) { | 107 ->IsLoggedInAsUserWithGaiaAccount()) { |
| 108 // This is not a regular user session, let's remove the throttle | 108 // This is not a regular user session, let's remove the throttle |
| 109 // permanently. | 109 // permanently. |
| 110 if (!AreAllSessionMergedAlready()) | 110 if (!AreAllSessionMergedAlready()) |
| 111 base::AtomicRefCountInc(&g_all_profiles_restored_); | 111 base::AtomicRefCountInc(&g_all_profiles_restored_); |
| 112 | 112 |
| 113 return false; | 113 return false; |
| 114 } | 114 } |
| 115 | 115 |
| 116 content::BrowserContext* browser_context = web_contents->GetBrowserContext(); | |
| 117 if (!browser_context) | |
| 118 return false; | |
| 119 | |
| 120 Profile* profile = Profile::FromBrowserContext(browser_context); | |
| 121 if (!profile) | 116 if (!profile) |
| 122 return false; | 117 return false; |
| 123 | 118 |
| 124 chromeos::OAuth2LoginManager* login_manager = | 119 chromeos::OAuth2LoginManager* login_manager = |
| 125 chromeos::OAuth2LoginManagerFactory::GetInstance()->GetForProfile( | 120 chromeos::OAuth2LoginManagerFactory::GetInstance()->GetForProfile( |
| 126 profile); | 121 profile); |
| 127 if (!login_manager) | 122 if (!login_manager) |
| 128 return false; | 123 return false; |
| 129 | 124 |
| 130 switch (login_manager->state()) { | 125 switch (login_manager->state()) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 160 case chromeos::OAuth2LoginManager::SESSION_RESTORE_CONNECTION_FAILED: { | 155 case chromeos::OAuth2LoginManager::SESSION_RESTORE_CONNECTION_FAILED: { |
| 161 UnblockProfile(profile); | 156 UnblockProfile(profile); |
| 162 return false; | 157 return false; |
| 163 } | 158 } |
| 164 } | 159 } |
| 165 | 160 |
| 166 NOTREACHED(); | 161 NOTREACHED(); |
| 167 return false; | 162 return false; |
| 168 } | 163 } |
| 169 | 164 |
| 165 bool ShouldDelayRequest(content::WebContents* web_contents) { |
| 166 content::BrowserContext* browser_context = web_contents->GetBrowserContext(); |
| 167 if (!browser_context) |
| 168 return false; |
| 169 |
| 170 return ShouldDelayRequest(Profile::FromBrowserContext(browser_context)); |
| 171 } |
| 172 |
| 170 bool ShouldDelayUrl(const GURL& url) { | 173 bool ShouldDelayUrl(const GURL& url) { |
| 171 // If we are loading google properties while merge session is in progress, | 174 // If we are loading google properties while merge session is in progress, |
| 172 // we will show delayed loading page instead. | 175 // we will show delayed loading page instead. |
| 173 return !net::NetworkChangeNotifier::IsOffline() && | 176 return !net::NetworkChangeNotifier::IsOffline() && |
| 174 !AreAllSessionMergedAlready() && | 177 !AreAllSessionMergedAlready() && |
| 175 google_util::IsGoogleHostname(url.host_piece(), | 178 google_util::IsGoogleHostname(url.host_piece(), |
| 176 google_util::ALLOW_SUBDOMAIN); | 179 google_util::ALLOW_SUBDOMAIN); |
| 177 } | 180 } |
| 178 | 181 |
| 179 } // namespace merge_session_throttling_utils | 182 } // namespace merge_session_throttling_utils |
| OLD | NEW |