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

Side by Side Diff: content/renderer/renderer_blink_platform_impl.cc

Issue 592153002: Replace Chrome IPC with Mojo IPC for querying BatteryStatus service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Tom's comment. Created 6 years, 1 month 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 (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/renderer/renderer_blink_platform_impl.h" 5 #include "content/renderer/renderer_blink_platform_impl.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 // static 1038 // static
1039 PlatformEventObserverBase* 1039 PlatformEventObserverBase*
1040 RendererBlinkPlatformImpl::CreatePlatformEventObserverFromType( 1040 RendererBlinkPlatformImpl::CreatePlatformEventObserverFromType(
1041 blink::WebPlatformEventType type) { 1041 blink::WebPlatformEventType type) {
1042 RenderThread* thread = RenderThreadImpl::current(); 1042 RenderThread* thread = RenderThreadImpl::current();
1043 1043
1044 // When running layout tests, those observers should not listen to the actual 1044 // When running layout tests, those observers should not listen to the actual
1045 // hardware changes. In order to make that happen, they will receive a null 1045 // hardware changes. In order to make that happen, they will receive a null
1046 // thread. 1046 // thread.
1047 if (thread && RenderThreadImpl::current()->layout_test_mode()) 1047 if (thread && RenderThreadImpl::current()->layout_test_mode())
1048 thread = 0; 1048 thread = NULL;
1049 1049
1050 switch (type) { 1050 switch (type) {
1051 case blink::WebPlatformEventDeviceMotion: { 1051 case blink::WebPlatformEventDeviceMotion:
1052 return new DeviceMotionEventPump(thread); 1052 return new DeviceMotionEventPump(thread);
1053 } 1053 case blink::WebPlatformEventDeviceOrientation:
1054 case blink::WebPlatformEventDeviceOrientation: { 1054 return new DeviceOrientationEventPump(thread);
1055 return new DeviceOrientationEventPump(thread); 1055 case blink::WebPlatformEventDeviceLight:
1056 } 1056 return new DeviceLightEventPump(thread);
1057 case blink::WebPlatformEventDeviceLight: { 1057 case blink::WebPlatformEventGamepad:
1058 return new DeviceLightEventPump(thread); 1058 return new GamepadSharedMemoryReader(thread);
1059 } 1059 case blink::WebPlatformEventScreenOrientation:
1060 case blink::WebPlatformEventBattery: { 1060 return new ScreenOrientationObserver();
1061 return new BatteryStatusDispatcher(thread); 1061 default:
1062 } 1062 // A default statement is required to prevent compilation errors when
1063 case blink::WebPlatformEventGamepad: 1063 // Blink adds a new type.
1064 return new GamepadSharedMemoryReader(thread); 1064 VLOG(1) << "RendererBlinkPlatformImpl::startListening() with "
1065 break; 1065 "unknown type.";
1066 case blink::WebPlatformEventScreenOrientation:
1067 return new ScreenOrientationObserver();
1068 default:
1069 // A default statement is required to prevent compilation errors when Blink
1070 // adds a new type.
1071 VLOG(1) << "RendererBlinkPlatformImpl::startListening() with "
1072 "unknown type.";
1073 } 1066 }
1074 1067
1075 return 0; 1068 return NULL;
1076 } 1069 }
1077 1070
1078 void RendererBlinkPlatformImpl::SetPlatformEventObserverForTesting( 1071 void RendererBlinkPlatformImpl::SetPlatformEventObserverForTesting(
1079 blink::WebPlatformEventType type, 1072 blink::WebPlatformEventType type,
1080 scoped_ptr<PlatformEventObserverBase> observer) { 1073 scoped_ptr<PlatformEventObserverBase> observer) {
1074 DCHECK(type != blink::WebPlatformEventBattery);
1075
1081 if (platform_event_observers_.Lookup(type)) 1076 if (platform_event_observers_.Lookup(type))
1082 platform_event_observers_.Remove(type); 1077 platform_event_observers_.Remove(type);
1083 platform_event_observers_.AddWithID(observer.release(), type); 1078 platform_event_observers_.AddWithID(observer.release(), type);
1084 } 1079 }
1085 1080
1086 void RendererBlinkPlatformImpl::startListening( 1081 void RendererBlinkPlatformImpl::startListening(
1087 blink::WebPlatformEventType type, 1082 blink::WebPlatformEventType type,
1088 blink::WebPlatformEventListener* listener) { 1083 blink::WebPlatformEventListener* listener) {
1084 if (type == blink::WebPlatformEventBattery) {
1085 battery_status_dispatcher_.reset(new BatteryStatusDispatcher(
1086 static_cast<blink::WebBatteryStatusListener*>(listener)));
1087 return;
1088 }
1089
1089 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); 1090 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type);
1090 if (!observer) { 1091 if (!observer) {
1091 observer = CreatePlatformEventObserverFromType(type); 1092 observer = CreatePlatformEventObserverFromType(type);
1092 if (!observer) 1093 if (!observer)
1093 return; 1094 return;
1094 platform_event_observers_.AddWithID(observer, static_cast<int32>(type)); 1095 platform_event_observers_.AddWithID(observer, static_cast<int32>(type));
1095 } 1096 }
1096 observer->Start(listener); 1097 observer->Start(listener);
1097 1098
1098 // Device events (motion, orientation and light) expect to get an event fired 1099 // Device events (motion, orientation and light) expect to get an event fired
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 return; 1138 return;
1138 1139
1139 base::MessageLoopProxy::current()->PostTask( 1140 base::MessageLoopProxy::current()->PostTask(
1140 FROM_HERE, 1141 FROM_HERE,
1141 base::Bind(&PlatformEventObserverBase::SendFakeDataForTesting, 1142 base::Bind(&PlatformEventObserverBase::SendFakeDataForTesting,
1142 base::Unretained(observer), data)); 1143 base::Unretained(observer), data));
1143 } 1144 }
1144 1145
1145 void RendererBlinkPlatformImpl::stopListening( 1146 void RendererBlinkPlatformImpl::stopListening(
1146 blink::WebPlatformEventType type) { 1147 blink::WebPlatformEventType type) {
1148 if (type == blink::WebPlatformEventBattery) {
1149 battery_status_dispatcher_.reset();
1150 return;
1151 }
1152
1147 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); 1153 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type);
1148 if (!observer) 1154 if (!observer)
1149 return; 1155 return;
1150 observer->Stop(); 1156 observer->Stop();
1151 } 1157 }
1152 1158
1153 //------------------------------------------------------------------------------ 1159 //------------------------------------------------------------------------------
1154 1160
1155 void RendererBlinkPlatformImpl::queryStorageUsageAndQuota( 1161 void RendererBlinkPlatformImpl::queryStorageUsageAndQuota(
1156 const blink::WebURL& storage_partition, 1162 const blink::WebURL& storage_partition,
(...skipping 14 matching lines...) Expand all
1171 void RendererBlinkPlatformImpl::MockBatteryStatusChangedForTesting( 1177 void RendererBlinkPlatformImpl::MockBatteryStatusChangedForTesting(
1172 const blink::WebBatteryStatus& status) { 1178 const blink::WebBatteryStatus& status) {
1173 PlatformEventObserverBase* observer = 1179 PlatformEventObserverBase* observer =
1174 platform_event_observers_.Lookup(blink::WebPlatformEventBattery); 1180 platform_event_observers_.Lookup(blink::WebPlatformEventBattery);
1175 if (!observer) 1181 if (!observer)
1176 return; 1182 return;
1177 observer->SendFakeDataForTesting((void*)&status); 1183 observer->SendFakeDataForTesting((void*)&status);
1178 } 1184 }
1179 1185
1180 } // namespace content 1186 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/battery_status/battery_status_dispatcher.cc ('k') | content/renderer/shared_memory_seqlock_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698