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

Side by Side Diff: chrome/browser/ui/login/login_handler.cc

Issue 2824363002: Rewrite base::Bind to base::BindOnce with base_bind_rewriters in //chrome/browser/ui (Closed)
Patch Set: Created 3 years, 8 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
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/login/login_handler.h" 5 #include "chrome/browser/ui/login/login_handler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 DCHECK(request_) << "LoginHandler constructed with NULL request"; 114 DCHECK(request_) << "LoginHandler constructed with NULL request";
115 DCHECK(auth_info_.get()) << "LoginHandler constructed with NULL auth info"; 115 DCHECK(auth_info_.get()) << "LoginHandler constructed with NULL auth info";
116 116
117 AddRef(); // matched by LoginHandler::ReleaseSoon(). 117 AddRef(); // matched by LoginHandler::ReleaseSoon().
118 118
119 const content::ResourceRequestInfo* info = 119 const content::ResourceRequestInfo* info =
120 ResourceRequestInfo::ForRequest(request); 120 ResourceRequestInfo::ForRequest(request);
121 DCHECK(info); 121 DCHECK(info);
122 web_contents_getter_ = info->GetWebContentsGetterForRequest(); 122 web_contents_getter_ = info->GetWebContentsGetterForRequest();
123 123
124 BrowserThread::PostTask( 124 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
125 BrowserThread::UI, FROM_HERE, 125 base::BindOnce(&LoginHandler::AddObservers, this));
126 base::Bind(&LoginHandler::AddObservers, this));
127 } 126 }
128 127
129 void LoginHandler::OnRequestCancelled() { 128 void LoginHandler::OnRequestCancelled() {
130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) << 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) <<
131 "Why is OnRequestCancelled called from the UI thread?"; 130 "Why is OnRequestCancelled called from the UI thread?";
132 131
133 // Reference is no longer valid. 132 // Reference is no longer valid.
134 request_ = NULL; 133 request_ = NULL;
135 134
136 // Give up on auth if the request was cancelled. Since the dialog was canceled 135 // Give up on auth if the request was cancelled. Since the dialog was canceled
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 // Calling NotifyAuthSupplied() directly instead of posting a task 203 // Calling NotifyAuthSupplied() directly instead of posting a task
205 // allows other LoginHandler instances to queue their 204 // allows other LoginHandler instances to queue their
206 // CloseContentsDeferred() before ours. Closing dialogs in the 205 // CloseContentsDeferred() before ours. Closing dialogs in the
207 // opposite order as they were created avoids races where remaining 206 // opposite order as they were created avoids races where remaining
208 // dialogs in the same tab may be briefly displayed to the user 207 // dialogs in the same tab may be briefly displayed to the user
209 // before they are removed. 208 // before they are removed.
210 NotifyAuthSupplied(username, password); 209 NotifyAuthSupplied(username, password);
211 210
212 BrowserThread::PostTask( 211 BrowserThread::PostTask(
213 BrowserThread::UI, FROM_HERE, 212 BrowserThread::UI, FROM_HERE,
214 base::Bind(&LoginHandler::CloseContentsDeferred, this)); 213 base::BindOnce(&LoginHandler::CloseContentsDeferred, this));
215 BrowserThread::PostTask( 214 BrowserThread::PostTask(
216 BrowserThread::IO, FROM_HERE, 215 BrowserThread::IO, FROM_HERE,
217 base::Bind(&LoginHandler::SetAuthDeferred, this, username, password)); 216 base::BindOnce(&LoginHandler::SetAuthDeferred, this, username, password));
218 } 217 }
219 218
220 void LoginHandler::CancelAuth() { 219 void LoginHandler::CancelAuth() {
221 // Cancel the auth without canceling the navigation, so that the auth error 220 // Cancel the auth without canceling the navigation, so that the auth error
222 // page commits. 221 // page commits.
223 DoCancelAuth(false); 222 DoCancelAuth(false);
224 } 223 }
225 224
226 void LoginHandler::Observe(int type, 225 void LoginHandler::Observe(int type,
227 const content::NotificationSource& source, 226 const content::NotificationSource& source,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 304
306 service->Notify(chrome::NOTIFICATION_AUTH_NEEDED, 305 service->Notify(chrome::NOTIFICATION_AUTH_NEEDED,
307 content::Source<NavigationController>(controller), 306 content::Source<NavigationController>(controller),
308 content::Details<LoginNotificationDetails>(&details)); 307 content::Details<LoginNotificationDetails>(&details));
309 } 308 }
310 309
311 void LoginHandler::ReleaseSoon() { 310 void LoginHandler::ReleaseSoon() {
312 if (!TestAndSetAuthHandled()) { 311 if (!TestAndSetAuthHandled()) {
313 BrowserThread::PostTask( 312 BrowserThread::PostTask(
314 BrowserThread::IO, FROM_HERE, 313 BrowserThread::IO, FROM_HERE,
315 base::Bind(&LoginHandler::CancelAuthDeferred, this)); 314 base::BindOnce(&LoginHandler::CancelAuthDeferred, this));
316 BrowserThread::PostTask( 315 BrowserThread::PostTask(
317 BrowserThread::UI, FROM_HERE, 316 BrowserThread::UI, FROM_HERE,
318 base::Bind(&LoginHandler::NotifyAuthCancelled, this, false)); 317 base::BindOnce(&LoginHandler::NotifyAuthCancelled, this, false));
319 } 318 }
320 319
321 BrowserThread::PostTask( 320 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
322 BrowserThread::UI, FROM_HERE, 321 base::BindOnce(&LoginHandler::RemoveObservers, this));
323 base::Bind(&LoginHandler::RemoveObservers, this));
324 322
325 // Delete this object once all InvokeLaters have been called. 323 // Delete this object once all InvokeLaters have been called.
326 BrowserThread::ReleaseSoon(BrowserThread::IO, FROM_HERE, this); 324 BrowserThread::ReleaseSoon(BrowserThread::IO, FROM_HERE, this);
327 } 325 }
328 326
329 void LoginHandler::AddObservers() { 327 void LoginHandler::AddObservers() {
330 DCHECK_CURRENTLY_ON(BrowserThread::UI); 328 DCHECK_CURRENTLY_ON(BrowserThread::UI);
331 329
332 // This is probably OK; we need to listen to everything and we break out of 330 // This is probably OK; we need to listen to everything and we break out of
333 // the Observe() if we aren't handling the same auth_info(). 331 // the Observe() if we aren't handling the same auth_info().
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 411
414 void LoginHandler::DoCancelAuth(bool dismiss_navigation) { 412 void LoginHandler::DoCancelAuth(bool dismiss_navigation) {
415 if (TestAndSetAuthHandled()) 413 if (TestAndSetAuthHandled())
416 return; 414 return;
417 415
418 // Similar to how we deal with notifications above in SetAuth(). 416 // Similar to how we deal with notifications above in SetAuth().
419 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { 417 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
420 NotifyAuthCancelled(dismiss_navigation); 418 NotifyAuthCancelled(dismiss_navigation);
421 } else { 419 } else {
422 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 420 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
423 base::Bind(&LoginHandler::NotifyAuthCancelled, this, 421 base::BindOnce(&LoginHandler::NotifyAuthCancelled,
424 dismiss_navigation)); 422 this, dismiss_navigation));
425 } 423 }
426 424
427 BrowserThread::PostTask( 425 BrowserThread::PostTask(
428 BrowserThread::UI, FROM_HERE, 426 BrowserThread::UI, FROM_HERE,
429 base::Bind(&LoginHandler::CloseContentsDeferred, this)); 427 base::BindOnce(&LoginHandler::CloseContentsDeferred, this));
430 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 428 BrowserThread::PostTask(
431 base::Bind(&LoginHandler::CancelAuthDeferred, this)); 429 BrowserThread::IO, FROM_HERE,
430 base::BindOnce(&LoginHandler::CancelAuthDeferred, this));
432 } 431 }
433 432
434 // Calls CancelAuth from the IO loop. 433 // Calls CancelAuth from the IO loop.
435 void LoginHandler::CancelAuthDeferred() { 434 void LoginHandler::CancelAuthDeferred() {
436 DCHECK_CURRENTLY_ON(BrowserThread::IO); 435 DCHECK_CURRENTLY_ON(BrowserThread::IO);
437 436
438 if (request_) { 437 if (request_) {
439 request_->CancelAuth(); 438 request_->CancelAuth();
440 // Verify that CancelAuth doesn't destroy the request via our delegate. 439 // Verify that CancelAuth doesn't destroy the request via our delegate.
441 DCHECK(request_ != NULL); 440 DCHECK(request_ != NULL);
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 // ---------------------------------------------------------------------------- 656 // ----------------------------------------------------------------------------
658 // Public API 657 // Public API
659 658
660 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, 659 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info,
661 net::URLRequest* request) { 660 net::URLRequest* request) {
662 bool is_main_frame = 661 bool is_main_frame =
663 (request->load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0; 662 (request->load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0;
664 LoginHandler* handler = LoginHandler::Create(auth_info, request); 663 LoginHandler* handler = LoginHandler::Create(auth_info, request);
665 BrowserThread::PostTask( 664 BrowserThread::PostTask(
666 BrowserThread::UI, FROM_HERE, 665 BrowserThread::UI, FROM_HERE,
667 base::Bind(&LoginHandler::LoginDialogCallback, request->url(), 666 base::BindOnce(&LoginHandler::LoginDialogCallback, request->url(),
668 base::RetainedRef(auth_info), base::RetainedRef(handler), 667 base::RetainedRef(auth_info), base::RetainedRef(handler),
669 is_main_frame)); 668 is_main_frame));
670 return handler; 669 return handler;
671 } 670 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtkui/print_dialog_gtk.cc ('k') | chrome/browser/ui/prefs/prefs_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698