Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Unified Diff: chrome/browser/ui/auto_login_info_bar_delegate.cc

Issue 10692074: Stop autologin when the WebContents is destroyed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/auto_login_info_bar_delegate.cc
diff --git a/chrome/browser/ui/auto_login_info_bar_delegate.cc b/chrome/browser/ui/auto_login_info_bar_delegate.cc
index db5c071a1b632e5e2f1c025115969950a52931fe..a76a5e03679c95151004390871f0cea51e61f512 100644
--- a/chrome/browser/ui/auto_login_info_bar_delegate.cc
+++ b/chrome/browser/ui/auto_login_info_bar_delegate.cc
@@ -77,7 +77,8 @@ enum {
// auto-login. It holds context information needed while re-issuing service
// tokens using the TokenService, gets the browser cookies with the TokenAuth
// API, and finally redirects the user to the correct page.
-class AutoLoginRedirector : public UbertokenConsumer {
+class AutoLoginRedirector : public UbertokenConsumer,
+ public content::NotificationObserver {
public:
AutoLoginRedirector(NavigationController* navigation_controller,
const std::string& args);
@@ -88,6 +89,11 @@ class AutoLoginRedirector : public UbertokenConsumer {
virtual void OnUbertokenSuccess(const std::string& token) OVERRIDE;
virtual void OnUbertokenFailure(const GoogleServiceAuthError& error) OVERRIDE;
+ // Implementation of content::NotificationObserver
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
// Redirect tab to MergeSession URL, logging the user in and navigating
// to the desired page.
void RedirectToMergeSession(const std::string& token);
@@ -96,6 +102,9 @@ class AutoLoginRedirector : public UbertokenConsumer {
const std::string args_;
scoped_ptr<UbertokenFetcher> ubertoken_fetcher_;
+ // For listening to NavigationController destruction.
+ content::NotificationRegistrar registrar_;
+
DISALLOW_COPY_AND_ASSIGN(AutoLoginRedirector);
};
@@ -107,12 +116,26 @@ AutoLoginRedirector::AutoLoginRedirector(
ubertoken_fetcher_.reset(new UbertokenFetcher(
Profile::FromBrowserContext(navigation_controller_->GetBrowserContext()),
this));
+ registrar_.Add(this,
+ content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
+ content::Source<content::WebContents>(
+ navigation_controller_->GetWebContents()));
ubertoken_fetcher_->StartFetchingToken();
}
AutoLoginRedirector::~AutoLoginRedirector() {
}
+void AutoLoginRedirector::Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED);
+ // The WebContents that started this has been destroyed. The request must be
+ // cancelled and this object must be deleted.
+ ubertoken_fetcher_.reset();
+ MessageLoop::current()->DeleteSoon(FROM_HERE, this);
+}
+
void AutoLoginRedirector::OnUbertokenSuccess(const std::string& token) {
RedirectToMergeSession(token);
MessageLoop::current()->DeleteSoon(FROM_HERE, this);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698