| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "base/task.h" | 12 #include "base/task.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/custom_handlers/protocol_handler.h" | 14 #include "chrome/browser/custom_handlers/protocol_handler.h" |
| 15 #include "chrome/common/chrome_notification_types.h" |
| 15 #include "chrome/test/testing_browser_process.h" | 16 #include "chrome/test/testing_browser_process.h" |
| 16 #include "chrome/test/testing_browser_process_test.h" | 17 #include "chrome/test/testing_browser_process_test.h" |
| 17 #include "chrome/test/testing_pref_service.h" | 18 #include "chrome/test/testing_pref_service.h" |
| 18 #include "chrome/test/testing_profile.h" | 19 #include "chrome/test/testing_profile.h" |
| 19 #include "content/browser/browser_thread.h" | 20 #include "content/browser/browser_thread.h" |
| 20 #include "content/browser/renderer_host/test_render_view_host.h" | 21 #include "content/browser/renderer_host/test_render_view_host.h" |
| 21 #include "content/common/notification_observer.h" | 22 #include "content/common/notification_observer.h" |
| 22 #include "content/common/notification_registrar.h" | 23 #include "content/common/notification_registrar.h" |
| 23 #include "content/common/notification_service.h" | 24 #include "content/common/notification_service.h" |
| 24 #include "net/url_request/url_request.h" | 25 #include "net/url_request/url_request.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 std::set<std::string> registered_protocols_; | 61 std::set<std::string> registered_protocols_; |
| 61 std::set<std::string> os_registered_protocols_; | 62 std::set<std::string> os_registered_protocols_; |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 class NotificationCounter : public NotificationObserver { | 65 class NotificationCounter : public NotificationObserver { |
| 65 public: | 66 public: |
| 66 NotificationCounter() | 67 NotificationCounter() |
| 67 : events_(0), | 68 : events_(0), |
| 68 notification_registrar_() { | 69 notification_registrar_() { |
| 69 notification_registrar_.Add(this, | 70 notification_registrar_.Add(this, |
| 70 NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED, | 71 chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, |
| 71 NotificationService::AllSources()); | 72 NotificationService::AllSources()); |
| 72 } | 73 } |
| 73 | 74 |
| 74 ~NotificationCounter() { | 75 ~NotificationCounter() { |
| 75 notification_registrar_.Remove(this, | 76 notification_registrar_.Remove(this, |
| 76 NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED, | 77 chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, |
| 77 NotificationService::AllSources()); | 78 NotificationService::AllSources()); |
| 78 } | 79 } |
| 79 | 80 |
| 80 int events() { return events_; } | 81 int events() { return events_; } |
| 81 bool notified() { return events_ > 0; } | 82 bool notified() { return events_ > 0; } |
| 82 void Clear() { events_ = 0; } | 83 void Clear() { events_ = 0; } |
| 83 virtual void Observe(NotificationType type, | 84 virtual void Observe(int type, |
| 84 const NotificationSource& source, | 85 const NotificationSource& source, |
| 85 const NotificationDetails& details) { | 86 const NotificationDetails& details) { |
| 86 ++events_; | 87 ++events_; |
| 87 } | 88 } |
| 88 | 89 |
| 89 int events_; | 90 int events_; |
| 90 NotificationRegistrar notification_registrar_; | 91 NotificationRegistrar notification_registrar_; |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 class QueryProtocolHandlerOnChange : public NotificationObserver { | 94 class QueryProtocolHandlerOnChange : public NotificationObserver { |
| 94 public: | 95 public: |
| 95 explicit QueryProtocolHandlerOnChange(ProtocolHandlerRegistry* registry) | 96 explicit QueryProtocolHandlerOnChange(ProtocolHandlerRegistry* registry) |
| 96 : registry_(registry), | 97 : registry_(registry), |
| 97 called_(false), | 98 called_(false), |
| 98 notification_registrar_() { | 99 notification_registrar_() { |
| 99 notification_registrar_.Add(this, | 100 notification_registrar_.Add(this, |
| 100 NotificationType::PROTOCOL_HANDLER_REGISTRY_CHANGED, | 101 chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, |
| 101 NotificationService::AllSources()); | 102 NotificationService::AllSources()); |
| 102 } | 103 } |
| 103 | 104 |
| 104 virtual void Observe(NotificationType type, | 105 virtual void Observe(int type, |
| 105 const NotificationSource& source, | 106 const NotificationSource& source, |
| 106 const NotificationDetails& details) { | 107 const NotificationDetails& details) { |
| 107 std::vector<std::string> output; | 108 std::vector<std::string> output; |
| 108 registry_->GetRegisteredProtocols(&output); | 109 registry_->GetRegisteredProtocols(&output); |
| 109 called_ = true; | 110 called_ = true; |
| 110 } | 111 } |
| 111 | 112 |
| 112 ProtocolHandlerRegistry* registry_; | 113 ProtocolHandlerRegistry* registry_; |
| 113 bool called_; | 114 bool called_; |
| 114 NotificationRegistrar notification_registrar_; | 115 NotificationRegistrar notification_registrar_; |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 } | 520 } |
| 520 | 521 |
| 521 TEST_F(ProtocolHandlerRegistryTest, TestLoadEnabledGetsPropogatedToIO) { | 522 TEST_F(ProtocolHandlerRegistryTest, TestLoadEnabledGetsPropogatedToIO) { |
| 522 registry()->Disable(); | 523 registry()->Disable(); |
| 523 ReloadProtocolHandlerRegistry(); | 524 ReloadProtocolHandlerRegistry(); |
| 524 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 525 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 525 NewRunnableFunction(QuitUILoop)); | 526 NewRunnableFunction(QuitUILoop)); |
| 526 MessageLoop::current()->Run(); | 527 MessageLoop::current()->Run(); |
| 527 ASSERT_FALSE(enabled_io()); | 528 ASSERT_FALSE(enabled_io()); |
| 528 } | 529 } |
| OLD | NEW |