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

Side by Side 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, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ui/auto_login_info_bar_delegate.h" 5 #include "chrome/browser/ui/auto_login_info_bar_delegate.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 HISTOGRAM_MAX 71 HISTOGRAM_MAX
72 }; 72 };
73 73
74 // AutoLoginRedirector -------------------------------------------------------- 74 // AutoLoginRedirector --------------------------------------------------------
75 75
76 // This class is created by the AutoLoginInfoBarDelegate when the user wishes to 76 // This class is created by the AutoLoginInfoBarDelegate when the user wishes to
77 // auto-login. It holds context information needed while re-issuing service 77 // auto-login. It holds context information needed while re-issuing service
78 // tokens using the TokenService, gets the browser cookies with the TokenAuth 78 // tokens using the TokenService, gets the browser cookies with the TokenAuth
79 // API, and finally redirects the user to the correct page. 79 // API, and finally redirects the user to the correct page.
80 class AutoLoginRedirector : public UbertokenConsumer { 80 class AutoLoginRedirector : public UbertokenConsumer,
81 public content::NotificationObserver {
81 public: 82 public:
82 AutoLoginRedirector(NavigationController* navigation_controller, 83 AutoLoginRedirector(NavigationController* navigation_controller,
83 const std::string& args); 84 const std::string& args);
84 virtual ~AutoLoginRedirector(); 85 virtual ~AutoLoginRedirector();
85 86
86 private: 87 private:
87 // Overriden from UbertokenConsumer: 88 // Overriden from UbertokenConsumer:
88 virtual void OnUbertokenSuccess(const std::string& token) OVERRIDE; 89 virtual void OnUbertokenSuccess(const std::string& token) OVERRIDE;
89 virtual void OnUbertokenFailure(const GoogleServiceAuthError& error) OVERRIDE; 90 virtual void OnUbertokenFailure(const GoogleServiceAuthError& error) OVERRIDE;
90 91
92 // Implementation of content::NotificationObserver
93 virtual void Observe(int type,
94 const content::NotificationSource& source,
95 const content::NotificationDetails& details) OVERRIDE;
96
91 // Redirect tab to MergeSession URL, logging the user in and navigating 97 // Redirect tab to MergeSession URL, logging the user in and navigating
92 // to the desired page. 98 // to the desired page.
93 void RedirectToMergeSession(const std::string& token); 99 void RedirectToMergeSession(const std::string& token);
94 100
95 NavigationController* navigation_controller_; 101 NavigationController* navigation_controller_;
96 const std::string args_; 102 const std::string args_;
97 scoped_ptr<UbertokenFetcher> ubertoken_fetcher_; 103 scoped_ptr<UbertokenFetcher> ubertoken_fetcher_;
98 104
105 // For listening to NavigationController destruction.
106 content::NotificationRegistrar registrar_;
107
99 DISALLOW_COPY_AND_ASSIGN(AutoLoginRedirector); 108 DISALLOW_COPY_AND_ASSIGN(AutoLoginRedirector);
100 }; 109 };
101 110
102 AutoLoginRedirector::AutoLoginRedirector( 111 AutoLoginRedirector::AutoLoginRedirector(
103 NavigationController* navigation_controller, 112 NavigationController* navigation_controller,
104 const std::string& args) 113 const std::string& args)
105 : navigation_controller_(navigation_controller), 114 : navigation_controller_(navigation_controller),
106 args_(args) { 115 args_(args) {
107 ubertoken_fetcher_.reset(new UbertokenFetcher( 116 ubertoken_fetcher_.reset(new UbertokenFetcher(
108 Profile::FromBrowserContext(navigation_controller_->GetBrowserContext()), 117 Profile::FromBrowserContext(navigation_controller_->GetBrowserContext()),
109 this)); 118 this));
119 registrar_.Add(this,
120 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
121 content::Source<content::WebContents>(
122 navigation_controller_->GetWebContents()));
110 ubertoken_fetcher_->StartFetchingToken(); 123 ubertoken_fetcher_->StartFetchingToken();
111 } 124 }
112 125
113 AutoLoginRedirector::~AutoLoginRedirector() { 126 AutoLoginRedirector::~AutoLoginRedirector() {
114 } 127 }
115 128
129 void AutoLoginRedirector::Observe(int type,
130 const NotificationSource& source,
131 const NotificationDetails& details) {
132 DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED);
133 // The WebContents that started this has been destroyed. The request must be
134 // cancelled and this object must be deleted.
135 ubertoken_fetcher_.reset();
136 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
137 }
138
116 void AutoLoginRedirector::OnUbertokenSuccess(const std::string& token) { 139 void AutoLoginRedirector::OnUbertokenSuccess(const std::string& token) {
117 RedirectToMergeSession(token); 140 RedirectToMergeSession(token);
118 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 141 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
119 } 142 }
120 143
121 void AutoLoginRedirector::OnUbertokenFailure( 144 void AutoLoginRedirector::OnUbertokenFailure(
122 const GoogleServiceAuthError& error) { 145 const GoogleServiceAuthError& error) {
123 LOG(WARNING) << "AutoLoginRedirector: token request failed"; 146 LOG(WARNING) << "AutoLoginRedirector: token request failed";
124 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 147 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
125 } 148 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 void AutoLoginInfoBarDelegate::RecordHistogramAction(int action) { 240 void AutoLoginInfoBarDelegate::RecordHistogramAction(int action) {
218 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Regular", action, HISTOGRAM_MAX); 241 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Regular", action, HISTOGRAM_MAX);
219 } 242 }
220 243
221 void AutoLoginInfoBarDelegate::Observe(int type, 244 void AutoLoginInfoBarDelegate::Observe(int type,
222 const NotificationSource& source, 245 const NotificationSource& source,
223 const NotificationDetails& details) { 246 const NotificationDetails& details) {
224 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, type); 247 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, type);
225 owner()->RemoveInfoBar(this); 248 owner()->RemoveInfoBar(this);
226 } 249 }
OLDNEW
« 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