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

Side by Side Diff: chrome/browser/custom_handlers/protocol_handler_registry.cc

Issue 2825003002: Rewrite base::Bind to base::BindOnce with base_bind_rewriters in //chrome/browser/{a,b,c,d,e,f,g}* (Closed)
Patch Set: split rest of changes to 3 CLs 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/custom_handlers/protocol_handler_registry.h" 5 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 replaced_handlers.push_back(*p); 348 replaced_handlers.push_back(*p);
349 } 349 }
350 } 350 }
351 return replaced_handlers; 351 return replaced_handlers;
352 } 352 }
353 353
354 void ProtocolHandlerRegistry::ClearDefault(const std::string& scheme) { 354 void ProtocolHandlerRegistry::ClearDefault(const std::string& scheme) {
355 DCHECK_CURRENTLY_ON(BrowserThread::UI); 355 DCHECK_CURRENTLY_ON(BrowserThread::UI);
356 356
357 default_handlers_.erase(scheme); 357 default_handlers_.erase(scheme);
358 BrowserThread::PostTask( 358 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
359 BrowserThread::IO, 359 base::BindOnce(&IOThreadDelegate::ClearDefault,
360 FROM_HERE, 360 io_thread_delegate_, scheme));
361 base::Bind(&IOThreadDelegate::ClearDefault, io_thread_delegate_, scheme));
362 Save(); 361 Save();
363 NotifyChanged(); 362 NotifyChanged();
364 } 363 }
365 364
366 bool ProtocolHandlerRegistry::IsDefault( 365 bool ProtocolHandlerRegistry::IsDefault(
367 const ProtocolHandler& handler) const { 366 const ProtocolHandler& handler) const {
368 DCHECK_CURRENTLY_ON(BrowserThread::UI); 367 DCHECK_CURRENTLY_ON(BrowserThread::UI);
369 return GetHandlerFor(handler.protocol()) == handler; 368 return GetHandlerFor(handler.protocol()) == handler;
370 } 369 }
371 370
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 } 580 }
582 ProtocolHandlerMap::iterator q = default_handlers_.find(handler.protocol()); 581 ProtocolHandlerMap::iterator q = default_handlers_.find(handler.protocol());
583 if (erase_success && q != default_handlers_.end() && q->second == handler) { 582 if (erase_success && q != default_handlers_.end() && q->second == handler) {
584 // Make the new top handler in the list the default. 583 // Make the new top handler in the list the default.
585 if (!handlers.empty()) { 584 if (!handlers.empty()) {
586 // NOTE We pass a copy because SetDefault() modifies handlers. 585 // NOTE We pass a copy because SetDefault() modifies handlers.
587 SetDefault(ProtocolHandler(handlers[0])); 586 SetDefault(ProtocolHandler(handlers[0]));
588 } else { 587 } else {
589 BrowserThread::PostTask( 588 BrowserThread::PostTask(
590 BrowserThread::IO, FROM_HERE, 589 BrowserThread::IO, FROM_HERE,
591 base::Bind(&IOThreadDelegate::ClearDefault, io_thread_delegate_, 590 base::BindOnce(&IOThreadDelegate::ClearDefault, io_thread_delegate_,
592 q->second.protocol())); 591 q->second.protocol()));
593 592
594 default_handlers_.erase(q); 593 default_handlers_.erase(q);
595 } 594 }
596 } 595 }
597 596
598 if (erase_success && !IsHandledProtocol(handler.protocol())) { 597 if (erase_success && !IsHandledProtocol(handler.protocol())) {
599 delegate_->DeregisterExternalHandler(handler.protocol()); 598 delegate_->DeregisterExternalHandler(handler.protocol());
600 } 599 }
601 Save(); 600 Save();
602 if (erase_success) 601 if (erase_success)
(...skipping 13 matching lines...) Expand all
616 return LookupHandler(default_handlers_, scheme); 615 return LookupHandler(default_handlers_, scheme);
617 } 616 }
618 617
619 void ProtocolHandlerRegistry::Enable() { 618 void ProtocolHandlerRegistry::Enable() {
620 DCHECK_CURRENTLY_ON(BrowserThread::UI); 619 DCHECK_CURRENTLY_ON(BrowserThread::UI);
621 if (enabled_) { 620 if (enabled_) {
622 return; 621 return;
623 } 622 }
624 enabled_ = true; 623 enabled_ = true;
625 BrowserThread::PostTask( 624 BrowserThread::PostTask(
626 BrowserThread::IO, 625 BrowserThread::IO, FROM_HERE,
627 FROM_HERE, 626 base::BindOnce(&IOThreadDelegate::Enable, io_thread_delegate_));
628 base::Bind(&IOThreadDelegate::Enable, io_thread_delegate_));
629 627
630 ProtocolHandlerMap::const_iterator p; 628 ProtocolHandlerMap::const_iterator p;
631 for (p = default_handlers_.begin(); p != default_handlers_.end(); ++p) { 629 for (p = default_handlers_.begin(); p != default_handlers_.end(); ++p) {
632 delegate_->RegisterExternalHandler(p->first); 630 delegate_->RegisterExternalHandler(p->first);
633 } 631 }
634 Save(); 632 Save();
635 NotifyChanged(); 633 NotifyChanged();
636 } 634 }
637 635
638 void ProtocolHandlerRegistry::Disable() { 636 void ProtocolHandlerRegistry::Disable() {
639 DCHECK_CURRENTLY_ON(BrowserThread::UI); 637 DCHECK_CURRENTLY_ON(BrowserThread::UI);
640 if (!enabled_) { 638 if (!enabled_) {
641 return; 639 return;
642 } 640 }
643 enabled_ = false; 641 enabled_ = false;
644 BrowserThread::PostTask( 642 BrowserThread::PostTask(
645 BrowserThread::IO, 643 BrowserThread::IO, FROM_HERE,
646 FROM_HERE, 644 base::BindOnce(&IOThreadDelegate::Disable, io_thread_delegate_));
647 base::Bind(&IOThreadDelegate::Disable, io_thread_delegate_));
648 645
649 ProtocolHandlerMap::const_iterator p; 646 ProtocolHandlerMap::const_iterator p;
650 for (p = default_handlers_.begin(); p != default_handlers_.end(); ++p) { 647 for (p = default_handlers_.begin(); p != default_handlers_.end(); ++p) {
651 delegate_->DeregisterExternalHandler(p->first); 648 delegate_->DeregisterExternalHandler(p->first);
652 } 649 }
653 Save(); 650 Save();
654 NotifyChanged(); 651 NotifyChanged();
655 } 652 }
656 653
657 void ProtocolHandlerRegistry::Shutdown() { 654 void ProtocolHandlerRegistry::Shutdown() {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 DCHECK_CURRENTLY_ON(BrowserThread::UI); 715 DCHECK_CURRENTLY_ON(BrowserThread::UI);
719 ProtocolHandlerMap::const_iterator p = default_handlers_.find( 716 ProtocolHandlerMap::const_iterator p = default_handlers_.find(
720 handler.protocol()); 717 handler.protocol());
721 // If we're not loading, and we are setting a default for a new protocol, 718 // If we're not loading, and we are setting a default for a new protocol,
722 // register with the OS. 719 // register with the OS.
723 if (!is_loading_ && p == default_handlers_.end()) 720 if (!is_loading_ && p == default_handlers_.end())
724 delegate_->RegisterWithOSAsDefaultClient(handler.protocol(), this); 721 delegate_->RegisterWithOSAsDefaultClient(handler.protocol(), this);
725 default_handlers_.erase(handler.protocol()); 722 default_handlers_.erase(handler.protocol());
726 default_handlers_.insert(std::make_pair(handler.protocol(), handler)); 723 default_handlers_.insert(std::make_pair(handler.protocol(), handler));
727 PromoteHandler(handler); 724 PromoteHandler(handler);
728 BrowserThread::PostTask( 725 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
729 BrowserThread::IO, 726 base::BindOnce(&IOThreadDelegate::SetDefault,
730 FROM_HERE, 727 io_thread_delegate_, handler));
731 base::Bind(&IOThreadDelegate::SetDefault, io_thread_delegate_, handler));
732 } 728 }
733 729
734 void ProtocolHandlerRegistry::InsertHandler(const ProtocolHandler& handler) { 730 void ProtocolHandlerRegistry::InsertHandler(const ProtocolHandler& handler) {
735 DCHECK_CURRENTLY_ON(BrowserThread::UI); 731 DCHECK_CURRENTLY_ON(BrowserThread::UI);
736 ProtocolHandlerMultiMap::iterator p = 732 ProtocolHandlerMultiMap::iterator p =
737 protocol_handlers_.find(handler.protocol()); 733 protocol_handlers_.find(handler.protocol());
738 734
739 if (p != protocol_handlers_.end()) { 735 if (p != protocol_handlers_.end()) {
740 p->second.push_back(handler); 736 p->second.push_back(handler);
741 return; 737 return;
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 913
918 std::unique_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> 914 std::unique_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
919 ProtocolHandlerRegistry::CreateJobInterceptorFactory() { 915 ProtocolHandlerRegistry::CreateJobInterceptorFactory() {
920 DCHECK_CURRENTLY_ON(BrowserThread::UI); 916 DCHECK_CURRENTLY_ON(BrowserThread::UI);
921 // this is always created on the UI thread (in profile_io's 917 // this is always created on the UI thread (in profile_io's
922 // InitializeOnUIThread. Any method calls must be done 918 // InitializeOnUIThread. Any method calls must be done
923 // on the IO thread (this is checked). 919 // on the IO thread (this is checked).
924 return std::unique_ptr<JobInterceptorFactory>( 920 return std::unique_ptr<JobInterceptorFactory>(
925 new JobInterceptorFactory(io_thread_delegate_.get())); 921 new JobInterceptorFactory(io_thread_delegate_.get()));
926 } 922 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698