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

Unified Diff: content/browser/device_orientation/device_motion_service.cc

Issue 14678012: Implement the content/renderer and content/browser part of the Device Motion API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compilation: peer_handle -> PeerHandle() Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/device_orientation/device_motion_service.cc
diff --git a/content/browser/device_orientation/device_motion_service.cc b/content/browser/device_orientation/device_motion_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ed1dcc6f25d4f0b1e130d2993ffc4eea40eac99d
--- /dev/null
+++ b/content/browser/device_orientation/device_motion_service.cc
@@ -0,0 +1,65 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/device_orientation/device_motion_service.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/memory/singleton.h"
+#include "content/browser/device_orientation/device_motion_provider.h"
+#include "content/public/browser/render_process_host.h"
+
+namespace content {
+
+DeviceMotionService::DeviceMotionService()
+ : num_readers_(0),
+ is_shutdown_(false) {
+}
+
+DeviceMotionService::~DeviceMotionService() {
+}
+
+DeviceMotionService* DeviceMotionService::GetInstance() {
+ return Singleton<DeviceMotionService,
+ LeakySingletonTraits<DeviceMotionService> >::get();
+}
+
+void DeviceMotionService::AddConsumer() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (is_shutdown_)
+ return;
+
+ num_readers_++;
+ DCHECK(num_readers_ > 0);
+ if (!provider_.get())
+ provider_.reset(new DeviceMotionProvider);
+ provider_->StartFetchingDeviceMotionData();
+}
+
+void DeviceMotionService::RemoveConsumer() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (is_shutdown_)
+ return;
+
+ --num_readers_;
+ DCHECK(num_readers_ >= 0);
+
+ if (num_readers_ == 0) {
+ LOG(INFO) << "ACTIVE service stop fetching";
+ provider_->StopFetchingDeviceMotionData();
+ }
+}
+
+void DeviceMotionService::Shutdown() {
+ provider_.reset();
+ is_shutdown_ = true;
+}
+
+base::SharedMemoryHandle DeviceMotionService::GetSharedMemoryHandleForProcess(
+ base::ProcessHandle handle) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ return provider_->GetSharedMemoryHandleForProcess(handle);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698