OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_DEVICE_ORIENTATION_DEVICE_MOTION_SERVICE_H_ |
| 6 #define CONTENT_BROWSER_DEVICE_ORIENTATION_DEVICE_MOTION_SERVICE_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/callback_forward.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/singleton.h" |
| 12 #include "base/shared_memory.h" |
| 13 #include "base/threading/thread_checker.h" |
| 14 #include "content/common/content_export.h" |
| 15 |
| 16 namespace content { |
| 17 |
| 18 class DataFetcherSharedMemory; |
| 19 class DeviceMotionProvider; |
| 20 class RenderProcessHost; |
| 21 |
| 22 // Owns the DeviceMotionProvider (the background polling thread) and keeps |
| 23 // track of the number of consumers currently using the data (and pausing |
| 24 // the provider when not in use). |
| 25 class CONTENT_EXPORT DeviceMotionService { |
| 26 public: |
| 27 // Returns the DeviceMotionService singleton. |
| 28 static DeviceMotionService* GetInstance(); |
| 29 |
| 30 // Increments the number of users of the provider. The Provider is running |
| 31 // when there's > 0 users, and is paused when the count drops to 0. |
| 32 // |
| 33 // Must be called on the I/O thread. |
| 34 void AddConsumer(); |
| 35 |
| 36 // Removes a consumer. Should be matched with an AddConsumer call. |
| 37 // |
| 38 // Must be called on the I/O thread. |
| 39 void RemoveConsumer(); |
| 40 |
| 41 // Returns the shared memory handle of the device motion data duplicated |
| 42 // into the given process. |
| 43 base::SharedMemoryHandle GetSharedMemoryHandleForProcess( |
| 44 base::ProcessHandle handle); |
| 45 |
| 46 // Stop/join with the background thread in DeviceMotionProvider |provider_|. |
| 47 void Shutdown(); |
| 48 |
| 49 private: |
| 50 friend struct DefaultSingletonTraits<DeviceMotionService>; |
| 51 |
| 52 DeviceMotionService(); |
| 53 virtual ~DeviceMotionService(); |
| 54 |
| 55 int num_readers_; |
| 56 bool is_shutdown_; |
| 57 scoped_ptr<DeviceMotionProvider> provider_; |
| 58 base::ThreadChecker thread_checker_; |
| 59 |
| 60 DISALLOW_COPY_AND_ASSIGN(DeviceMotionService); |
| 61 }; |
| 62 |
| 63 } // namespace content |
| 64 |
| 65 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_DEVICE_MOTION_SERVICE_H_ |
OLD | NEW |