Chromium Code Reviews| 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 CHECK_EQ(signin_process_id_, kInvalidProcessId); | |
|
Charlie Reis
2013/02/28 19:19:46
I don't think we can enforce this CHECK. There ar
tim (not reviewing)
2013/03/01 01:53:57
Done.
| |
| 213 signin_process_id_ = process_id; | |
| 214 const content::RenderProcessHost* process = | |
| 215 content::RenderProcessHost::FromID(process_id); | |
| 216 DCHECK(process); | |
| 217 registrar_.Add(this, | |
| 218 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
| 219 content::Source<content::RenderProcessHost>(process)); | |
| 220 } | |
| 221 | |
| 222 bool SigninManager::IsSigninProcess(int process_id) const { | |
| 223 return process_id == signin_process_id_; | |
| 203 } | 224 } |
| 204 | 225 |
| 205 SigninManager::~SigninManager() { | 226 SigninManager::~SigninManager() { |
| 206 DCHECK(!signin_global_error_.get()) << | 227 DCHECK(!signin_global_error_.get()) << |
| 207 "SigninManager::Initialize called but not SigninManager::Shutdown"; | 228 "SigninManager::Initialize called but not SigninManager::Shutdown"; |
| 208 } | 229 } |
| 209 | 230 |
| 210 void SigninManager::Initialize(Profile* profile) { | 231 void SigninManager::Initialize(Profile* profile) { |
| 211 // Should never call Initialize() twice. | 232 // Should never call Initialize() twice. |
| 212 DCHECK(!IsInitialized()); | 233 DCHECK(!IsInitialized()); |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 878 if (tok_details->service() == | 899 if (tok_details->service() == |
| 879 GaiaConstants::kGaiaOAuth2LoginRefreshToken) { | 900 GaiaConstants::kGaiaOAuth2LoginRefreshToken) { |
| 880 ubertoken_fetcher_.reset(new UbertokenFetcher(profile_, this)); | 901 ubertoken_fetcher_.reset(new UbertokenFetcher(profile_, this)); |
| 881 ubertoken_fetcher_->StartFetchingToken(); | 902 ubertoken_fetcher_->StartFetchingToken(); |
| 882 | 903 |
| 883 // We only want to do this once per sign-in. | 904 // We only want to do this once per sign-in. |
| 884 CleanupNotificationRegistration(); | 905 CleanupNotificationRegistration(); |
| 885 } | 906 } |
| 886 break; | 907 break; |
| 887 } | 908 } |
| 909 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { | |
| 910 DCHECK_EQ(signin_process_id_, | |
|
Charlie Reis
2013/02/28 19:19:46
Similar to above, this should be an if rather than
tim (not reviewing)
2013/03/01 01:53:57
Done.
| |
| 911 content::Source<content::RenderProcessHost>(source)->GetID()); | |
| 912 signin_process_id_ = kInvalidProcessId; | |
| 913 registrar_.Remove(this, | |
| 914 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
| 915 source); | |
| 916 break; | |
| 917 } | |
| 888 #endif | 918 #endif |
| 889 default: | 919 default: |
| 890 NOTREACHED(); | 920 NOTREACHED(); |
| 891 } | 921 } |
| 892 } | 922 } |
| 893 | 923 |
| 894 void SigninManager::Shutdown() { | 924 void SigninManager::Shutdown() { |
| 895 if (signin_global_error_.get()) { | 925 if (signin_global_error_.get()) { |
| 896 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( | 926 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( |
| 897 signin_global_error_.get()); | 927 signin_global_error_.get()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 934 NotifySigninValueChanged(field, value)); | 964 NotifySigninValueChanged(field, value)); |
| 935 } | 965 } |
| 936 | 966 |
| 937 void SigninManager::NotifyDiagnosticsObservers( | 967 void SigninManager::NotifyDiagnosticsObservers( |
| 938 const TimedSigninStatusField& field, | 968 const TimedSigninStatusField& field, |
| 939 const std::string& value) { | 969 const std::string& value) { |
| 940 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, | 970 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, |
| 941 signin_diagnostics_observers_, | 971 signin_diagnostics_observers_, |
| 942 NotifySigninValueChanged(field, value)); | 972 NotifySigninValueChanged(field, value)); |
| 943 } | 973 } |
| OLD | NEW |