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

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

Issue 3136008: Implement device_orientation::Provider. (Closed)
Patch Set: Patch Created 10 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
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_DEVICE_ORIENTATION_PROVIDER_IMPL_H_
6 #define CHROME_BROWSER_DEVICE_ORIENTATION_PROVIDER_IMPL_H_
7
8 #include <set>
9 #include <vector>
10
11 #include "base/scoped_ptr.h"
12 #include "base/task.h"
13 #include "chrome/browser/device_orientation/data_fetcher.h"
14 #include "chrome/browser/device_orientation/orientation.h"
15 #include "chrome/browser/device_orientation/provider.h"
16
17 class MessageLoop;
18
19 namespace base {
20 class Thread;
21 }
22
23 namespace device_orientation {
24
25 class ProviderImpl : public Provider {
26 public:
27 typedef DataFetcher* (*DataFetcherFactory)();
28
29 // Create a ProviderImpl that expects calls to AddObserver and RemoveObserver
30 // on message_loop, sends notifications to observers on message_loop,
31 // and uses the NULL-terminated factories array to find a DataFetcher
32 // that can provide orientation data.
33 ProviderImpl(MessageLoop* message_loop, const DataFetcherFactory factories[]);
34
35 // From Provider.
36 virtual void AddObserver(Observer* observer);
37 virtual void RemoveObserver(Observer* observer);
38
39 private:
40 virtual ~ProviderImpl();
41
42 // Starts or Stops the provider. Called from creator_loop_.
43 void Start();
44 void Stop();
45
46 // Method for finding a suitable DataFetcher and starting the polling.
47 // Runs on the polling_thread_.
48 void DoInitializePollingThread(std::vector<DataFetcherFactory> factories);
49 void ScheduleInitializePollingThread();
50
51 // Method for polling a DataFetcher. Runs on the polling_thread_.
52 void DoPoll();
53 void ScheduleDoPoll();
54
55 // Method for notifying observers of an orientation update.
56 // Runs on the creator_thread_.
57 void DoNotify(Orientation orientation);
58 void ScheduleDoNotify(Orientation orientation);
59
60 static bool SignificantlyDifferent(const Orientation& orientation1,
61 const Orientation& orientation2);
62
63 enum { kDesiredSamplingIntervalMs = 100 };
64 int SamplingIntervalMs() const;
65
66 // The Message Loop on which this object was created.
67 // Typically the I/O loop, but may be something else during testing.
68 MessageLoop* creator_loop_;
69
70 // Members below are only to be used from the creator_loop_.
71 std::vector<DataFetcherFactory> factories_;
72 std::set<Observer*> observers_;
73 Orientation last_notification_;
74
75 // When polling_thread_ is running, members below are only to be used
76 // from that thread.
77 scoped_ptr<DataFetcher> data_fetcher_;
78 Orientation last_orientation_;
79 ScopedRunnableMethodFactory<ProviderImpl> do_poll_method_factory_;
80
81 // Polling is done on this background thread.
82 scoped_ptr<base::Thread> polling_thread_;
83 };
84
85 } // namespace device_orientation
86
87 #endif // CHROME_BROWSER_DEVICE_ORIENTATION_PROVIDER_IMPL_H_
OLDNEW
« no previous file with comments | « chrome/browser/device_orientation/provider.cc ('k') | chrome/browser/device_orientation/provider_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698