diff options
author | cwolfe@chromium.org <cwolfe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-19 20:39:26 +0000 |
---|---|---|
committer | cwolfe@chromium.org <cwolfe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-19 20:39:26 +0000 |
commit | a27a92efe4dd9eb4d71e48e1bbc4c6953fa13971 (patch) | |
tree | 0b3b1cdc3ba36e9e4427b47d82a67f0c6df30008 /content | |
parent | 215a61222817f1fd7a07e91c60cdb73f8fe192a3 (diff) | |
download | chromium_src-a27a92efe4dd9eb4d71e48e1bbc4c6953fa13971.zip chromium_src-a27a92efe4dd9eb4d71e48e1bbc4c6953fa13971.tar.gz chromium_src-a27a92efe4dd9eb4d71e48e1bbc4c6953fa13971.tar.bz2 |
Initial sensor event provider for testing views screen rotation
The sensors API will unify various types of sensor data into a set of channels, each of which provides change events and periodic updates.
This version of the API is intended only to support the experimental screen rotation code and is not for general use. In particular, the final listener will declare generic |OnSensorChange| and |OnSensorUpdate| methods, rather than the special-purpose |OnScreenOrientationChange|.
BUG=none
TEST=manual with http://codereview.chromium.org/7273073/
Review URL: http://codereview.chromium.org/7366011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93094 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/sensors/provider.cc | 20 | ||||
-rw-r--r-- | content/browser/sensors/provider.h | 56 | ||||
-rw-r--r-- | content/browser/sensors/provider_impl.cc | 35 | ||||
-rw-r--r-- | content/browser/sensors/provider_impl.h | 44 | ||||
-rw-r--r-- | content/common/sensors.h | 29 | ||||
-rw-r--r-- | content/common/sensors_listener.h | 36 | ||||
-rw-r--r-- | content/content_browser.gypi | 4 | ||||
-rw-r--r-- | content/content_common.gypi | 2 |
8 files changed, 226 insertions, 0 deletions
diff --git a/content/browser/sensors/provider.cc b/content/browser/sensors/provider.cc new file mode 100644 index 0000000..431e836 --- /dev/null +++ b/content/browser/sensors/provider.cc @@ -0,0 +1,20 @@ +// Copyright (c) 2011 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. + +#include "content/browser/sensors/provider.h" +#include "content/browser/sensors/provider_impl.h" + +namespace sensors { + +Provider* Provider::GetInstance() { + return ProviderImpl::GetInstance(); +} + +Provider::Provider() { +} + +Provider::~Provider() { +} + +} // sensors diff --git a/content/browser/sensors/provider.h b/content/browser/sensors/provider.h new file mode 100644 index 0000000..d2c204d --- /dev/null +++ b/content/browser/sensors/provider.h @@ -0,0 +1,56 @@ +// Copyright (c) 2011 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 CONTENT_BROWSER_SENSORS_PROVIDER_H_ +#define CONTENT_BROWSER_SENSORS_PROVIDER_H_ +#pragma once + +#include "content/common/sensors_listener.h" + +namespace sensors { + +// The sensors API will unify various types of sensor data into a set of +// channels, each of which provides change events and periodic updates. +// +// This version of the API is intended only to support the experimental screen +// rotation code and is not for general use. In particular, the final listener +// will declare generic |OnSensorChanged| and |OnSensorUpdated| methods, rather +// than the special-purpose |OnScreenOrientationChanged|. +// +// TODO(cwolfe): Finish defining the initial set of channels and replace this +// with the generic sensor provider. +// +class Provider { + public: + static Provider* GetInstance(); + + // Adds a sensor listener. The listener will receive callbacks to indicate + // sensor changes and updates until it is removed. + // + // This method may be called in any thread. Callbacks on a listener will + // always be executed in the thread which added that listener. + virtual void AddListener(Listener* listener) = 0; + + // Removes a sensor listener. + // + // This method must be called in the same thread which added the listener. + // If the listener is not currently subscribed, this method may be called in + // any thread. + virtual void RemoveListener(Listener* listener) = 0; + + // Broadcasts a change to the coarse screen orientation. + // + // This method may be called in any thread. + virtual void ScreenOrientationChanged(const ScreenOrientation& change) = 0; + + protected: + Provider(); + virtual ~Provider(); + + DISALLOW_COPY_AND_ASSIGN(Provider); +}; + +} // namespace sensors + +#endif // CONTENT_BROWSER_SENSORS_PROVIDER_H_ diff --git a/content/browser/sensors/provider_impl.cc b/content/browser/sensors/provider_impl.cc new file mode 100644 index 0000000..b7b4ffe --- /dev/null +++ b/content/browser/sensors/provider_impl.cc @@ -0,0 +1,35 @@ +// Copyright (c) 2011 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. + +#include "base/logging.h" +#include "base/memory/singleton.h" +#include "content/browser/sensors/provider_impl.h" + +namespace sensors { + +ProviderImpl* ProviderImpl::GetInstance() { + return Singleton<ProviderImpl>::get(); +} + +ProviderImpl::ProviderImpl() + : listeners_(new ListenerList()) { +} + +ProviderImpl::~ProviderImpl() { +} + +void ProviderImpl::AddListener(Listener* listener) { + listeners_->AddObserver(listener); +} + +void ProviderImpl::RemoveListener(Listener* listener) { + listeners_->RemoveObserver(listener); +} + +void ProviderImpl::ScreenOrientationChanged( + const ScreenOrientation& change) { + listeners_->Notify(&Listener::OnScreenOrientationChanged, change); +} + +} // namespace sensors diff --git a/content/browser/sensors/provider_impl.h b/content/browser/sensors/provider_impl.h new file mode 100644 index 0000000..eb8e271 --- /dev/null +++ b/content/browser/sensors/provider_impl.h @@ -0,0 +1,44 @@ +// Copyright (c) 2011 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 CONTENT_BROWSER_SENSORS_PROVIDER_IMPL_H_ +#define CONTENT_BROWSER_SENSORS_PROVIDER_IMPL_H_ +#pragma once + +#include "base/memory/ref_counted.h" +#include "base/observer_list_threadsafe.h" +#include "base/task.h" +#include "content/browser/sensors/provider.h" + +template <typename T> +struct DefaultSingletonTraits; + +namespace sensors { + +class ProviderImpl : public Provider { + public: + static ProviderImpl* GetInstance(); + + // Provider implementation + virtual void AddListener(Listener* listener); + virtual void RemoveListener(Listener* listener); + virtual void ScreenOrientationChanged(const ScreenOrientation& change); + + private: + friend struct DefaultSingletonTraits<ProviderImpl>; + + ProviderImpl(); + virtual ~ProviderImpl(); + + typedef ObserverListThreadSafe<Listener> ListenerList; + scoped_refptr<ListenerList> listeners_; + + DISALLOW_COPY_AND_ASSIGN(ProviderImpl); +}; + +} // namespace sensors + +DISABLE_RUNNABLE_METHOD_REFCOUNT(sensors::ProviderImpl); + +#endif // CONTENT_BROWSER_SENSORS_PROVIDER_IMPL_H_ diff --git a/content/common/sensors.h b/content/common/sensors.h new file mode 100644 index 0000000..26beb12 --- /dev/null +++ b/content/common/sensors.h @@ -0,0 +1,29 @@ +// Copyright (c) 2011 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 CONTENT_COMMON_SENSORS_H_ +#define CONTENT_COMMON_SENSORS_H_ +#pragma once + +namespace sensors { + +// Indicates the coarse orientation of the device. +struct ScreenOrientation { + enum Side { + TOP = 0, // The screen is in its normal orientation. + BOTTOM = 1, // The screen is upside-down (180-degree rotation). + LEFT = 2, // The right side of the screen is at the top. + RIGHT = 3, // The left side of the screen is at the top. + FRONT = 4, // The screen is laid flat, facing upward. + BACK = 5, // The screen is laid flat, facing downward. + }; + + // The side of the device which the user probably perceives as facing upward. + // This can be used to orient controls and content in a "natural" direction. + Side upward; +}; + +} // namespace sensors + +#endif // CONTENT_COMMON_SENSORS_H_ diff --git a/content/common/sensors_listener.h b/content/common/sensors_listener.h new file mode 100644 index 0000000..a2fe5e0 --- /dev/null +++ b/content/common/sensors_listener.h @@ -0,0 +1,36 @@ +// Copyright (c) 2011 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 CONTENT_COMMON_SENSORS_LISTENER_H_ +#define CONTENT_COMMON_SENSORS_LISTENER_H_ +#pragma once + +#include "base/basictypes.h" +#include "content/common/sensors.h" + +namespace sensors { + +// The sensors API will unify various types of sensor data into a set of +// channels, each of which provides change events and periodic updates. +// +// This version of the API is intended only to support the experimental screen +// rotation code and is not for general use. In particular, the final listener +// will declare generic |OnSensorChanged| and |OnSensorUpdated| methods, rather +// than the special-purpose |OnScreenOrientationChanged|. +// +class Listener { + public: + // Called whenever the coarse orientation of the device changes. + virtual void OnScreenOrientationChanged(const ScreenOrientation& change) = 0; + + protected: + Listener() {} + virtual ~Listener() {} + + DISALLOW_COPY_AND_ASSIGN(Listener); +}; + +} // namespace sensors + +#endif // CONTENT_COMMON_SENSORS_LISTENER_H_ diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 67e5a17..868ea58 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -374,6 +374,10 @@ 'browser/resource_context.h', 'browser/safe_util_win.cc', 'browser/safe_util_win.h', + 'browser/sensors/provider.cc', + 'browser/sensors/provider.h', + 'browser/sensors/provider_impl.cc', + 'browser/sensors/provider_impl.h', 'browser/site_instance.cc', 'browser/site_instance.h', 'browser/speech/audio_encoder.cc', diff --git a/content/content_common.gypi b/content/content_common.gypi index 42cfd32..638b5db 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -210,6 +210,8 @@ 'common/section_util_win.cc', 'common/section_util_win.h', 'common/security_style.h', + 'common/sensors.h', + 'common/sensors_listener.h', 'common/serialized_script_value.cc', 'common/serialized_script_value.h', 'common/set_process_title.cc', |