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

Side by Side Diff: content/shell/renderer/shell_content_renderer_client.cc

Issue 2870373002: [DeviceService] Add end-to-end browsertest for PowerMonitor (Closed)
Patch Set: Address comments from jam@ and blundell@ Created 3 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
« no previous file with comments | « content/shell/common/power_monitor_test.mojom ('k') | content/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/shell/renderer/shell_content_renderer_client.h" 5 #include "content/shell/renderer/shell_content_renderer_client.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/power_monitor/power_monitor.h"
13 #include "components/cdm/renderer/external_clear_key_key_system_properties.h" 14 #include "components/cdm/renderer/external_clear_key_key_system_properties.h"
14 #include "components/web_cache/renderer/web_cache_impl.h" 15 #include "components/web_cache/renderer/web_cache_impl.h"
15 #include "content/public/child/child_thread.h" 16 #include "content/public/child/child_thread.h"
16 #include "content/public/common/service_manager_connection.h" 17 #include "content/public/common/service_manager_connection.h"
17 #include "content/public/common/simple_connection_filter.h" 18 #include "content/public/common/simple_connection_filter.h"
18 #include "content/public/test/test_service.mojom.h" 19 #include "content/public/test/test_service.mojom.h"
20 #include "content/shell/common/power_monitor_test.mojom.h"
19 #include "content/shell/common/shell_switches.h" 21 #include "content/shell/common/shell_switches.h"
20 #include "content/shell/renderer/shell_render_view_observer.h" 22 #include "content/shell/renderer/shell_render_view_observer.h"
21 #include "mojo/public/cpp/bindings/binding.h" 23 #include "mojo/public/cpp/bindings/binding.h"
24 #include "mojo/public/cpp/bindings/strong_binding.h"
22 #include "mojo/public/cpp/system/message_pipe.h" 25 #include "mojo/public/cpp/system/message_pipe.h"
23 #include "ppapi/features/features.h" 26 #include "ppapi/features/features.h"
24 #include "services/service_manager/public/cpp/binder_registry.h" 27 #include "services/service_manager/public/cpp/binder_registry.h"
25 #include "third_party/WebKit/public/web/WebTestingSupport.h" 28 #include "third_party/WebKit/public/web/WebTestingSupport.h"
26 #include "third_party/WebKit/public/web/WebView.h" 29 #include "third_party/WebKit/public/web/WebView.h"
27 #include "v8/include/v8.h" 30 #include "v8/include/v8.h"
28 31
29 #if BUILDFLAG(ENABLE_PLUGINS) 32 #if BUILDFLAG(ENABLE_PLUGINS)
30 #include "ppapi/shared_impl/ppapi_switches.h" // nogncheck 33 #include "ppapi/shared_impl/ppapi_switches.h" // nogncheck
31 #endif 34 #endif
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 91
89 DISALLOW_COPY_AND_ASSIGN(TestServiceImpl); 92 DISALLOW_COPY_AND_ASSIGN(TestServiceImpl);
90 }; 93 };
91 94
92 void CreateTestService(const service_manager::BindSourceInfo& source_info, 95 void CreateTestService(const service_manager::BindSourceInfo& source_info,
93 mojom::TestServiceRequest request) { 96 mojom::TestServiceRequest request) {
94 // Owns itself. 97 // Owns itself.
95 new TestServiceImpl(std::move(request)); 98 new TestServiceImpl(std::move(request));
96 } 99 }
97 100
101 class PowerMonitorTestImpl : public base::PowerObserver,
102 public mojom::PowerMonitorTest {
103 public:
104 static void MakeStrongBinding(
105 std::unique_ptr<PowerMonitorTestImpl> instance,
106 const service_manager::BindSourceInfo& source_info,
107 mojom::PowerMonitorTestRequest request) {
108 mojo::MakeStrongBinding(std::move(instance), std::move(request));
109 }
110
111 PowerMonitorTestImpl() {
112 base::PowerMonitor* power_monitor = base::PowerMonitor::Get();
113 if (power_monitor)
114 power_monitor->AddObserver(this);
115 }
116 ~PowerMonitorTestImpl() override {
117 base::PowerMonitor* power_monitor = base::PowerMonitor::Get();
118 if (power_monitor)
119 power_monitor->RemoveObserver(this);
120 }
121
122 private:
123 // mojom::PowerMonitorTest:
124 void QueryNextState(QueryNextStateCallback callback) override {
125 // Do not allow overlapping call.
126 DCHECK(callback_.is_null());
127 callback_ = std::move(callback);
128
129 if (need_to_report_)
130 ReportState();
131 }
132
133 // base::PowerObserver:
134 void OnPowerStateChange(bool on_battery_power) override {
135 on_battery_power_ = on_battery_power;
136 need_to_report_ = true;
137
138 if (!callback_.is_null())
139 ReportState();
140 }
141 void OnSuspend() override {}
142 void OnResume() override {}
143
144 void ReportState() {
145 std::move(callback_).Run(on_battery_power_);
146 need_to_report_ = false;
147 }
148
149 QueryNextStateCallback callback_;
150 bool on_battery_power_ = false;
151 bool need_to_report_ = false;
152
153 DISALLOW_COPY_AND_ASSIGN(PowerMonitorTestImpl);
154 };
155
98 } // namespace 156 } // namespace
99 157
100 ShellContentRendererClient::ShellContentRendererClient() {} 158 ShellContentRendererClient::ShellContentRendererClient() {}
101 159
102 ShellContentRendererClient::~ShellContentRendererClient() { 160 ShellContentRendererClient::~ShellContentRendererClient() {
103 } 161 }
104 162
105 void ShellContentRendererClient::RenderThreadStarted() { 163 void ShellContentRendererClient::RenderThreadStarted() {
106 web_cache_impl_.reset(new web_cache::WebCacheImpl()); 164 web_cache_impl_.reset(new web_cache::WebCacheImpl());
107 165
108 auto registry = base::MakeUnique<service_manager::BinderRegistry>(); 166 auto registry = base::MakeUnique<service_manager::BinderRegistry>();
109 registry->AddInterface<mojom::TestService>( 167 registry->AddInterface<mojom::TestService>(
110 base::Bind(&CreateTestService), base::ThreadTaskRunnerHandle::Get()); 168 base::Bind(&CreateTestService), base::ThreadTaskRunnerHandle::Get());
169 registry->AddInterface<mojom::PowerMonitorTest>(
170 base::Bind(&PowerMonitorTestImpl::MakeStrongBinding,
171 base::Passed(base::MakeUnique<PowerMonitorTestImpl>())),
172 base::ThreadTaskRunnerHandle::Get());
111 content::ChildThread::Get() 173 content::ChildThread::Get()
112 ->GetServiceManagerConnection() 174 ->GetServiceManagerConnection()
113 ->AddConnectionFilter( 175 ->AddConnectionFilter(
114 base::MakeUnique<SimpleConnectionFilter>(std::move(registry))); 176 base::MakeUnique<SimpleConnectionFilter>(std::move(registry)));
115 } 177 }
116 178
117 void ShellContentRendererClient::RenderViewCreated(RenderView* render_view) { 179 void ShellContentRendererClient::RenderViewCreated(RenderView* render_view) {
118 new ShellRenderViewObserver(render_view); 180 new ShellRenderViewObserver(render_view);
119 } 181 }
120 182
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 return; 214 return;
153 215
154 static const char kExternalClearKeyKeySystem[] = 216 static const char kExternalClearKeyKeySystem[] =
155 "org.chromium.externalclearkey"; 217 "org.chromium.externalclearkey";
156 key_systems->emplace_back( 218 key_systems->emplace_back(
157 new cdm::ExternalClearKeyProperties(kExternalClearKeyKeySystem)); 219 new cdm::ExternalClearKeyProperties(kExternalClearKeyKeySystem));
158 } 220 }
159 #endif 221 #endif
160 222
161 } // namespace content 223 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/common/power_monitor_test.mojom ('k') | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698