| 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 19 matching lines...) Expand all Loading... |
| 30 #include "chrome/browser/sync/sync_prefs.h" | 30 #include "chrome/browser/sync/sync_prefs.h" |
| 31 #include "chrome/browser/ui/global_error/global_error_service.h" | 31 #include "chrome/browser/ui/global_error/global_error_service.h" |
| 32 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 32 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| 33 #include "chrome/browser/ui/host_desktop.h" | 33 #include "chrome/browser/ui/host_desktop.h" |
| 34 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h" | 34 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h" |
| 35 #include "chrome/common/chrome_notification_types.h" | 35 #include "chrome/common/chrome_notification_types.h" |
| 36 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 37 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
| 38 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
| 39 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
| 40 #include "content/public/browser/render_process_host.h" |
| 40 #include "google_apis/gaia/gaia_auth_fetcher.h" | 41 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 41 #include "google_apis/gaia/gaia_auth_util.h" | 42 #include "google_apis/gaia/gaia_auth_util.h" |
| 42 #include "google_apis/gaia/gaia_constants.h" | 43 #include "google_apis/gaia/gaia_constants.h" |
| 43 #include "google_apis/gaia/gaia_urls.h" | 44 #include "google_apis/gaia/gaia_urls.h" |
| 44 #include "net/cookies/cookie_monster.h" | 45 #include "net/cookies/cookie_monster.h" |
| 45 #include "net/url_request/url_request_context.h" | 46 #include "net/url_request/url_request_context.h" |
| 46 #include "net/url_request/url_request_context_getter.h" | 47 #include "net/url_request/url_request_context_getter.h" |
| 47 #include "third_party/icu/public/i18n/unicode/regex.h" | 48 #include "third_party/icu/public/i18n/unicode/regex.h" |
| 48 | 49 |
| 49 #if defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS) | 50 #if defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS) |
| 50 #include "chrome/browser/policy/user_policy_signin_service.h" | 51 #include "chrome/browser/policy/user_policy_signin_service.h" |
| 51 #include "chrome/browser/policy/user_policy_signin_service_factory.h" | 52 #include "chrome/browser/policy/user_policy_signin_service_factory.h" |
| 52 #endif | 53 #endif |
| 53 | 54 |
| 54 using namespace signin_internals_util; | 55 using namespace signin_internals_util; |
| 55 | 56 |
| 56 using content::BrowserThread; | 57 using content::BrowserThread; |
| 57 | 58 |
| 58 namespace { | 59 namespace { |
| 59 | 60 |
| 60 const char kGetInfoDisplayEmailKey[] = "displayEmail"; | 61 const char kGetInfoDisplayEmailKey[] = "displayEmail"; |
| 61 const char kGetInfoEmailKey[] = "email"; | 62 const char kGetInfoEmailKey[] = "email"; |
| 62 | 63 |
| 63 const char kGoogleAccountsUrl[] = "https://accounts.google.com"; | 64 const char kGoogleAccountsUrl[] = "https://accounts.google.com"; |
| 64 | 65 |
| 66 const int kInvalidProcessId = -1; |
| 67 |
| 65 } // namespace | 68 } // namespace |
| 66 | 69 |
| 67 // This class fetches GAIA cookie on IO thread on behalf of SigninManager which | 70 // This class fetches GAIA cookie on IO thread on behalf of SigninManager which |
| 68 // only lives on the UI thread. | 71 // only lives on the UI thread. |
| 69 class SigninManagerCookieHelper | 72 class SigninManagerCookieHelper |
| 70 : public base::RefCountedThreadSafe<SigninManagerCookieHelper> { | 73 : public base::RefCountedThreadSafe<SigninManagerCookieHelper> { |
| 71 public: | 74 public: |
| 72 explicit SigninManagerCookieHelper( | 75 explicit SigninManagerCookieHelper( |
| 73 net::URLRequestContextGetter* request_context_getter); | 76 net::URLRequestContextGetter* request_context_getter); |
| 74 | 77 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 UBool match = matcher.matches(status); | 195 UBool match = matcher.matches(status); |
| 193 DCHECK(U_SUCCESS(status)); | 196 DCHECK(U_SUCCESS(status)); |
| 194 return !!match; // !! == convert from UBool to bool. | 197 return !!match; // !! == convert from UBool to bool. |
| 195 } | 198 } |
| 196 | 199 |
| 197 SigninManager::SigninManager() | 200 SigninManager::SigninManager() |
| 198 : profile_(NULL), | 201 : profile_(NULL), |
| 199 prohibit_signout_(false), | 202 prohibit_signout_(false), |
| 200 had_two_factor_error_(false), | 203 had_two_factor_error_(false), |
| 201 type_(SIGNIN_TYPE_NONE), | 204 type_(SIGNIN_TYPE_NONE), |
| 202 weak_pointer_factory_(this) { | 205 weak_pointer_factory_(this), |
| 206 signin_process_id_(kInvalidProcessId) { |
| 207 } |
| 208 |
| 209 void SigninManager::SetSigninProcess(int process_id) { |
| 210 if (process_id == signin_process_id_) |
| 211 return; |
| 212 DLOG_IF(WARNING, signin_process_id_ != kInvalidProcessId) << |
| 213 "Replacing in-use signin process."; |
| 214 signin_process_id_ = process_id; |
| 215 const content::RenderProcessHost* process = |
| 216 content::RenderProcessHost::FromID(process_id); |
| 217 DCHECK(process); |
| 218 registrar_.Add(this, |
| 219 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 220 content::Source<content::RenderProcessHost>(process)); |
| 221 } |
| 222 |
| 223 bool SigninManager::IsSigninProcess(int process_id) const { |
| 224 return process_id == signin_process_id_; |
| 225 } |
| 226 |
| 227 bool SigninManager::HasSigninProcess() const { |
| 228 return signin_process_id_ != kInvalidProcessId; |
| 203 } | 229 } |
| 204 | 230 |
| 205 SigninManager::~SigninManager() { | 231 SigninManager::~SigninManager() { |
| 206 DCHECK(!signin_global_error_.get()) << | 232 DCHECK(!signin_global_error_.get()) << |
| 207 "SigninManager::Initialize called but not SigninManager::Shutdown"; | 233 "SigninManager::Initialize called but not SigninManager::Shutdown"; |
| 208 } | 234 } |
| 209 | 235 |
| 210 void SigninManager::Initialize(Profile* profile) { | 236 void SigninManager::Initialize(Profile* profile) { |
| 211 // Should never call Initialize() twice. | 237 // Should never call Initialize() twice. |
| 212 DCHECK(!IsInitialized()); | 238 DCHECK(!IsInitialized()); |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 if (tok_details->service() == | 904 if (tok_details->service() == |
| 879 GaiaConstants::kGaiaOAuth2LoginRefreshToken) { | 905 GaiaConstants::kGaiaOAuth2LoginRefreshToken) { |
| 880 ubertoken_fetcher_.reset(new UbertokenFetcher(profile_, this)); | 906 ubertoken_fetcher_.reset(new UbertokenFetcher(profile_, this)); |
| 881 ubertoken_fetcher_->StartFetchingToken(); | 907 ubertoken_fetcher_->StartFetchingToken(); |
| 882 | 908 |
| 883 // We only want to do this once per sign-in. | 909 // We only want to do this once per sign-in. |
| 884 CleanupNotificationRegistration(); | 910 CleanupNotificationRegistration(); |
| 885 } | 911 } |
| 886 break; | 912 break; |
| 887 } | 913 } |
| 914 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { |
| 915 // It's possible we're listening to a "stale" renderer because it was |
| 916 // replaced with a new process by process-per-site. In either case, |
| 917 // stop listening to it, but only reset signin_process_id_ tracking |
| 918 // if this was from the current signin process. |
| 919 registrar_.Remove(this, |
| 920 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 921 source); |
| 922 if (signin_process_id_ == |
| 923 content::Source<content::RenderProcessHost>(source)->GetID()) { |
| 924 signin_process_id_ = kInvalidProcessId; |
| 925 } |
| 926 break; |
| 927 } |
| 888 #endif | 928 #endif |
| 889 default: | 929 default: |
| 890 NOTREACHED(); | 930 NOTREACHED(); |
| 891 } | 931 } |
| 892 } | 932 } |
| 893 | 933 |
| 894 void SigninManager::Shutdown() { | 934 void SigninManager::Shutdown() { |
| 895 if (signin_global_error_.get()) { | 935 if (signin_global_error_.get()) { |
| 896 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( | 936 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( |
| 897 signin_global_error_.get()); | 937 signin_global_error_.get()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 NotifySigninValueChanged(field, value)); | 974 NotifySigninValueChanged(field, value)); |
| 935 } | 975 } |
| 936 | 976 |
| 937 void SigninManager::NotifyDiagnosticsObservers( | 977 void SigninManager::NotifyDiagnosticsObservers( |
| 938 const TimedSigninStatusField& field, | 978 const TimedSigninStatusField& field, |
| 939 const std::string& value) { | 979 const std::string& value) { |
| 940 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, | 980 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, |
| 941 signin_diagnostics_observers_, | 981 signin_diagnostics_observers_, |
| 942 NotifySigninValueChanged(field, value)); | 982 NotifySigninValueChanged(field, value)); |
| 943 } | 983 } |
| OLD | NEW |