OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_ORIENTATION_PROVIDER_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_IMPL_H_ |
6 #define CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_IMPL_H_ | 6 #define CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_IMPL_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "content/browser/device_orientation/data_fetcher.h" | 14 #include "content/browser/device_orientation/data_fetcher.h" |
15 #include "content/browser/device_orientation/orientation.h" | 15 #include "content/browser/device_orientation/orientation.h" |
16 #include "content/browser/device_orientation/provider.h" | 16 #include "content/browser/device_orientation/provider.h" |
17 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
18 | 18 |
19 class MessageLoop; | 19 class MessageLoop; |
20 | 20 |
21 namespace device_orientation { | 21 namespace device_orientation { |
22 | 22 |
23 class ProviderImpl : public Provider { | 23 class ProviderImpl : public Provider { |
24 public: | 24 public: |
25 typedef DataFetcher* (*DataFetcherFactory)(); | 25 typedef DataFetcher* (*DataFetcherFactory)(); |
26 | 26 |
27 // Create a ProviderImpl that uses the NULL-terminated factories array to find | 27 // Create a ProviderImpl that uses the factory to create a DataFetcher that |
28 // a DataFetcher that can provide orientation data. | 28 // can provide orientation data. A NULL DataFetcherFactory indicates that |
29 CONTENT_EXPORT ProviderImpl(const DataFetcherFactory factories[]); | 29 // there are no DataFetchers for this OS. |
| 30 CONTENT_EXPORT ProviderImpl(DataFetcherFactory factory); |
30 | 31 |
31 // From Provider. | 32 // From Provider. |
32 virtual void AddObserver(Observer* observer) OVERRIDE; | 33 virtual void AddObserver(Observer* observer) OVERRIDE; |
33 virtual void RemoveObserver(Observer* observer) OVERRIDE; | 34 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
34 | 35 |
35 private: | 36 private: |
36 class PollingThread; | 37 class PollingThread; |
37 | 38 |
38 virtual ~ProviderImpl(); | 39 virtual ~ProviderImpl(); |
39 | 40 |
40 // Starts or Stops the provider. Called from creator_loop_. | 41 // Starts or Stops the provider. Called from creator_loop_. |
41 void Start(); | 42 void Start(); |
42 void Stop(); | 43 void Stop(); |
43 | 44 |
44 void ScheduleInitializePollingThread(); | 45 void ScheduleInitializePollingThread(); |
45 | 46 |
46 // Method for notifying observers of an orientation update. | 47 // Method for notifying observers of an orientation update. |
47 // Runs on the creator_thread_. | 48 // Runs on the creator_thread_. |
48 void DoNotify(const Orientation& orientation); | 49 void DoNotify(const Orientation& orientation); |
49 | 50 |
50 // The Message Loop on which this object was created. | 51 // The Message Loop on which this object was created. |
51 // Typically the I/O loop, but may be something else during testing. | 52 // Typically the I/O loop, but may be something else during testing. |
52 MessageLoop* creator_loop_; | 53 MessageLoop* creator_loop_; |
53 | 54 |
54 // Members below are only to be used from the creator_loop_. | 55 // Members below are only to be used from the creator_loop_. |
55 std::vector<DataFetcherFactory> factories_; | 56 DataFetcherFactory factory_; |
56 std::set<Observer*> observers_; | 57 std::set<Observer*> observers_; |
57 Orientation last_notification_; | 58 Orientation last_notification_; |
58 | 59 |
59 base::WeakPtrFactory<ProviderImpl> weak_factory_; | 60 base::WeakPtrFactory<ProviderImpl> weak_factory_; |
60 | 61 |
61 // Polling is done on this background thread. PollingThread is owned by | 62 // Polling is done on this background thread. PollingThread is owned by |
62 // the ProviderImpl object. But its deletion doesn't happen synchronously | 63 // the ProviderImpl object. But its deletion doesn't happen synchronously |
63 // along with deletion of the ProviderImpl. Thus this should be a raw | 64 // along with deletion of the ProviderImpl. Thus this should be a raw |
64 // pointer instead of scoped_ptr. | 65 // pointer instead of scoped_ptr. |
65 PollingThread* polling_thread_; | 66 PollingThread* polling_thread_; |
66 }; | 67 }; |
67 | 68 |
68 } // namespace device_orientation | 69 } // namespace device_orientation |
69 | 70 |
70 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_IMPL_H_ | 71 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_IMPL_H_ |
OLD | NEW |