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

Unified Diff: content/browser/device_sensors/device_sensor_service.cc

Issue 2410123002: Remove content::BrowserThread knowledge from Device Sensors (Closed)
Patch Set: Handle DeviceSensorService's ThreadChecker Created 4 years, 2 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_sensors/device_sensor_service.cc
diff --git a/content/browser/device_sensors/device_sensor_service.cc b/content/browser/device_sensors/device_sensor_service.cc
index 827600740f7c4bf3355020a3fbe8c85e782f53ee..b058af81f9d786adc6461ff661e5cba3f03d8782 100644
--- a/content/browser/device_sensors/device_sensor_service.cc
+++ b/content/browser/device_sensors/device_sensor_service.cc
@@ -7,8 +7,13 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/singleton.h"
+#include "build/build_config.h"
#include "content/browser/device_sensors/data_fetcher_shared_memory.h"
+#if defined(OS_ANDROID)
+#include "content/browser/device_sensors/sensor_manager_android.h"
+#endif
+
namespace content {
DeviceSensorService::DeviceSensorService()
@@ -46,7 +51,7 @@ void DeviceSensorService::RemoveConsumer(ConsumerType consumer_type) {
bool DeviceSensorService::ChangeNumberConsumers(ConsumerType consumer_type,
int delta) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(io_thread_checker_.CalledOnValidThread());
if (is_shutdown_)
return false;
@@ -91,13 +96,26 @@ int DeviceSensorService::GetNumberConsumers(ConsumerType consumer_type) const {
mojo::ScopedSharedBufferHandle DeviceSensorService::GetSharedMemoryHandle(
ConsumerType consumer_type) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(io_thread_checker_.CalledOnValidThread());
return data_fetcher_->GetSharedMemoryHandle(consumer_type);
}
-void DeviceSensorService::Shutdown() {
+void DeviceSensorService::InitOnUIThread() {
+#if defined(OS_ANDROID)
+ SensorManagerAndroid::GetInstance()->InitOnUIThread();
+#endif
+}
+
+void DeviceSensorService::InitOnIOThread() {
timvolodine 2016/10/12 16:28:58 I am slightly confused by the two Init methods, wi
+ // Ensure that the thread checker is associated with the IO thread in case
+ // instantiation of this object occurred on the UI thread.
+ io_thread_checker_.DetachFromThread();
+ ignore_result(io_thread_checker_.CalledOnValidThread());
+}
+
+void DeviceSensorService::ShutDownOnUIThread() {
if (data_fetcher_) {
- data_fetcher_->Shutdown();
+ data_fetcher_->ShutDownOnUIThread();
data_fetcher_.reset();
}
is_shutdown_ = true;
@@ -106,7 +124,7 @@ void DeviceSensorService::Shutdown() {
void DeviceSensorService::SetDataFetcherForTesting(
DataFetcherSharedMemory* test_data_fetcher) {
if (data_fetcher_)
- data_fetcher_->Shutdown();
+ data_fetcher_->ShutDownOnUIThread();
data_fetcher_.reset(test_data_fetcher);
}
« no previous file with comments | « content/browser/device_sensors/device_sensor_service.h ('k') | content/browser/device_sensors/sensor_manager_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698