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

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

Issue 10755002: Refactors DeviceOrientation to make it more extensible (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: 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 CHROME_BROWSER_DEVICE_ORIENTATION_DATA_FETCHER_IMPL_ANDROID_H_ 5 #ifndef CHROME_BROWSER_DEVICE_ORIENTATION_DATA_FETCHER_IMPL_ANDROID_H_
6 #define CHROME_BROWSER_DEVICE_ORIENTATION_DATA_FETCHER_IMPL_ANDROID_H_ 6 #define CHROME_BROWSER_DEVICE_ORIENTATION_DATA_FETCHER_IMPL_ANDROID_H_
7 #pragma once 7 #pragma once
8 8
9 #include <jni.h> 9 #include <jni.h>
10 10
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/synchronization/lock.h" 12 #include "base/synchronization/lock.h"
13 #include "content/browser/device_orientation/data_fetcher.h" 13 #include "content/browser/device_orientation/data_fetcher.h"
14 #include "content/browser/device_orientation/orientation.h" 14 #include "content/browser/device_orientation/orientation.h"
15 15
16 namespace device_orientation { 16 namespace device_orientation {
17 17
18 // Android implementation of DeviceOrientation API. 18 // Android implementation of DeviceOrientation API.
19 19
20 // Android's SensorManager has a push API, whereas Chrome wants to pull data. 20 // Android's SensorManager has a push API, whereas Chrome wants to pull data.
21 // To fit them together, we store incoming sensor events in a 1-element buffer. 21 // To fit them together, we store incoming sensor events in a 1-element buffer.
22 // SensorManager calls SetOrientation() which pushes a new value (discarding the 22 // SensorManager calls SetOrientation() which pushes a new value (discarding the
23 // previous value if any). Chrome calls GetOrientation() which reads the most 23 // previous value if any). Chrome calls GetDeviceData() which reads the most
24 // recent value. Repeated calls to GetOrientation() will return the same value. 24 // recent value. Repeated calls to GetDeviceData() will return the same value.
25 25
26 class DataFetcherImplAndroid : public DataFetcher { 26 class DataFetcherImplAndroid : public DataFetcher {
27 public: 27 public:
28 // Must be called at startup, before Create(). 28 // Must be called at startup, before Create().
29 static void Init(JNIEnv* env); 29 static void Init(JNIEnv* env);
30 30
31 // Factory function. We'll listen for events for the lifetime of this object. 31 // Factory function. We'll listen for events for the lifetime of this object.
32 // Returns NULL on error. 32 // Returns NULL on error.
33 static DataFetcher* Create(); 33 static DataFetcher* Create();
34 34
35 virtual ~DataFetcherImplAndroid(); 35 virtual ~DataFetcherImplAndroid();
36 36
37 // Called from Java via JNI. 37 // Called from Java via JNI.
38 void GotOrientation(JNIEnv*, jobject, 38 void GotOrientation(JNIEnv*, jobject,
39 double alpha, double beta, double gamma); 39 double alpha, double beta, double gamma);
40 40
41 // Implementation of DataFetcher. 41 // Implementation of DataFetcher.
42 virtual bool GetOrientation(Orientation* orientation) OVERRIDE; 42 virtual bool GetDeviceData(DeviceData* device_data) OVERRIDE;
43 43
44 private: 44 private:
45 DataFetcherImplAndroid(); 45 DataFetcherImplAndroid();
46 bool GetOrientation(Orientation* orientation);
46 47
47 // Wrappers for JNI methods. 48 // Wrappers for JNI methods.
48 bool Start(int rate_in_milliseconds); 49 bool Start(int rate_in_milliseconds);
49 void Stop(); 50 void Stop();
50 51
51 // Value returned by GetOrientation. 52 // Value returned by GetDeviceData.
52 scoped_ptr<Orientation> current_orientation_; 53 scoped_ptr<Orientation> current_orientation_;
53 54
54 // 1-element buffer, written by GotOrientation, read by GetOrientation. 55 // 1-element buffer, written by GotOrientation, read by GetDeviceData.
55 base::Lock next_orientation_lock_; 56 base::Lock next_orientation_lock_;
56 scoped_ptr<Orientation> next_orientation_; 57 scoped_ptr<Orientation> next_orientation_;
57 58
58 DISALLOW_COPY_AND_ASSIGN(DataFetcherImplAndroid); 59 DISALLOW_COPY_AND_ASSIGN(DataFetcherImplAndroid);
59 }; 60 };
60 61
61 } // namespace device_orientation 62 } // namespace device_orientation
62 63
63 #endif // CHROME_BROWSER_DEVICE_ORIENTATION_DATA_FETCHER_IMPL_ANDROID_H_ 64 #endif // CHROME_BROWSER_DEVICE_ORIENTATION_DATA_FETCHER_IMPL_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698