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

Unified Diff: device/sensors/device_sensor_service.cc

Issue 2730333002: Make DeviceSensorService implement MainLoop::DestructionObserver (Closed)
Patch Set: Make DeviceSensorService observes IOThread to shutdown in right time. Created 3 years, 9 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: device/sensors/device_sensor_service.cc
diff --git a/device/sensors/device_sensor_service.cc b/device/sensors/device_sensor_service.cc
index 12ffa6bb5c07cbb2f2b7495a57735d8ba4328899..08f714010d1da0c8c51f6b3a86c2f71276c823ca 100644
--- a/device/sensors/device_sensor_service.cc
+++ b/device/sensors/device_sensor_service.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/singleton.h"
+#include "base/trace_event/trace_event.h"
#include "device/sensors/data_fetcher_shared_memory.h"
namespace device {
@@ -16,7 +17,12 @@ DeviceSensorService::DeviceSensorService()
num_motion_readers_(0),
num_orientation_readers_(0),
num_orientation_absolute_readers_(0),
- is_shutdown_(false) {}
+ is_shutdown_(false) {
+#if !defined(OS_ANDROID)
ke.he 2017/03/08 09:19:55 For Non-Android platform, The strongBinding happen
+ DCHECK(base::MessageLoopForIO::IsCurrent());
+ base::MessageLoop::current()->AddDestructionObserver(this);
+#endif
+}
DeviceSensorService::~DeviceSensorService() {}
@@ -95,6 +101,13 @@ mojo::ScopedSharedBufferHandle DeviceSensorService::GetSharedMemoryHandle(
return data_fetcher_->GetSharedMemoryHandle(consumer_type);
}
+void DeviceSensorService::WillDestroyCurrentMessageLoop() {
+ DCHECK(base::MessageLoopForIO::IsCurrent());
+ base::MessageLoop::current()->RemoveDestructionObserver(this);
+ TRACE_EVENT0("shutdown", "DeviceSensorService::Subsystem:SensorService");
+ Shutdown();
+}
+
void DeviceSensorService::Shutdown() {
if (data_fetcher_) {
data_fetcher_->Shutdown();

Powered by Google App Engine
This is Rietveld 408576698