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 #include "content/browser/device_orientation/device_motion_service.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/memory/singleton.h" |
| 10 #include "content/browser/device_orientation/device_motion_provider.h" |
| 11 #include "content/public/browser/render_process_host.h" |
| 12 |
| 13 namespace content { |
| 14 |
| 15 DeviceMotionService::DeviceMotionService() |
| 16 : num_readers_(0), |
| 17 is_shutdown_(false) { |
| 18 } |
| 19 |
| 20 DeviceMotionService::~DeviceMotionService() { |
| 21 } |
| 22 |
| 23 DeviceMotionService* DeviceMotionService::GetInstance() { |
| 24 return Singleton<DeviceMotionService, |
| 25 LeakySingletonTraits<DeviceMotionService> >::get(); |
| 26 } |
| 27 |
| 28 void DeviceMotionService::AddConsumer() { |
| 29 DCHECK(thread_checker_.CalledOnValidThread()); |
| 30 if (is_shutdown_) |
| 31 return; |
| 32 |
| 33 num_readers_++; |
| 34 DCHECK(num_readers_ > 0); |
| 35 if (!provider_.get()) |
| 36 provider_.reset(new DeviceMotionProvider); |
| 37 provider_->StartFetchingDeviceMotionData(); |
| 38 } |
| 39 |
| 40 void DeviceMotionService::RemoveConsumer() { |
| 41 DCHECK(thread_checker_.CalledOnValidThread()); |
| 42 if (is_shutdown_) |
| 43 return; |
| 44 |
| 45 --num_readers_; |
| 46 DCHECK(num_readers_ >= 0); |
| 47 |
| 48 if (num_readers_ == 0) { |
| 49 LOG(INFO) << "ACTIVE service stop fetching"; |
| 50 provider_->StopFetchingDeviceMotionData(); |
| 51 } |
| 52 } |
| 53 |
| 54 void DeviceMotionService::Shutdown() { |
| 55 provider_.reset(); |
| 56 is_shutdown_ = true; |
| 57 } |
| 58 |
| 59 base::SharedMemoryHandle DeviceMotionService::GetSharedMemoryHandleForProcess( |
| 60 base::ProcessHandle handle) { |
| 61 DCHECK(thread_checker_.CalledOnValidThread()); |
| 62 return provider_->GetSharedMemoryHandleForProcess(handle); |
| 63 } |
| 64 |
| 65 } // namespace content |
OLD | NEW |