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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/stl_util.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
20 #include "chrome/browser/profiles/profile_io_data.h" | 21 #include "chrome/browser/profiles/profile_io_data.h" |
21 #include "chrome/common/custom_handlers/protocol_handler.h" | 22 #include "chrome/common/custom_handlers/protocol_handler.h" |
22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
23 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
24 #include "components/pref_registry/pref_registry_syncable.h" | 25 #include "components/pref_registry/pref_registry_syncable.h" |
25 #include "components/prefs/pref_service.h" | 26 #include "components/prefs/pref_service.h" |
26 #include "components/user_prefs/user_prefs.h" | 27 #include "components/user_prefs/user_prefs.h" |
27 #include "content/public/browser/child_process_security_policy.h" | 28 #include "content/public/browser/child_process_security_policy.h" |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 return !delegate_->IsExternalHandlerRegistered(scheme); | 470 return !delegate_->IsExternalHandlerRegistered(scheme); |
470 } | 471 } |
471 | 472 |
472 bool ProtocolHandlerRegistry::IsRegistered( | 473 bool ProtocolHandlerRegistry::IsRegistered( |
473 const ProtocolHandler& handler) const { | 474 const ProtocolHandler& handler) const { |
474 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 475 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
475 const ProtocolHandlerList* handlers = GetHandlerList(handler.protocol()); | 476 const ProtocolHandlerList* handlers = GetHandlerList(handler.protocol()); |
476 if (!handlers) { | 477 if (!handlers) { |
477 return false; | 478 return false; |
478 } | 479 } |
479 return std::find(handlers->begin(), handlers->end(), handler) != | 480 return base::ContainsValue(*handlers, handler); |
480 handlers->end(); | |
481 } | 481 } |
482 | 482 |
483 bool ProtocolHandlerRegistry::IsRegisteredByUser( | 483 bool ProtocolHandlerRegistry::IsRegisteredByUser( |
484 const ProtocolHandler& handler) { | 484 const ProtocolHandler& handler) { |
485 return HandlerExists(handler, &user_protocol_handlers_); | 485 return HandlerExists(handler, &user_protocol_handlers_); |
486 } | 486 } |
487 | 487 |
488 bool ProtocolHandlerRegistry::HasPolicyRegisteredHandler( | 488 bool ProtocolHandlerRegistry::HasPolicyRegisteredHandler( |
489 const std::string& scheme) { | 489 const std::string& scheme) { |
490 return (policy_protocol_handlers_.find(scheme) != | 490 return (policy_protocol_handlers_.find(scheme) != |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 } | 856 } |
857 } | 857 } |
858 | 858 |
859 bool ProtocolHandlerRegistry::HandlerExists(const ProtocolHandler& handler, | 859 bool ProtocolHandlerRegistry::HandlerExists(const ProtocolHandler& handler, |
860 ProtocolHandlerMultiMap* map) { | 860 ProtocolHandlerMultiMap* map) { |
861 return HandlerExists(handler, (*map)[handler.protocol()]); | 861 return HandlerExists(handler, (*map)[handler.protocol()]); |
862 } | 862 } |
863 | 863 |
864 bool ProtocolHandlerRegistry::HandlerExists(const ProtocolHandler& handler, | 864 bool ProtocolHandlerRegistry::HandlerExists(const ProtocolHandler& handler, |
865 const ProtocolHandlerList& list) { | 865 const ProtocolHandlerList& list) { |
866 return std::find(list.begin(), list.end(), handler) != list.end(); | 866 return base::ContainsValue(list, handler); |
867 } | 867 } |
868 | 868 |
869 void ProtocolHandlerRegistry::EraseHandler(const ProtocolHandler& handler, | 869 void ProtocolHandlerRegistry::EraseHandler(const ProtocolHandler& handler, |
870 ProtocolHandlerMultiMap* map) { | 870 ProtocolHandlerMultiMap* map) { |
871 EraseHandler(handler, &(*map)[handler.protocol()]); | 871 EraseHandler(handler, &(*map)[handler.protocol()]); |
872 } | 872 } |
873 | 873 |
874 void ProtocolHandlerRegistry::EraseHandler(const ProtocolHandler& handler, | 874 void ProtocolHandlerRegistry::EraseHandler(const ProtocolHandler& handler, |
875 ProtocolHandlerList* list) { | 875 ProtocolHandlerList* list) { |
876 list->erase(std::find(list->begin(), list->end(), handler)); | 876 list->erase(std::find(list->begin(), list->end(), handler)); |
(...skipping 25 matching lines...) Expand all Loading... |
902 | 902 |
903 std::unique_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 903 std::unique_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
904 ProtocolHandlerRegistry::CreateJobInterceptorFactory() { | 904 ProtocolHandlerRegistry::CreateJobInterceptorFactory() { |
905 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 905 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
906 // this is always created on the UI thread (in profile_io's | 906 // this is always created on the UI thread (in profile_io's |
907 // InitializeOnUIThread. Any method calls must be done | 907 // InitializeOnUIThread. Any method calls must be done |
908 // on the IO thread (this is checked). | 908 // on the IO thread (this is checked). |
909 return std::unique_ptr<JobInterceptorFactory>( | 909 return std::unique_ptr<JobInterceptorFactory>( |
910 new JobInterceptorFactory(io_thread_delegate_.get())); | 910 new JobInterceptorFactory(io_thread_delegate_.get())); |
911 } | 911 } |
OLD | NEW |