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

Side by Side Diff: content/browser/device_orientation/provider_impl.h

Issue 10755002: Refactors DeviceOrientation to make it more extensible (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Handles null device_data in observer Created 8 years, 5 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 (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/id_map.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "base/time.h" 14 #include "base/time.h"
14 #include "content/browser/device_orientation/data_fetcher.h" 15 #include "content/browser/device_orientation/data_fetcher.h"
15 #include "content/browser/device_orientation/orientation.h" 16 #include "content/browser/device_orientation/device_data.h"
16 #include "content/browser/device_orientation/provider.h" 17 #include "content/browser/device_orientation/provider.h"
17 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
18 19
19 class MessageLoop; 20 class MessageLoop;
20 21
21 namespace base { 22 namespace base {
22 class Thread; 23 class Thread;
23 } 24 }
24 25
25 namespace device_orientation { 26 namespace device_orientation {
26 27
27 class ProviderImpl : public Provider { 28 class ProviderImpl : public Provider {
28 public: 29 public:
29 typedef DataFetcher* (*DataFetcherFactory)(); 30 typedef DataFetcher* (*DataFetcherFactory)();
30 31
31 // Create a ProviderImpl that uses the NULL-terminated factories array to find 32 // Create a ProviderImpl that uses the NULL-terminated factories array to find
32 // a DataFetcher that can provide orientation data. 33 // a DataFetcher that can provide data.
33 CONTENT_EXPORT ProviderImpl(const DataFetcherFactory factories[]); 34 CONTENT_EXPORT ProviderImpl(const DataFetcherFactory factories[]);
34 35
35 // From Provider. 36 // From Provider.
36 virtual void AddObserver(Observer* observer) OVERRIDE; 37 virtual void AddObserver(Observer* observer) OVERRIDE;
37 virtual void RemoveObserver(Observer* observer) OVERRIDE; 38 virtual void RemoveObserver(Observer* observer) OVERRIDE;
38 39
39 private: 40 private:
40 virtual ~ProviderImpl(); 41 virtual ~ProviderImpl();
41 42
42 // Starts or Stops the provider. Called from creator_loop_. 43 // Starts or Stops the provider. Called from creator_loop_.
43 void Start(); 44 void Start();
44 void Stop(); 45 void Stop();
45 46
47 // Method for adding a type of observer to poll. Runs on the polling_thread_.
hans 2012/07/18 17:21:02 we're not really polling the observers, though? Ma
aousterh 2012/07/20 11:18:52 Done. I also renamed the function and member obser
48 void DoAddObserverType(DeviceData::Type device_data_type);
49 void ScheduleDoAddObserverType(DeviceData::Type device_data_type);
50
46 // Method for finding a suitable DataFetcher and starting the polling. 51 // Method for finding a suitable DataFetcher and starting the polling.
47 // Runs on the polling_thread_. 52 // Runs on the polling_thread_.
48 void DoInitializePollingThread( 53 void DoInitializePollingThread(
49 const std::vector<DataFetcherFactory>& factories); 54 const std::vector<DataFetcherFactory>& factories,
50 void ScheduleInitializePollingThread(); 55 DeviceData::Type device_data_type);
56 void ScheduleInitializePollingThread(DeviceData::Type device_data_type);
51 57
52 // Method for polling a DataFetcher. Runs on the polling_thread_. 58 // Method for polling a DataFetcher. Runs on the polling_thread_.
53 void DoPoll(); 59 void DoPoll();
54 void ScheduleDoPoll(); 60 void ScheduleDoPoll();
55 61
56 // Method for notifying observers of an orientation update. 62 // Method for notifying observers of a data update.
57 // Runs on the creator_thread_. 63 // Runs on the creator_thread_.
58 void DoNotify(const Orientation& orientation); 64 void DoNotify(const DeviceData* device_data,
59 void ScheduleDoNotify(const Orientation& orientation); 65 DeviceData::Type device_data_type);
60 66 void ScheduleDoNotify(const DeviceData* device_data,
61 static bool SignificantlyDifferent(const Orientation& orientation1, 67 DeviceData::Type device_data_type);
62 const Orientation& orientation2);
63 68
64 enum { kDesiredSamplingIntervalMs = 100 }; 69 enum { kDesiredSamplingIntervalMs = 100 };
65 base::TimeDelta SamplingInterval() const; 70 base::TimeDelta SamplingInterval() const;
66 71
67 // The Message Loop on which this object was created. 72 // The Message Loop on which this object was created.
68 // Typically the I/O loop, but may be something else during testing. 73 // Typically the I/O loop, but may be something else during testing.
69 MessageLoop* creator_loop_; 74 MessageLoop* creator_loop_;
70 75
71 // Members below are only to be used from the creator_loop_. 76 // Members below are only to be used from the creator_loop_.
72 std::vector<DataFetcherFactory> factories_; 77 std::vector<DataFetcherFactory> factories_;
73 std::set<Observer*> observers_; 78 std::set<Observer*> observers_;
74 Orientation last_notification_; 79 IDMap<DeviceData, IDMapOwnPointer> last_notifications_map_;
hans 2012/07/18 17:21:02 I'm not sure IDMap is the best for this. Could we
aousterh 2012/07/20 11:18:52 I used IDMap because it's not possible to use std:
75 80
76 // When polling_thread_ is running, members below are only to be used 81 // When polling_thread_ is running, members below are only to be used
77 // from that thread. 82 // from that thread.
78 scoped_ptr<DataFetcher> data_fetcher_; 83 scoped_ptr<DataFetcher> data_fetcher_;
79 Orientation last_orientation_; 84 scoped_ptr<IDMap<DeviceData, IDMapOwnPointer> > last_device_data_map_;
hans 2012/07/18 17:21:02 same here
aousterh 2012/07/20 11:18:52 Done.
80 base::WeakPtrFactory<ProviderImpl> weak_factory_; 85 base::WeakPtrFactory<ProviderImpl> weak_factory_;
86 std::set<DeviceData::Type> observer_types_;
81 87
82 // Polling is done on this background thread. 88 // Polling is done on this background thread.
83 scoped_ptr<base::Thread> polling_thread_; 89 scoped_ptr<base::Thread> polling_thread_;
84 }; 90 };
85 91
86 } // namespace device_orientation 92 } // namespace device_orientation
87 93
88 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_IMPL_H_ 94 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698