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

Side by Side Diff: content/browser/battery_status/battery_monitor_integration_browsertest.cc

Issue 2080513002: Deletes mojo::Callback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <utility> 5 #include <utility>
6 6
7 #include "base/callback_list.h" 7 #include "base/callback_list.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 g_callback_list.Get().Notify(battery_status); 47 g_callback_list.Get().Notify(battery_status);
48 } 48 }
49 49
50 class FakeBatteryMonitor : public device::BatteryMonitor { 50 class FakeBatteryMonitor : public device::BatteryMonitor {
51 public: 51 public:
52 static void Create(mojo::InterfaceRequest<BatteryMonitor> request) { 52 static void Create(mojo::InterfaceRequest<BatteryMonitor> request) {
53 new FakeBatteryMonitor(std::move(request)); 53 new FakeBatteryMonitor(std::move(request));
54 } 54 }
55 55
56 private: 56 private:
57 typedef mojo::Callback<void(device::BatteryStatusPtr)> BatteryStatusCallback;
58
59 FakeBatteryMonitor(mojo::InterfaceRequest<BatteryMonitor> request) 57 FakeBatteryMonitor(mojo::InterfaceRequest<BatteryMonitor> request)
60 : binding_(this, std::move(request)) {} 58 : binding_(this, std::move(request)) {}
61 ~FakeBatteryMonitor() override {} 59 ~FakeBatteryMonitor() override {}
62 60
63 void QueryNextStatus(const BatteryStatusCallback& callback) override { 61 void QueryNextStatus(const QueryNextStatusCallback& callback) override {
64 // We don't expect overlapped calls to QueryNextStatus. 62 // We don't expect overlapped calls to QueryNextStatus.
65 DCHECK(callback_.is_null()); 63 DCHECK(callback_.is_null());
66 64
67 callback_ = callback; 65 callback_ = callback;
68 66
69 if (!subscription_) { 67 if (!subscription_) {
70 subscription_ = 68 subscription_ =
71 g_callback_list.Get().Add(base::Bind(&FakeBatteryMonitor::DidChange, 69 g_callback_list.Get().Add(base::Bind(&FakeBatteryMonitor::DidChange,
72 base::Unretained(this))); 70 base::Unretained(this)));
73 // Report initial value. 71 // Report initial value.
74 DidChange(g_battery_status); 72 DidChange(g_battery_status);
75 } 73 }
76 } 74 }
77 75
78 void DidChange(const device::BatteryStatus& battery_status) { 76 void DidChange(const device::BatteryStatus& battery_status) {
79 if (!callback_.is_null()) { 77 if (!callback_.is_null()) {
80 callback_.Run(battery_status.Clone()); 78 callback_.Run(battery_status.Clone());
81 callback_.Reset(); 79 callback_.Reset();
82 } 80 }
83 } 81 }
84 82
85 std::unique_ptr<BatteryUpdateSubscription> subscription_; 83 std::unique_ptr<BatteryUpdateSubscription> subscription_;
86 mojo::StrongBinding<BatteryMonitor> binding_; 84 mojo::StrongBinding<BatteryMonitor> binding_;
87 BatteryStatusCallback callback_; 85 QueryNextStatusCallback callback_;
88 }; 86 };
89 87
90 // Overrides the default service implementation with the test implementation 88 // Overrides the default service implementation with the test implementation
91 // declared above. 89 // declared above.
92 class TestContentBrowserClient : public ContentBrowserClient { 90 class TestContentBrowserClient : public ContentBrowserClient {
93 public: 91 public:
94 void RegisterRenderProcessMojoServices( 92 void RegisterRenderProcessMojoServices(
95 ServiceRegistry* registry, 93 ServiceRegistry* registry,
96 RenderProcessHost* render_process_host) override { 94 RenderProcessHost* render_process_host) override {
97 registry->AddService(base::Bind(&FakeBatteryMonitor::Create)); 95 registry->AddService(base::Bind(&FakeBatteryMonitor::Create));
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 TestNavigationObserver same_tab_observer2(shell()->web_contents(), 1); 179 TestNavigationObserver same_tab_observer2(shell()->web_contents(), 1);
182 status.level = 0.6; 180 status.level = 0.6;
183 UpdateBattery(status); 181 UpdateBattery(status);
184 same_tab_observer2.Wait(); 182 same_tab_observer2.Wait();
185 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); 183 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref());
186 } 184 }
187 185
188 } // namespace 186 } // namespace
189 187
190 } // namespace content 188 } // namespace content
OLDNEW
« no previous file with comments | « components/mus/ws/window_tree_client_unittest.cc ('k') | content/browser/geolocation/geolocation_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698