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

Side by Side Diff: content/browser/device_sensors/device_sensor_service.h

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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_SENSOR_SERVICE_H_ 5 #ifndef CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_SENSOR_SERVICE_H_
6 #define CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_SENSOR_SERVICE_H_ 6 #define CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_SENSOR_SERVICE_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/callback_forward.h" 10 #include "base/callback_forward.h"
(...skipping 12 matching lines...) Expand all
23 // Owns the data fetcher for Device Motion and Orientation and keeps track of 23 // Owns the data fetcher for Device Motion and Orientation and keeps track of
24 // the number of consumers currently using the data. The data fetcher is stopped 24 // the number of consumers currently using the data. The data fetcher is stopped
25 // when there are no consumers. 25 // when there are no consumers.
26 class CONTENT_EXPORT DeviceSensorService { 26 class CONTENT_EXPORT DeviceSensorService {
27 public: 27 public:
28 // Returns the DeviceSensorService singleton. 28 // Returns the DeviceSensorService singleton.
29 static DeviceSensorService* GetInstance(); 29 static DeviceSensorService* GetInstance();
30 30
31 // Increments the number of users of the provider. The Provider is running 31 // Increments the number of users of the provider. The Provider is running
32 // when there's > 0 users, and is paused when the count drops to 0. 32 // when there's > 0 users, and is paused when the count drops to 0.
33 // Must be called on the I/O thread. 33 // Must be called on a thread that can perform I/O.
34 void AddConsumer(ConsumerType consumer_type); 34 void AddConsumer(ConsumerType consumer_type);
35 35
36 // Removes a consumer. Should be matched with an AddConsumer call. 36 // Removes a consumer. Should be matched with an AddConsumer call.
37 // Must be called on the I/O thread. 37 // Must be called on a thread that can perform I/O.
38 void RemoveConsumer(ConsumerType cosumer_type); 38 void RemoveConsumer(ConsumerType cosumer_type);
39 39
40 // Returns the shared memory handle of the device motion data. 40 // Returns the shared memory handle of the device motion data.
41 mojo::ScopedSharedBufferHandle GetSharedMemoryHandle( 41 mojo::ScopedSharedBufferHandle GetSharedMemoryHandle(
42 ConsumerType consumer_type); 42 ConsumerType consumer_type);
43 43
44 // Stop/join with the background polling thread in |provider_|. 44 // Performs initialization operations on the UI thread.
45 void Shutdown(); 45 void InitOnUIThread();
46
47 // Performs initialization operations on the IO thread.
48 void InitOnIOThread();
49
50 // Stop/join with the background polling thread in |provider_|. Must be
51 // called on the UI thread.
52 void ShutDownOnUIThread();
46 53
47 // Injects a custom data fetcher for testing purposes. This class takes 54 // Injects a custom data fetcher for testing purposes. This class takes
48 // ownership of the injected object. 55 // ownership of the injected object.
49 void SetDataFetcherForTesting(DataFetcherSharedMemory* test_data_fetcher); 56 void SetDataFetcherForTesting(DataFetcherSharedMemory* test_data_fetcher);
50 57
51 private: 58 private:
52 friend struct base::DefaultSingletonTraits<DeviceSensorService>; 59 friend struct base::DefaultSingletonTraits<DeviceSensorService>;
53 60
54 DeviceSensorService(); 61 DeviceSensorService();
55 virtual ~DeviceSensorService(); 62 virtual ~DeviceSensorService();
56 63
57 bool ChangeNumberConsumers(ConsumerType consumer_type, int delta); 64 bool ChangeNumberConsumers(ConsumerType consumer_type, int delta);
58 int GetNumberConsumers(ConsumerType consumer_type) const; 65 int GetNumberConsumers(ConsumerType consumer_type) const;
59 66
60 int num_light_readers_; 67 int num_light_readers_;
61 int num_motion_readers_; 68 int num_motion_readers_;
62 int num_orientation_readers_; 69 int num_orientation_readers_;
63 int num_orientation_absolute_readers_; 70 int num_orientation_absolute_readers_;
64 bool is_shutdown_; 71 bool is_shutdown_;
65 std::unique_ptr<DataFetcherSharedMemory> data_fetcher_; 72 std::unique_ptr<DataFetcherSharedMemory> data_fetcher_;
66 base::ThreadChecker thread_checker_; 73
74 // Associated with the IO thread.
75 base::ThreadChecker io_thread_checker_;
67 76
68 DISALLOW_COPY_AND_ASSIGN(DeviceSensorService); 77 DISALLOW_COPY_AND_ASSIGN(DeviceSensorService);
69 }; 78 };
70 79
71 } // namespace content 80 } // namespace content
72 81
73 #endif // CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_SENSOR_SERVICE_H_ 82 #endif // CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_SENSOR_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698