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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/device_orientation/provider_impl.h
diff --git a/chrome/browser/device_orientation/provider_impl.h b/chrome/browser/device_orientation/provider_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..bf2e27e69a8bec21a87af6a1ec51f931212bf47e
--- /dev/null
+++ b/chrome/browser/device_orientation/provider_impl.h
@@ -0,0 +1,87 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_DEVICE_ORIENTATION_PROVIDER_IMPL_H_
+#define CHROME_BROWSER_DEVICE_ORIENTATION_PROVIDER_IMPL_H_
+
+#include <set>
+#include <vector>
+
+#include "base/scoped_ptr.h"
+#include "base/task.h"
+#include "chrome/browser/device_orientation/data_fetcher.h"
+#include "chrome/browser/device_orientation/orientation.h"
+#include "chrome/browser/device_orientation/provider.h"
+
+class MessageLoop;
+
+namespace base {
+class Thread;
+}
+
+namespace device_orientation {
+
+class ProviderImpl : public Provider {
+ public:
+ typedef DataFetcher* (*DataFetcherFactory)();
+
+ // Create a ProviderImpl that expects calls to AddObserver and RemoveObserver
+ // on message_loop, sends notifications to observers on message_loop,
+ // and uses the NULL-terminated factories array to find a DataFetcher
+ // that can provide orientation data.
+ ProviderImpl(MessageLoop* message_loop, const DataFetcherFactory factories[]);
+
+ // From Provider.
+ virtual void AddObserver(Observer* observer);
+ virtual void RemoveObserver(Observer* observer);
+
+ private:
+ virtual ~ProviderImpl();
+
+ // Starts or Stops the provider. Called from creator_loop_.
+ void Start();
+ void Stop();
+
+ // Method for finding a suitable DataFetcher and starting the polling.
+ // Runs on the polling_thread_.
+ void DoInitializePollingThread(std::vector<DataFetcherFactory> factories);
+ void ScheduleInitializePollingThread();
+
+ // Method for polling a DataFetcher. Runs on the polling_thread_.
+ void DoPoll();
+ void ScheduleDoPoll();
+
+ // Method for notifying observers of an orientation update.
+ // Runs on the creator_thread_.
+ void DoNotify(Orientation orientation);
+ void ScheduleDoNotify(Orientation orientation);
+
+ static bool SignificantlyDifferent(const Orientation& orientation1,
+ const Orientation& orientation2);
+
+ enum { kDesiredSamplingIntervalMs = 100 };
+ int SamplingIntervalMs() const;
+
+ // The Message Loop on which this object was created.
+ // Typically the I/O loop, but may be something else during testing.
+ MessageLoop* creator_loop_;
+
+ // Members below are only to be used from the creator_loop_.
+ std::vector<DataFetcherFactory> factories_;
+ std::set<Observer*> observers_;
+ Orientation last_notification_;
+
+ // When polling_thread_ is running, members below are only to be used
+ // from that thread.
+ scoped_ptr<DataFetcher> data_fetcher_;
+ Orientation last_orientation_;
+ ScopedRunnableMethodFactory<ProviderImpl> do_poll_method_factory_;
+
+ // Polling is done on this background thread.
+ scoped_ptr<base::Thread> polling_thread_;
+};
+
+} // namespace device_orientation
+
+#endif // CHROME_BROWSER_DEVICE_ORIENTATION_PROVIDER_IMPL_H_
« 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