Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2017 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
| 17 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef DeviceMotionDispatcher_h | 31 #ifndef WebDeviceMotionData_h |
| 32 #define DeviceMotionDispatcher_h | 32 #define WebDeviceMotionData_h |
| 33 | 33 |
| 34 #include "core/frame/PlatformEventDispatcher.h" | 34 #include <string.h> |
| 35 #include "platform/heap/Handle.h" | |
| 36 #include "platform/wtf/RefPtr.h" | |
| 37 #include "public/platform/modules/device_orientation/WebDeviceMotionListener.h" | |
| 38 | |
| 39 namespace device { | |
| 40 class MotionData; | |
| 41 } | |
| 42 | 35 |
| 43 namespace blink { | 36 namespace blink { |
| 44 | 37 |
| 45 class DeviceMotionData; | 38 #pragma pack(push, 1) |
| 46 | 39 |
| 47 // This class listens to device motion data and notifies all registered | 40 class WebDeviceMotionData { |
| 48 // controllers. | 41 public: |
| 49 class DeviceMotionDispatcher final | 42 WebDeviceMotionData() { |
| 50 : public GarbageCollectedFinalized<DeviceMotionDispatcher>, | 43 // Make sure to zero out the memory so that there are no uninitialized bits. |
| 51 public PlatformEventDispatcher, | 44 // This object is used in the shared memory buffer and is memory copied by |
| 52 public WebDeviceMotionListener { | 45 // two processes. Valgrind will complain if we copy around memory that is |
| 53 USING_GARBAGE_COLLECTED_MIXIN(DeviceMotionDispatcher); | 46 // only partially initialized. |
| 47 memset(this, 0, sizeof(*this)); | |
|
Reilly Grant (use Gerrit)
2017/05/19 20:20:11
This structure is no longer used for a shared buff
juncai
2017/05/20 00:55:02
Fixed it in a new CL:
https://codereview.chromium.
| |
| 48 } | |
| 49 WebDeviceMotionData(const WebDeviceMotionData& other) = default; | |
| 50 ~WebDeviceMotionData() {} | |
| 54 | 51 |
| 55 public: | 52 double acceleration_x; |
| 56 static DeviceMotionDispatcher& Instance(); | 53 double acceleration_y; |
| 57 ~DeviceMotionDispatcher() override; | 54 double acceleration_z; |
| 58 | 55 |
| 59 // Note that the returned object is owned by this class. | 56 double acceleration_including_gravity_x; |
| 60 // FIXME: make the return value const, see crbug.com/233174. | 57 double acceleration_including_gravity_y; |
| 61 DeviceMotionData* LatestDeviceMotionData(); | 58 double acceleration_including_gravity_z; |
| 62 | 59 |
| 63 // Inherited from WebDeviceMotionListener. | 60 double rotation_rate_alpha; |
| 64 void DidChangeDeviceMotion(const device::MotionData&) override; | 61 double rotation_rate_beta; |
| 62 double rotation_rate_gamma; | |
| 65 | 63 |
| 66 DECLARE_VIRTUAL_TRACE(); | 64 double interval; |
| 67 | 65 |
| 68 private: | 66 bool has_acceleration_x : 1; |
| 69 DeviceMotionDispatcher(); | 67 bool has_acceleration_y : 1; |
| 68 bool has_acceleration_z : 1; | |
| 70 | 69 |
| 71 // Inherited from PlatformEventDispatcher. | 70 bool has_acceleration_including_gravity_x : 1; |
| 72 void StartListening() override; | 71 bool has_acceleration_including_gravity_y : 1; |
| 73 void StopListening() override; | 72 bool has_acceleration_including_gravity_z : 1; |
| 74 | 73 |
| 75 Member<DeviceMotionData> last_device_motion_data_; | 74 bool has_rotation_rate_alpha : 1; |
| 75 bool has_rotation_rate_beta : 1; | |
| 76 bool has_rotation_rate_gamma : 1; | |
| 76 }; | 77 }; |
| 77 | 78 |
| 79 static_assert(sizeof(WebDeviceMotionData) == | |
| 80 (10 * sizeof(double) + 2 * sizeof(char)), | |
| 81 "WebDeviceMotionData has wrong size"); | |
| 82 | |
| 83 #pragma pack(pop) | |
| 84 | |
| 78 } // namespace blink | 85 } // namespace blink |
| 79 | 86 |
| 80 #endif // DeviceMotionDispatcher_h | 87 #endif // WebDeviceMotionData_h |
| OLD | NEW |