| 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/custom_handlers/protocol_handler_registry.h" | 5 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 const ProtocolHandler& handler) const { | 526 const ProtocolHandler& handler) const { |
| 527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 528 const ProtocolHandlerList* handlers = GetHandlerList(handler.protocol()); | 528 const ProtocolHandlerList* handlers = GetHandlerList(handler.protocol()); |
| 529 if (!handlers) { | 529 if (!handlers) { |
| 530 return false; | 530 return false; |
| 531 } | 531 } |
| 532 return std::find(handlers->begin(), handlers->end(), handler) != | 532 return std::find(handlers->begin(), handlers->end(), handler) != |
| 533 handlers->end(); | 533 handlers->end(); |
| 534 } | 534 } |
| 535 | 535 |
| 536 bool ProtocolHandlerRegistry::IsRegisteredByUser( |
| 537 const ProtocolHandler& handler) { |
| 538 return HandlerExists(handler, &user_protocol_handlers_); |
| 539 } |
| 540 |
| 536 bool ProtocolHandlerRegistry::IsIgnored(const ProtocolHandler& handler) const { | 541 bool ProtocolHandlerRegistry::IsIgnored(const ProtocolHandler& handler) const { |
| 537 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 542 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 538 ProtocolHandlerList::const_iterator i; | 543 ProtocolHandlerList::const_iterator i; |
| 539 for (i = ignored_protocol_handlers_.begin(); | 544 for (i = ignored_protocol_handlers_.begin(); |
| 540 i != ignored_protocol_handlers_.end(); ++i) { | 545 i != ignored_protocol_handlers_.end(); ++i) { |
| 541 if (*i == handler) { | 546 if (*i == handler) { |
| 542 return true; | 547 return true; |
| 543 } | 548 } |
| 544 } | 549 } |
| 545 return false; | 550 return false; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 } | 603 } |
| 599 | 604 |
| 600 void ProtocolHandlerRegistry::RemoveHandler( | 605 void ProtocolHandlerRegistry::RemoveHandler( |
| 601 const ProtocolHandler& handler) { | 606 const ProtocolHandler& handler) { |
| 602 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 607 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 603 ProtocolHandlerList& handlers = protocol_handlers_[handler.protocol()]; | 608 ProtocolHandlerList& handlers = protocol_handlers_[handler.protocol()]; |
| 604 bool erase_success = false; | 609 bool erase_success = false; |
| 605 if (HandlerExists(handler, handlers) && | 610 if (HandlerExists(handler, handlers) && |
| 606 HandlerExists(handler, &user_protocol_handlers_)) { | 611 HandlerExists(handler, &user_protocol_handlers_)) { |
| 607 EraseHandler(handler, &user_protocol_handlers_); | 612 EraseHandler(handler, &user_protocol_handlers_); |
| 608 if (!HandlerExists(handler, &policy_protocol_handlers_)) { | 613 erase_success = true; |
| 609 erase_success = true; | 614 if (!HandlerExists(handler, &policy_protocol_handlers_)) |
| 610 EraseHandler(handler, &protocol_handlers_); | 615 EraseHandler(handler, &protocol_handlers_); |
| 611 } | |
| 612 } | 616 } |
| 613 ProtocolHandlerMap::iterator q = default_handlers_.find(handler.protocol()); | 617 ProtocolHandlerMap::iterator q = default_handlers_.find(handler.protocol()); |
| 614 if (erase_success && q != default_handlers_.end() && q->second == handler) { | 618 if (erase_success && q != default_handlers_.end() && q->second == handler) { |
| 615 // Make the new top handler in the list the default. | 619 // Make the new top handler in the list the default. |
| 616 if (!handlers.empty()) { | 620 if (!handlers.empty()) { |
| 617 // NOTE We pass a copy because SetDefault() modifies handlers. | 621 // NOTE We pass a copy because SetDefault() modifies handlers. |
| 618 SetDefault(ProtocolHandler(handlers[0])); | 622 SetDefault(ProtocolHandler(handlers[0])); |
| 619 } else { | 623 } else { |
| 620 BrowserThread::PostTask( | 624 BrowserThread::PostTask( |
| 621 BrowserThread::IO, FROM_HERE, | 625 BrowserThread::IO, FROM_HERE, |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 | 948 |
| 945 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 949 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 946 ProtocolHandlerRegistry::CreateJobInterceptorFactory() { | 950 ProtocolHandlerRegistry::CreateJobInterceptorFactory() { |
| 947 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 951 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 948 // this is always created on the UI thread (in profile_io's | 952 // this is always created on the UI thread (in profile_io's |
| 949 // InitializeOnUIThread. Any method calls must be done | 953 // InitializeOnUIThread. Any method calls must be done |
| 950 // on the IO thread (this is checked). | 954 // on the IO thread (this is checked). |
| 951 return scoped_ptr<JobInterceptorFactory>( | 955 return scoped_ptr<JobInterceptorFactory>( |
| 952 new JobInterceptorFactory(io_thread_delegate_.get())); | 956 new JobInterceptorFactory(io_thread_delegate_.get())); |
| 953 } | 957 } |
| OLD | NEW |