| 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/signin/signin_manager.h" | 5 #include "chrome/browser/signin/signin_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "chrome/browser/sync/sync_prefs.h" | 31 #include "chrome/browser/sync/sync_prefs.h" |
| 32 #include "chrome/browser/ui/global_error/global_error_service.h" | 32 #include "chrome/browser/ui/global_error/global_error_service.h" |
| 33 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 33 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| 34 #include "chrome/browser/ui/host_desktop.h" | 34 #include "chrome/browser/ui/host_desktop.h" |
| 35 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h" | 35 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h" |
| 36 #include "chrome/common/chrome_notification_types.h" | 36 #include "chrome/common/chrome_notification_types.h" |
| 37 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
| 38 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
| 39 #include "content/public/browser/browser_thread.h" | 39 #include "content/public/browser/browser_thread.h" |
| 40 #include "content/public/browser/notification_service.h" | 40 #include "content/public/browser/notification_service.h" |
| 41 #include "content/public/browser/render_process_host.h" |
| 41 #include "google_apis/gaia/gaia_auth_fetcher.h" | 42 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 42 #include "google_apis/gaia/gaia_auth_util.h" | 43 #include "google_apis/gaia/gaia_auth_util.h" |
| 43 #include "google_apis/gaia/gaia_constants.h" | 44 #include "google_apis/gaia/gaia_constants.h" |
| 44 #include "google_apis/gaia/gaia_urls.h" | 45 #include "google_apis/gaia/gaia_urls.h" |
| 45 #include "net/cookies/cookie_monster.h" | 46 #include "net/cookies/cookie_monster.h" |
| 46 #include "net/url_request/url_request_context.h" | 47 #include "net/url_request/url_request_context.h" |
| 47 #include "net/url_request/url_request_context_getter.h" | 48 #include "net/url_request/url_request_context_getter.h" |
| 48 #include "third_party/icu/public/i18n/unicode/regex.h" | 49 #include "third_party/icu/public/i18n/unicode/regex.h" |
| 49 | 50 |
| 50 #if defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS) | 51 #if defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS) |
| 51 #include "chrome/browser/policy/user_policy_signin_service.h" | 52 #include "chrome/browser/policy/user_policy_signin_service.h" |
| 52 #include "chrome/browser/policy/user_policy_signin_service_factory.h" | 53 #include "chrome/browser/policy/user_policy_signin_service_factory.h" |
| 53 #endif | 54 #endif |
| 54 | 55 |
| 55 using namespace signin_internals_util; | 56 using namespace signin_internals_util; |
| 56 | 57 |
| 57 using content::BrowserThread; | 58 using content::BrowserThread; |
| 58 | 59 |
| 59 namespace { | 60 namespace { |
| 60 | 61 |
| 61 const char kGetInfoDisplayEmailKey[] = "displayEmail"; | 62 const char kGetInfoDisplayEmailKey[] = "displayEmail"; |
| 62 const char kGetInfoEmailKey[] = "email"; | 63 const char kGetInfoEmailKey[] = "email"; |
| 63 | 64 |
| 64 const char kGoogleAccountsUrl[] = "https://accounts.google.com"; | 65 const char kGoogleAccountsUrl[] = "https://accounts.google.com"; |
| 65 | 66 |
| 67 const int kInvalidProcessId = -1; |
| 68 |
| 66 } // namespace | 69 } // namespace |
| 67 | 70 |
| 68 // This class fetches GAIA cookie on IO thread on behalf of SigninManager which | 71 // This class fetches GAIA cookie on IO thread on behalf of SigninManager which |
| 69 // only lives on the UI thread. | 72 // only lives on the UI thread. |
| 70 class SigninManagerCookieHelper | 73 class SigninManagerCookieHelper |
| 71 : public base::RefCountedThreadSafe<SigninManagerCookieHelper> { | 74 : public base::RefCountedThreadSafe<SigninManagerCookieHelper> { |
| 72 public: | 75 public: |
| 73 explicit SigninManagerCookieHelper( | 76 explicit SigninManagerCookieHelper( |
| 74 net::URLRequestContextGetter* request_context_getter); | 77 net::URLRequestContextGetter* request_context_getter); |
| 75 | 78 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 BrowserThread::UI, FROM_HERE, | 144 BrowserThread::UI, FROM_HERE, |
| 142 base::Bind(&SigninManagerCookieHelper::NotifyOnUIThread, this, cookies)); | 145 base::Bind(&SigninManagerCookieHelper::NotifyOnUIThread, this, cookies)); |
| 143 } | 146 } |
| 144 | 147 |
| 145 void SigninManagerCookieHelper::NotifyOnUIThread( | 148 void SigninManagerCookieHelper::NotifyOnUIThread( |
| 146 const net::CookieList& cookies) { | 149 const net::CookieList& cookies) { |
| 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 148 base::ResetAndReturn(&completion_callback_).Run(cookies); | 151 base::ResetAndReturn(&completion_callback_).Run(cookies); |
| 149 } | 152 } |
| 150 | 153 |
| 154 // Under the covers, we use a dummy chrome-extension ID to serve the purposes |
| 155 // outlined in the .h file comment for this string. |
| 156 const char* SigninManager::kChromeSigninEffectiveSite = |
| 157 "chrome-extension://acfccoigjajmmgbhpfbjnpckhjjegnih"; |
| 158 |
| 159 // static |
| 160 bool SigninManager::IsWebBasedSigninFlowURL(const GURL& url) { |
| 161 GURL effective(kChromeSigninEffectiveSite); |
| 162 if (url.SchemeIs(effective.scheme().c_str()) && |
| 163 url.host() == effective.host()) { |
| 164 return true; |
| 165 } |
| 166 |
| 167 GURL service_login(GaiaUrls::GetInstance()->service_login_url()); |
| 168 if (url.GetOrigin() != service_login.GetOrigin()) |
| 169 return false; |
| 170 |
| 171 return url.path() == service_login.path(); |
| 172 } |
| 173 |
| 151 // static | 174 // static |
| 152 bool SigninManager::AreSigninCookiesAllowed(Profile* profile) { | 175 bool SigninManager::AreSigninCookiesAllowed(Profile* profile) { |
| 153 CookieSettings* cookie_settings = | 176 CookieSettings* cookie_settings = |
| 154 CookieSettings::Factory::GetForProfile(profile); | 177 CookieSettings::Factory::GetForProfile(profile); |
| 155 return AreSigninCookiesAllowed(cookie_settings); | 178 return AreSigninCookiesAllowed(cookie_settings); |
| 156 } | 179 } |
| 157 | 180 |
| 158 // static | 181 // static |
| 159 bool SigninManager::AreSigninCookiesAllowed(CookieSettings* cookie_settings) { | 182 bool SigninManager::AreSigninCookiesAllowed(CookieSettings* cookie_settings) { |
| 160 return cookie_settings && | 183 return cookie_settings && |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 UBool match = matcher.matches(status); | 216 UBool match = matcher.matches(status); |
| 194 DCHECK(U_SUCCESS(status)); | 217 DCHECK(U_SUCCESS(status)); |
| 195 return !!match; // !! == convert from UBool to bool. | 218 return !!match; // !! == convert from UBool to bool. |
| 196 } | 219 } |
| 197 | 220 |
| 198 SigninManager::SigninManager() | 221 SigninManager::SigninManager() |
| 199 : profile_(NULL), | 222 : profile_(NULL), |
| 200 prohibit_signout_(false), | 223 prohibit_signout_(false), |
| 201 had_two_factor_error_(false), | 224 had_two_factor_error_(false), |
| 202 type_(SIGNIN_TYPE_NONE), | 225 type_(SIGNIN_TYPE_NONE), |
| 203 weak_pointer_factory_(this) { | 226 weak_pointer_factory_(this), |
| 227 signin_process_id_(kInvalidProcessId) { |
| 228 } |
| 229 |
| 230 void SigninManager::SetSigninProcess(int process_id) { |
| 231 if (process_id == signin_process_id_) |
| 232 return; |
| 233 DLOG_IF(WARNING, signin_process_id_ != kInvalidProcessId) << |
| 234 "Replacing in-use signin process."; |
| 235 signin_process_id_ = process_id; |
| 236 const content::RenderProcessHost* process = |
| 237 content::RenderProcessHost::FromID(process_id); |
| 238 DCHECK(process); |
| 239 registrar_.Add(this, |
| 240 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 241 content::Source<content::RenderProcessHost>(process)); |
| 242 } |
| 243 |
| 244 bool SigninManager::IsSigninProcess(int process_id) const { |
| 245 return process_id == signin_process_id_; |
| 246 } |
| 247 |
| 248 bool SigninManager::HasSigninProcess() const { |
| 249 return signin_process_id_ != kInvalidProcessId; |
| 204 } | 250 } |
| 205 | 251 |
| 206 SigninManager::~SigninManager() { | 252 SigninManager::~SigninManager() { |
| 207 DCHECK(!signin_global_error_.get()) << | 253 DCHECK(!signin_global_error_.get()) << |
| 208 "SigninManager::Initialize called but not SigninManager::Shutdown"; | 254 "SigninManager::Initialize called but not SigninManager::Shutdown"; |
| 209 } | 255 } |
| 210 | 256 |
| 211 void SigninManager::Initialize(Profile* profile) { | 257 void SigninManager::Initialize(Profile* profile) { |
| 212 // Should never call Initialize() twice. | 258 // Should never call Initialize() twice. |
| 213 DCHECK(!IsInitialized()); | 259 DCHECK(!IsInitialized()); |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 if (tok_details->service() == | 938 if (tok_details->service() == |
| 893 GaiaConstants::kGaiaOAuth2LoginRefreshToken) { | 939 GaiaConstants::kGaiaOAuth2LoginRefreshToken) { |
| 894 ubertoken_fetcher_.reset(new UbertokenFetcher(profile_, this)); | 940 ubertoken_fetcher_.reset(new UbertokenFetcher(profile_, this)); |
| 895 ubertoken_fetcher_->StartFetchingToken(); | 941 ubertoken_fetcher_->StartFetchingToken(); |
| 896 | 942 |
| 897 // We only want to do this once per sign-in. | 943 // We only want to do this once per sign-in. |
| 898 CleanupNotificationRegistration(); | 944 CleanupNotificationRegistration(); |
| 899 } | 945 } |
| 900 break; | 946 break; |
| 901 } | 947 } |
| 948 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { |
| 949 // It's possible we're listening to a "stale" renderer because it was |
| 950 // replaced with a new process by process-per-site. In either case, |
| 951 // stop listening to it, but only reset signin_process_id_ tracking |
| 952 // if this was from the current signin process. |
| 953 registrar_.Remove(this, |
| 954 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 955 source); |
| 956 if (signin_process_id_ == |
| 957 content::Source<content::RenderProcessHost>(source)->GetID()) { |
| 958 signin_process_id_ = kInvalidProcessId; |
| 959 } |
| 960 break; |
| 961 } |
| 902 #endif | 962 #endif |
| 903 default: | 963 default: |
| 904 NOTREACHED(); | 964 NOTREACHED(); |
| 905 } | 965 } |
| 906 } | 966 } |
| 907 | 967 |
| 908 void SigninManager::Shutdown() { | 968 void SigninManager::Shutdown() { |
| 909 if (signin_global_error_.get()) { | 969 if (signin_global_error_.get()) { |
| 910 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( | 970 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( |
| 911 signin_global_error_.get()); | 971 signin_global_error_.get()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 NotifySigninValueChanged(field, value)); | 1013 NotifySigninValueChanged(field, value)); |
| 954 } | 1014 } |
| 955 | 1015 |
| 956 void SigninManager::NotifyDiagnosticsObservers( | 1016 void SigninManager::NotifyDiagnosticsObservers( |
| 957 const TimedSigninStatusField& field, | 1017 const TimedSigninStatusField& field, |
| 958 const std::string& value) { | 1018 const std::string& value) { |
| 959 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, | 1019 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, |
| 960 signin_diagnostics_observers_, | 1020 signin_diagnostics_observers_, |
| 961 NotifySigninValueChanged(field, value)); | 1021 NotifySigninValueChanged(field, value)); |
| 962 } | 1022 } |
| OLD | NEW |