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

Side by Side Diff: content/browser/geolocation/geolocation_provider.cc

Issue 10107017: Remove requesting_frame parameters from Geolocation stack (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Comment addressed. Created 8 years, 8 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) 2011 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 "content/browser/geolocation/geolocation_provider.h" 5 #include "content/browser/geolocation/geolocation_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "base/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
11 #include "content/browser/geolocation/location_arbitrator.h" 11 #include "content/browser/geolocation/location_arbitrator.h"
12 12
13 GeolocationProvider* GeolocationProvider::GetInstance() { 13 GeolocationProvider* GeolocationProvider::GetInstance() {
14 return Singleton<GeolocationProvider>::get(); 14 return Singleton<GeolocationProvider>::get();
15 } 15 }
16 16
17 GeolocationProvider::GeolocationProvider() 17 GeolocationProvider::GeolocationProvider()
18 : base::Thread("Geolocation"), 18 : base::Thread("Geolocation"),
19 client_loop_(base::MessageLoopProxy::current()), 19 client_loop_(base::MessageLoopProxy::current()),
20 is_permission_granted_(false),
20 arbitrator_(NULL) { 21 arbitrator_(NULL) {
21 } 22 }
22 23
23 GeolocationProvider::~GeolocationProvider() { 24 GeolocationProvider::~GeolocationProvider() {
24 DCHECK(observers_.empty()); // observers must unregister. 25 DCHECK(observers_.empty()); // observers must unregister.
25 Stop(); 26 Stop();
26 DCHECK(!arbitrator_); 27 DCHECK(!arbitrator_);
27 } 28 }
28 29
29 void GeolocationProvider::AddObserver(GeolocationObserver* observer, 30 void GeolocationProvider::AddObserver(GeolocationObserver* observer,
(...skipping 16 matching lines...) Expand all
46 DCHECK(OnClientThread()); 47 DCHECK(OnClientThread());
47 base::Closure task; 48 base::Closure task;
48 if (observers_.empty()) { 49 if (observers_.empty()) {
49 DCHECK(IsRunning()); 50 DCHECK(IsRunning());
50 task = base::Bind(&GeolocationProvider::StopProviders, 51 task = base::Bind(&GeolocationProvider::StopProviders,
51 base::Unretained(this)); 52 base::Unretained(this));
52 } else { 53 } else {
53 if (!IsRunning()) { 54 if (!IsRunning()) {
54 Start(); 55 Start();
55 if (HasPermissionBeenGranted()) 56 if (HasPermissionBeenGranted())
56 InformProvidersPermissionGranted(most_recent_authorized_frame_); 57 InformProvidersPermissionGranted();
57 } 58 }
58 59
59 // The high accuracy requirement may have changed. 60 // The high accuracy requirement may have changed.
60 task = base::Bind(&GeolocationProvider::StartProviders, 61 task = base::Bind(&GeolocationProvider::StartProviders,
61 base::Unretained(this), 62 base::Unretained(this),
62 GeolocationObserverOptions::Collapse(observers_)); 63 GeolocationObserverOptions::Collapse(observers_));
63 } 64 }
64 65
65 message_loop()->PostTask(FROM_HERE, task); 66 message_loop()->PostTask(FROM_HERE, task);
66 } 67 }
(...skipping 17 matching lines...) Expand all
84 DCHECK(arbitrator_); 85 DCHECK(arbitrator_);
85 arbitrator_->StartProviders(options); 86 arbitrator_->StartProviders(options);
86 } 87 }
87 88
88 void GeolocationProvider::StopProviders() { 89 void GeolocationProvider::StopProviders() {
89 DCHECK(OnGeolocationThread()); 90 DCHECK(OnGeolocationThread());
90 DCHECK(arbitrator_); 91 DCHECK(arbitrator_);
91 arbitrator_->StopProviders(); 92 arbitrator_->StopProviders();
92 } 93 }
93 94
94 void GeolocationProvider::OnPermissionGranted(const GURL& requesting_frame) { 95 void GeolocationProvider::OnPermissionGranted() {
95 DCHECK(OnClientThread()); 96 DCHECK(OnClientThread());
96 most_recent_authorized_frame_ = requesting_frame; 97 is_permission_granted_ = true;
97 if (IsRunning()) 98 if (IsRunning())
98 InformProvidersPermissionGranted(requesting_frame); 99 InformProvidersPermissionGranted();
99 } 100 }
100 101
101 void GeolocationProvider::InformProvidersPermissionGranted( 102 void GeolocationProvider::InformProvidersPermissionGranted() {
102 const GURL& requesting_frame) {
103 DCHECK(IsRunning()); 103 DCHECK(IsRunning());
104 DCHECK(requesting_frame.is_valid());
105 if (!OnGeolocationThread()) { 104 if (!OnGeolocationThread()) {
106 message_loop()->PostTask( 105 message_loop()->PostTask(
107 FROM_HERE, 106 FROM_HERE,
108 base::Bind(&GeolocationProvider::InformProvidersPermissionGranted, 107 base::Bind(&GeolocationProvider::InformProvidersPermissionGranted,
109 base::Unretained(this), requesting_frame)); 108 base::Unretained(this)));
110 return; 109 return;
111 } 110 }
112 DCHECK(OnGeolocationThread()); 111 DCHECK(OnGeolocationThread());
113 DCHECK(arbitrator_); 112 DCHECK(arbitrator_);
114 arbitrator_->OnPermissionGranted(requesting_frame); 113 arbitrator_->OnPermissionGranted();
115 } 114 }
116 115
117 void GeolocationProvider::Init() { 116 void GeolocationProvider::Init() {
118 DCHECK(OnGeolocationThread()); 117 DCHECK(OnGeolocationThread());
119 DCHECK(!arbitrator_); 118 DCHECK(!arbitrator_);
120 arbitrator_ = GeolocationArbitrator::Create(this); 119 arbitrator_ = GeolocationArbitrator::Create(this);
121 } 120 }
122 121
123 void GeolocationProvider::CleanUp() { 122 void GeolocationProvider::CleanUp() {
124 DCHECK(OnGeolocationThread()); 123 DCHECK(OnGeolocationThread());
125 delete arbitrator_; 124 delete arbitrator_;
126 arbitrator_ = NULL; 125 arbitrator_ = NULL;
127 } 126 }
128 127
129 void GeolocationProvider::OnLocationUpdate(const Geoposition& position) { 128 void GeolocationProvider::OnLocationUpdate(const Geoposition& position) {
130 DCHECK(OnGeolocationThread()); 129 DCHECK(OnGeolocationThread());
131 client_loop_->PostTask( 130 client_loop_->PostTask(
132 FROM_HERE, 131 FROM_HERE,
133 base::Bind(&GeolocationProvider::NotifyObservers, 132 base::Bind(&GeolocationProvider::NotifyObservers,
134 base::Unretained(this), position)); 133 base::Unretained(this), position));
135 } 134 }
136 135
137 bool GeolocationProvider::HasPermissionBeenGranted() const { 136 bool GeolocationProvider::HasPermissionBeenGranted() const {
138 DCHECK(OnClientThread()); 137 DCHECK(OnClientThread());
139 return most_recent_authorized_frame_.is_valid(); 138 return is_permission_granted_;
140 } 139 }
141 140
142 bool GeolocationProvider::OnClientThread() const { 141 bool GeolocationProvider::OnClientThread() const {
143 return client_loop_->BelongsToCurrentThread(); 142 return client_loop_->BelongsToCurrentThread();
144 } 143 }
145 144
146 bool GeolocationProvider::OnGeolocationThread() const { 145 bool GeolocationProvider::OnGeolocationThread() const {
147 return MessageLoop::current() == message_loop(); 146 return MessageLoop::current() == message_loop();
148 } 147 }
OLDNEW
« no previous file with comments | « content/browser/geolocation/geolocation_provider.h ('k') | content/browser/geolocation/geolocation_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698