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

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: Adds a unit test, responds to other comments Created 8 years, 4 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 <map>
8 #include <set> 9 #include <set>
9 #include <vector> 10 #include <vector>
10 11
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 device_orientation { 22 namespace device_orientation {
22 23
23 class ProviderImpl : public Provider { 24 class ProviderImpl : public Provider {
24 public: 25 public:
25 typedef DataFetcher* (*DataFetcherFactory)(); 26 typedef DataFetcher* (*DataFetcherFactory)();
26 27
27 // Create a ProviderImpl that uses the factory to create a DataFetcher that 28 // Create a ProviderImpl that uses the factory to create a DataFetcher that
28 // can provide orientation data. A NULL DataFetcherFactory indicates that 29 // can provide data. A NULL DataFetcherFactory indicates that there are no
29 // there are no DataFetchers for this OS. 30 // DataFetchers for this OS.
30 CONTENT_EXPORT ProviderImpl(DataFetcherFactory factory); 31 CONTENT_EXPORT ProviderImpl(DataFetcherFactory factory);
31 32
32 // From Provider. 33 // From Provider.
33 virtual void AddObserver(Observer* observer) OVERRIDE; 34 virtual void AddObserver(Observer* observer) OVERRIDE;
34 virtual void RemoveObserver(Observer* observer) OVERRIDE; 35 virtual void RemoveObserver(Observer* observer) OVERRIDE;
35 36
36 private: 37 private:
37 class PollingThread; 38 class PollingThread;
38 39
39 virtual ~ProviderImpl(); 40 virtual ~ProviderImpl();
40 41
41 // Starts or Stops the provider. Called from creator_loop_. 42 // Starts or Stops the provider. Called from creator_loop_.
42 void Start(); 43 void Start(DeviceData::Type type);
43 void Stop(); 44 void Stop();
44 45
45 void ScheduleInitializePollingThread(); 46 void ScheduleInitializePollingThread(DeviceData::Type device_data_type);
47 void ScheduleDoAddPollingDataType(DeviceData::Type type);
46 48
47 // Method for notifying observers of an orientation update. 49 // Method for notifying observers of a data update.
48 // Runs on the creator_thread_. 50 // Runs on the creator_thread_.
49 void DoNotify(const Orientation& orientation); 51 void DoNotify(const DeviceData* device_data,
52 DeviceData::Type device_data_type);
53
54 static bool ShouldFireEvent(const DeviceData* old_data,
55 const DeviceData* new_data, DeviceData::Type device_data_type);
50 56
51 // The Message Loop on which this object was created. 57 // The Message Loop on which this object was created.
52 // Typically the I/O loop, but may be something else during testing. 58 // Typically the I/O loop, but may be something else during testing.
53 MessageLoop* creator_loop_; 59 MessageLoop* creator_loop_;
54 60
55 // Members below are only to be used from the creator_loop_. 61 // Members below are only to be used from the creator_loop_.
56 DataFetcherFactory factory_; 62 DataFetcherFactory factory_;
57 std::set<Observer*> observers_; 63 std::set<Observer*> observers_;
58 Orientation last_notification_; 64 std::map<DeviceData::Type, scoped_refptr<const DeviceData> >
65 last_notifications_map_;
59 66
67 // When polling_thread_ is running, members below are only to be used
68 // from that thread.
60 base::WeakPtrFactory<ProviderImpl> weak_factory_; 69 base::WeakPtrFactory<ProviderImpl> weak_factory_;
61 70
62 // Polling is done on this background thread. PollingThread is owned by 71 // Polling is done on this background thread. PollingThread is owned by
63 // the ProviderImpl object. But its deletion doesn't happen synchronously 72 // the ProviderImpl object. But its deletion doesn't happen synchronously
64 // along with deletion of the ProviderImpl. Thus this should be a raw 73 // along with deletion of the ProviderImpl. Thus this should be a raw
65 // pointer instead of scoped_ptr. 74 // pointer instead of scoped_ptr.
66 PollingThread* polling_thread_; 75 PollingThread* polling_thread_;
67 }; 76 };
68 77
69 } // namespace device_orientation 78 } // namespace device_orientation
70 79
71 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_IMPL_H_ 80 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_PROVIDER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698