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/extensions/event_router_forwarder.h" | 5 #include "chrome/browser/extensions/event_router_forwarder.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
9 #include "base/power_monitor/power_monitor.h" | 11 #include "base/power_monitor/power_monitor.h" |
10 #include "base/power_monitor/power_monitor_device_source.h" | 12 #include "base/power_monitor/power_monitor_device_source.h" |
11 #include "base/test/thread_test_helper.h" | 13 #include "base/test/thread_test_helper.h" |
12 #include "build/build_config.h" | 14 #include "build/build_config.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/test/base/testing_browser_process.h" | 16 #include "chrome/test/base/testing_browser_process.h" |
15 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
16 #include "chrome/test/base/testing_profile_manager.h" | 18 #include "chrome/test/base/testing_profile_manager.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 protected: | 56 protected: |
55 virtual ~MockEventRouterForwarder() {} | 57 virtual ~MockEventRouterForwarder() {} |
56 }; | 58 }; |
57 | 59 |
58 static void BroadcastEventToRenderers(EventRouterForwarder* event_router, | 60 static void BroadcastEventToRenderers(EventRouterForwarder* event_router, |
59 events::HistogramValue histogram_value, | 61 events::HistogramValue histogram_value, |
60 const std::string& event_name, | 62 const std::string& event_name, |
61 const GURL& url) { | 63 const GURL& url) { |
62 scoped_ptr<base::ListValue> args(new base::ListValue()); | 64 scoped_ptr<base::ListValue> args(new base::ListValue()); |
63 event_router->BroadcastEventToRenderers(histogram_value, event_name, | 65 event_router->BroadcastEventToRenderers(histogram_value, event_name, |
64 args.Pass(), url); | 66 std::move(args), url); |
65 } | 67 } |
66 | 68 |
67 static void DispatchEventToRenderers(EventRouterForwarder* event_router, | 69 static void DispatchEventToRenderers(EventRouterForwarder* event_router, |
68 events::HistogramValue histogram_value, | 70 events::HistogramValue histogram_value, |
69 const std::string& event_name, | 71 const std::string& event_name, |
70 void* profile, | 72 void* profile, |
71 bool use_profile_to_restrict_events, | 73 bool use_profile_to_restrict_events, |
72 const GURL& url) { | 74 const GURL& url) { |
73 scoped_ptr<base::ListValue> args(new base::ListValue()); | 75 scoped_ptr<base::ListValue> args(new base::ListValue()); |
74 event_router->DispatchEventToRenderers(histogram_value, event_name, | 76 event_router->DispatchEventToRenderers(histogram_value, event_name, |
75 args.Pass(), profile, | 77 std::move(args), profile, |
76 use_profile_to_restrict_events, url); | 78 use_profile_to_restrict_events, url); |
77 } | 79 } |
78 | 80 |
79 static void BroadcastEventToExtension(EventRouterForwarder* event_router, | 81 static void BroadcastEventToExtension(EventRouterForwarder* event_router, |
80 const std::string& extension, | 82 const std::string& extension, |
81 events::HistogramValue histogram_value, | 83 events::HistogramValue histogram_value, |
82 const std::string& event_name, | 84 const std::string& event_name, |
83 const GURL& url) { | 85 const GURL& url) { |
84 scoped_ptr<base::ListValue> args(new base::ListValue()); | 86 scoped_ptr<base::ListValue> args(new base::ListValue()); |
85 event_router->BroadcastEventToExtension(extension, histogram_value, | 87 event_router->BroadcastEventToExtension(extension, histogram_value, |
86 event_name, args.Pass(), url); | 88 event_name, std::move(args), url); |
87 } | 89 } |
88 | 90 |
89 static void DispatchEventToExtension(EventRouterForwarder* event_router, | 91 static void DispatchEventToExtension(EventRouterForwarder* event_router, |
90 const std::string& extension, | 92 const std::string& extension, |
91 events::HistogramValue histogram_value, | 93 events::HistogramValue histogram_value, |
92 const std::string& event_name, | 94 const std::string& event_name, |
93 void* profile, | 95 void* profile, |
94 bool use_profile_to_restrict_events, | 96 bool use_profile_to_restrict_events, |
95 const GURL& url) { | 97 const GURL& url) { |
96 scoped_ptr<base::ListValue> args(new base::ListValue()); | 98 scoped_ptr<base::ListValue> args(new base::ListValue()); |
97 event_router->DispatchEventToExtension(extension, histogram_value, event_name, | 99 event_router->DispatchEventToExtension(extension, histogram_value, event_name, |
98 args.Pass(), profile, | 100 std::move(args), profile, |
99 use_profile_to_restrict_events, url); | 101 use_profile_to_restrict_events, url); |
100 } | 102 } |
101 | 103 |
102 } // namespace | 104 } // namespace |
103 | 105 |
104 class EventRouterForwarderTest : public testing::Test { | 106 class EventRouterForwarderTest : public testing::Test { |
105 protected: | 107 protected: |
106 EventRouterForwarderTest() | 108 EventRouterForwarderTest() |
107 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD), | 109 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD), |
108 profile_manager_( | 110 profile_manager_( |
109 TestingBrowserProcess::GetGlobal()) { | 111 TestingBrowserProcess::GetGlobal()) { |
110 #if defined(OS_MACOSX) | 112 #if defined(OS_MACOSX) |
111 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); | 113 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); |
112 #endif | 114 #endif |
113 scoped_ptr<base::PowerMonitorSource> power_monitor_source( | 115 scoped_ptr<base::PowerMonitorSource> power_monitor_source( |
114 new base::PowerMonitorDeviceSource()); | 116 new base::PowerMonitorDeviceSource()); |
115 dummy.reset(new base::PowerMonitor(power_monitor_source.Pass())); | 117 dummy.reset(new base::PowerMonitor(std::move(power_monitor_source))); |
116 } | 118 } |
117 | 119 |
118 void SetUp() override { | 120 void SetUp() override { |
119 ASSERT_TRUE(profile_manager_.SetUp()); | 121 ASSERT_TRUE(profile_manager_.SetUp()); |
120 | 122 |
121 // Inject a BrowserProcess with a ProfileManager. | 123 // Inject a BrowserProcess with a ProfileManager. |
122 profile1_ = profile_manager_.CreateTestingProfile("one"); | 124 profile1_ = profile_manager_.CreateTestingProfile("one"); |
123 profile2_ = profile_manager_.CreateTestingProfile("two"); | 125 profile2_ = profile_manager_.CreateTestingProfile("two"); |
124 } | 126 } |
125 | 127 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 EXPECT_CALL( | 306 EXPECT_CALL( |
305 *event_router.get(), | 307 *event_router.get(), |
306 CallEventRouter(profile1_, kExt, kHistogramValue, kEventName, NULL, url)); | 308 CallEventRouter(profile1_, kExt, kHistogramValue, kEventName, NULL, url)); |
307 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _, _)) | 309 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _, _)) |
308 .Times(0); | 310 .Times(0); |
309 DispatchEventToExtension(event_router.get(), kExt, kHistogramValue, | 311 DispatchEventToExtension(event_router.get(), kExt, kHistogramValue, |
310 kEventName, profile1_, false, url); | 312 kEventName, profile1_, false, url); |
311 } | 313 } |
312 | 314 |
313 } // namespace extensions | 315 } // namespace extensions |
OLD | NEW |