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/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "google_apis/gaia/gaia_constants.h" | 39 #include "google_apis/gaia/gaia_constants.h" |
40 #include "google_apis/gaia/gaia_urls.h" | 40 #include "google_apis/gaia/gaia_urls.h" |
41 #include "net/base/escape.h" | 41 #include "net/base/escape.h" |
42 #include "net/url_request/url_request_context.h" | 42 #include "net/url_request/url_request_context.h" |
43 #include "third_party/icu/source/i18n/unicode/regex.h" | 43 #include "third_party/icu/source/i18n/unicode/regex.h" |
44 | 44 |
45 using namespace signin_internals_util; | 45 using namespace signin_internals_util; |
46 | 46 |
47 using content::BrowserThread; | 47 using content::BrowserThread; |
48 using content::ChildProcessHost; | 48 using content::ChildProcessHost; |
| 49 using content::RenderProcessHost; |
49 | 50 |
50 namespace { | 51 namespace { |
51 | 52 |
52 const char kGetInfoDisplayEmailKey[] = "displayEmail"; | 53 const char kGetInfoDisplayEmailKey[] = "displayEmail"; |
53 const char kGetInfoEmailKey[] = "email"; | 54 const char kGetInfoEmailKey[] = "email"; |
54 | 55 |
55 const char kChromiumSyncService[] = "service=chromiumsync"; | 56 const char kChromiumSyncService[] = "service=chromiumsync"; |
56 | 57 |
57 } // namespace | 58 } // namespace |
58 | 59 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 delegate_(delegate.Pass()) { | 91 delegate_(delegate.Pass()) { |
91 } | 92 } |
92 | 93 |
93 void SigninManager::SetSigninProcess(int process_id) { | 94 void SigninManager::SetSigninProcess(int process_id) { |
94 if (process_id == signin_host_id_) | 95 if (process_id == signin_host_id_) |
95 return; | 96 return; |
96 DLOG_IF(WARNING, | 97 DLOG_IF(WARNING, |
97 signin_host_id_ != ChildProcessHost::kInvalidUniqueID) | 98 signin_host_id_ != ChildProcessHost::kInvalidUniqueID) |
98 << "Replacing in-use signin process."; | 99 << "Replacing in-use signin process."; |
99 signin_host_id_ = process_id; | 100 signin_host_id_ = process_id; |
100 const content::RenderProcessHost* process = | 101 RenderProcessHost* host = RenderProcessHost::FromID(process_id); |
101 content::RenderProcessHost::FromID(process_id); | 102 DCHECK(host); |
102 DCHECK(process); | 103 host->AddObserver(this); |
103 registrar_.Add(this, | 104 signin_hosts_observed_.insert(host); |
104 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
105 content::Source<content::RenderProcessHost>(process)); | |
106 } | 105 } |
107 | 106 |
108 void SigninManager::ClearSigninProcess() { | 107 void SigninManager::ClearSigninProcess() { |
109 signin_host_id_ = ChildProcessHost::kInvalidUniqueID; | 108 signin_host_id_ = ChildProcessHost::kInvalidUniqueID; |
110 } | 109 } |
111 | 110 |
112 bool SigninManager::IsSigninProcess(int process_id) const { | 111 bool SigninManager::IsSigninProcess(int process_id) const { |
113 return process_id == signin_host_id_; | 112 return process_id == signin_host_id_; |
114 } | 113 } |
115 | 114 |
116 bool SigninManager::HasSigninProcess() const { | 115 bool SigninManager::HasSigninProcess() const { |
117 return signin_host_id_ != ChildProcessHost::kInvalidUniqueID; | 116 return signin_host_id_ != ChildProcessHost::kInvalidUniqueID; |
118 } | 117 } |
119 | 118 |
120 void SigninManager::AddMergeSessionObserver( | 119 void SigninManager::AddMergeSessionObserver( |
121 GoogleAutoLoginHelper::Observer* observer) { | 120 GoogleAutoLoginHelper::Observer* observer) { |
122 if (merge_session_helper_) | 121 if (merge_session_helper_) |
123 merge_session_helper_->AddObserver(observer); | 122 merge_session_helper_->AddObserver(observer); |
124 } | 123 } |
125 | 124 |
126 void SigninManager::RemoveMergeSessionObserver( | 125 void SigninManager::RemoveMergeSessionObserver( |
127 GoogleAutoLoginHelper::Observer* observer) { | 126 GoogleAutoLoginHelper::Observer* observer) { |
128 if (merge_session_helper_) | 127 if (merge_session_helper_) |
129 merge_session_helper_->RemoveObserver(observer); | 128 merge_session_helper_->RemoveObserver(observer); |
130 } | 129 } |
131 | 130 |
132 SigninManager::~SigninManager() { | 131 SigninManager::~SigninManager() { |
| 132 std::set<RenderProcessHost*>::iterator i; |
| 133 for (i = signin_hosts_observed_.begin(); |
| 134 i != signin_hosts_observed_.end(); |
| 135 ++i) { |
| 136 (*i)->RemoveObserver(this); |
| 137 } |
133 } | 138 } |
134 | 139 |
135 void SigninManager::InitTokenService() { | 140 void SigninManager::InitTokenService() { |
136 ProfileOAuth2TokenService* token_service = | 141 ProfileOAuth2TokenService* token_service = |
137 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 142 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
138 if (token_service && !GetAuthenticatedUsername().empty()) | 143 if (token_service && !GetAuthenticatedUsername().empty()) |
139 token_service->LoadCredentials(); | 144 token_service->LoadCredentials(); |
140 } | 145 } |
141 | 146 |
142 std::string SigninManager::SigninTypeToString( | 147 std::string SigninManager::SigninTypeToString( |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 DisableOneClickSignIn(profile_); // Don't ever offer again. | 625 DisableOneClickSignIn(profile_); // Don't ever offer again. |
621 } | 626 } |
622 | 627 |
623 void SigninManager::OnGetUserInfoFailure(const GoogleServiceAuthError& error) { | 628 void SigninManager::OnGetUserInfoFailure(const GoogleServiceAuthError& error) { |
624 LOG(ERROR) << "Unable to retreive the canonical email address. Login failed."; | 629 LOG(ERROR) << "Unable to retreive the canonical email address. Login failed."; |
625 NotifyDiagnosticsObservers(GET_USER_INFO_STATUS, error.ToString()); | 630 NotifyDiagnosticsObservers(GET_USER_INFO_STATUS, error.ToString()); |
626 // REVIEW: why does this call OnClientLoginFailure? | 631 // REVIEW: why does this call OnClientLoginFailure? |
627 OnClientLoginFailure(error); | 632 OnClientLoginFailure(error); |
628 } | 633 } |
629 | 634 |
630 void SigninManager::Observe(int type, | 635 void SigninManager::RenderProcessHostDestroyed(RenderProcessHost* host) { |
631 const content::NotificationSource& source, | 636 // It's possible we're listening to a "stale" renderer because it was replaced |
632 const content::NotificationDetails& details) { | 637 // with a new process by process-per-site. In either case, stop observing it, |
633 DCHECK_EQ(content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, type); | 638 // but only reset signin_host_id_ tracking if this was from the current signin |
634 | 639 // process. |
635 // It's possible we're listening to a "stale" renderer because it was | 640 signin_hosts_observed_.erase(host); |
636 // replaced with a new process by process-per-site. In either case, | 641 if (signin_host_id_ == host->GetID()) |
637 // stop listening to it, but only reset signin_host_id_ tracking | |
638 // if this was from the current signin process. | |
639 registrar_.Remove(this, | |
640 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
641 source); | |
642 if (signin_host_id_ == | |
643 content::Source<content::RenderProcessHost>(source)->GetID()) { | |
644 signin_host_id_ = ChildProcessHost::kInvalidUniqueID; | 642 signin_host_id_ = ChildProcessHost::kInvalidUniqueID; |
645 } | |
646 } | 643 } |
647 | 644 |
648 void SigninManager::ProhibitSignout(bool prohibit_signout) { | 645 void SigninManager::ProhibitSignout(bool prohibit_signout) { |
649 prohibit_signout_ = prohibit_signout; | 646 prohibit_signout_ = prohibit_signout; |
650 } | 647 } |
651 | 648 |
652 bool SigninManager::IsSignoutProhibited() const { | 649 bool SigninManager::IsSignoutProhibited() const { |
653 return prohibit_signout_; | 650 return prohibit_signout_; |
654 } | 651 } |
OLD | NEW |