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

Side by Side Diff: content/browser/device_orientation/provider_impl.cc

Issue 10698046: Implements part of Device Motion in the Renderer (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 #include <cmath> 5 #include <cmath>
6 #include <set> 6 #include <set>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/threading/thread.h" 12 #include "base/threading/thread.h"
13 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
14 #include "content/browser/device_orientation/orientation.h" 14 #include "content/browser/device_orientation/orientation.h"
15 #include "content/browser/device_orientation/provider_impl.h" 15 #include "content/browser/device_orientation/provider_impl.h"
16 16
17 namespace device_orientation { 17 namespace device_orientation {
18 18
19 ProviderImpl::ProviderImpl(const DataFetcherFactory factories[]) 19 ProviderImpl::ProviderImpl(const DataFetcherFactory factories[])
20 : creator_loop_(MessageLoop::current()), 20 : creator_loop_(MessageLoop::current()),
21 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 21 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
22 for (const DataFetcherFactory* fp = factories; *fp; ++fp) 22 for (const DataFetcherFactory* fp = factories; *fp; ++fp)
23 factories_.push_back(*fp); 23 factories_.push_back(*fp);
24 } 24 }
25 25
26 ProviderImpl::~ProviderImpl() { 26 ProviderImpl::~ProviderImpl() {
27 } 27 }
28 28
29 void ProviderImpl::AddObserver(Observer* observer) { 29 void ProviderImpl::AddOrientationObserver(OrientationObserver* observer) {
30 DCHECK(MessageLoop::current() == creator_loop_); 30 DCHECK(MessageLoop::current() == creator_loop_);
31 31
32 observers_.insert(observer); 32 observers_.insert(observer);
33 if (observers_.size() == 1) 33 if (observers_.size() == 1)
34 Start(); 34 Start();
35 else 35 else
36 observer->OnOrientationUpdate(last_notification_); 36 observer->OnOrientationUpdate(last_notification_);
37 } 37 }
38 38
39 void ProviderImpl::RemoveObserver(Observer* observer) { 39 void ProviderImpl::RemoveOrientationObserver(OrientationObserver* observer) {
40 DCHECK(MessageLoop::current() == creator_loop_); 40 DCHECK(MessageLoop::current() == creator_loop_);
41 41
42 observers_.erase(observer); 42 observers_.erase(observer);
43 if (observers_.empty()) 43 if (observers_.empty())
44 Stop(); 44 Stop();
45 } 45 }
46 46
47 void ProviderImpl::Start() { 47 void ProviderImpl::Start() {
48 DCHECK(MessageLoop::current() == creator_loop_); 48 DCHECK(MessageLoop::current() == creator_loop_);
49 DCHECK(!polling_thread_.get()); 49 DCHECK(!polling_thread_.get());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 base::Bind(&ProviderImpl::DoInitializePollingThread, 104 base::Bind(&ProviderImpl::DoInitializePollingThread,
105 this, 105 this,
106 factories_)); 106 factories_));
107 } 107 }
108 108
109 void ProviderImpl::DoNotify(const Orientation& orientation) { 109 void ProviderImpl::DoNotify(const Orientation& orientation) {
110 DCHECK(MessageLoop::current() == creator_loop_); 110 DCHECK(MessageLoop::current() == creator_loop_);
111 111
112 last_notification_ = orientation; 112 last_notification_ = orientation;
113 113
114 typedef std::set<Observer*>::const_iterator Iterator; 114 typedef std::set<OrientationObserver*>::const_iterator Iterator;
115 for (Iterator i = observers_.begin(), e = observers_.end(); i != e; ++i) 115 for (Iterator i = observers_.begin(), e = observers_.end(); i != e; ++i)
116 (*i)->OnOrientationUpdate(orientation); 116 (*i)->OnOrientationUpdate(orientation);
117 117
118 if (orientation.IsEmpty()) { 118 if (orientation.IsEmpty()) {
119 // Notify observers about failure to provide data exactly once. 119 // Notify observers about failure to provide data exactly once.
120 observers_.clear(); 120 observers_.clear();
121 Stop(); 121 Stop();
122 } 122 }
123 } 123 }
124 124
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); 200 DCHECK(MessageLoop::current() == polling_thread_->message_loop());
201 DCHECK(data_fetcher_.get()); 201 DCHECK(data_fetcher_.get());
202 202
203 // TODO(erg): There used to be unused code here, that called a default 203 // TODO(erg): There used to be unused code here, that called a default
204 // implementation on the DataFetcherInterface that was never defined. I'm 204 // implementation on the DataFetcherInterface that was never defined. I'm
205 // removing unused methods from headers. 205 // removing unused methods from headers.
206 return base::TimeDelta::FromMilliseconds(kDesiredSamplingIntervalMs); 206 return base::TimeDelta::FromMilliseconds(kDesiredSamplingIntervalMs);
207 } 207 }
208 208
209 } // namespace device_orientation 209 } // namespace device_orientation
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698