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/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/string_split.h" | 11 #include "base/string_split.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/content_settings/cookie_settings.h" | 16 #include "chrome/browser/content_settings/cookie_settings.h" |
17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/signin/about_signin_internals.h" | 19 #include "chrome/browser/signin/about_signin_internals.h" |
20 #include "chrome/browser/signin/about_signin_internals_factory.h" | 20 #include "chrome/browser/signin/about_signin_internals_factory.h" |
21 #include "chrome/browser/signin/signin_global_error.h" | |
22 #include "chrome/browser/signin/signin_internals_util.h" | 21 #include "chrome/browser/signin/signin_internals_util.h" |
23 #include "chrome/browser/signin/token_service.h" | 22 #include "chrome/browser/signin/token_service.h" |
24 #include "chrome/browser/signin/token_service_factory.h" | 23 #include "chrome/browser/signin/token_service_factory.h" |
25 #include "chrome/browser/sync/profile_sync_service.h" | 24 #include "chrome/browser/sync/profile_sync_service.h" |
26 #include "chrome/browser/ui/global_error/global_error_service.h" | |
27 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | |
28 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
29 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
30 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
31 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
32 #include "google_apis/gaia/gaia_auth_fetcher.h" | 29 #include "google_apis/gaia/gaia_auth_fetcher.h" |
33 #include "google_apis/gaia/gaia_constants.h" | 30 #include "google_apis/gaia/gaia_constants.h" |
34 #include "google_apis/gaia/gaia_urls.h" | 31 #include "google_apis/gaia/gaia_urls.h" |
35 #include "net/cookies/cookie_monster.h" | 32 #include "net/cookies/cookie_monster.h" |
36 #include "third_party/icu/public/i18n/unicode/regex.h" | 33 #include "third_party/icu/public/i18n/unicode/regex.h" |
37 | 34 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 DCHECK(U_SUCCESS(status)); | 92 DCHECK(U_SUCCESS(status)); |
96 return !!match; // !! == convert from UBool to bool. | 93 return !!match; // !! == convert from UBool to bool. |
97 } | 94 } |
98 | 95 |
99 SigninManager::SigninManager() | 96 SigninManager::SigninManager() |
100 : profile_(NULL), | 97 : profile_(NULL), |
101 had_two_factor_error_(false), | 98 had_two_factor_error_(false), |
102 type_(SIGNIN_TYPE_NONE) { | 99 type_(SIGNIN_TYPE_NONE) { |
103 } | 100 } |
104 | 101 |
105 SigninManager::~SigninManager() { | 102 SigninManager::~SigninManager() {} |
106 DCHECK(!signin_global_error_.get()) << | |
107 "SigninManager::Initialize called but not SigninManager::Shutdown"; | |
108 } | |
109 | 103 |
110 void SigninManager::Initialize(Profile* profile) { | 104 void SigninManager::Initialize(Profile* profile) { |
111 // Should never call Initialize() twice. | 105 // Should never call Initialize() twice. |
112 DCHECK(!IsInitialized()); | 106 DCHECK(!IsInitialized()); |
113 profile_ = profile; | 107 profile_ = profile; |
114 signin_global_error_.reset(new SigninGlobalError(profile)); | |
115 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( | |
116 signin_global_error_.get()); | |
117 PrefService* local_state = g_browser_process->local_state(); | 108 PrefService* local_state = g_browser_process->local_state(); |
118 // local_state can be null during unit tests. | 109 // local_state can be null during unit tests. |
119 if (local_state) { | 110 if (local_state) { |
120 local_state_pref_registrar_.Init(local_state); | 111 local_state_pref_registrar_.Init(local_state); |
121 local_state_pref_registrar_.Add( | 112 local_state_pref_registrar_.Add( |
122 prefs::kGoogleServicesUsernamePattern, | 113 prefs::kGoogleServicesUsernamePattern, |
123 base::Bind(&SigninManager::OnGoogleServicesUsernamePatternChanged, | 114 base::Bind(&SigninManager::OnGoogleServicesUsernamePatternChanged, |
124 base::Unretained(this))); | 115 base::Unretained(this))); |
125 } | 116 } |
126 | 117 |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 CleanupNotificationRegistration(); | 598 CleanupNotificationRegistration(); |
608 } | 599 } |
609 break; | 600 break; |
610 } | 601 } |
611 #endif | 602 #endif |
612 default: | 603 default: |
613 NOTREACHED(); | 604 NOTREACHED(); |
614 } | 605 } |
615 } | 606 } |
616 | 607 |
617 void SigninManager::Shutdown() { | |
618 if (signin_global_error_.get()) { | |
619 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( | |
620 signin_global_error_.get()); | |
621 signin_global_error_.reset(); | |
622 } | |
623 } | |
624 | |
625 void SigninManager::OnGoogleServicesUsernamePatternChanged() { | 608 void SigninManager::OnGoogleServicesUsernamePatternChanged() { |
626 if (!authenticated_username_.empty() && | 609 if (!authenticated_username_.empty() && |
627 !IsAllowedUsername(authenticated_username_)) { | 610 !IsAllowedUsername(authenticated_username_)) { |
628 // Signed in user is invalid according to the current policy so sign | 611 // Signed in user is invalid according to the current policy so sign |
629 // the user out. | 612 // the user out. |
630 SignOut(); | 613 SignOut(); |
631 } | 614 } |
632 } | 615 } |
633 | 616 |
634 void SigninManager::AddSigninDiagnosticsObserver( | 617 void SigninManager::AddSigninDiagnosticsObserver( |
(...skipping 14 matching lines...) Expand all Loading... |
649 NotifySigninValueChanged(field, value)); | 632 NotifySigninValueChanged(field, value)); |
650 } | 633 } |
651 | 634 |
652 void SigninManager::NotifyDiagnosticsObservers( | 635 void SigninManager::NotifyDiagnosticsObservers( |
653 const TimedSigninStatusField& field, | 636 const TimedSigninStatusField& field, |
654 const std::string& value) { | 637 const std::string& value) { |
655 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, | 638 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, |
656 signin_diagnostics_observers_, | 639 signin_diagnostics_observers_, |
657 NotifySigninValueChanged(field, value)); | 640 NotifySigninValueChanged(field, value)); |
658 } | 641 } |
OLD | NEW |