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

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

Issue 2127973002: Geolocation: change GeolocationDelegate to injected by content/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: simplified shell_content_browser_client.cc Created 4 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 "content/browser/geolocation/geolocation_provider_impl.h" 5 #include "content/browser/geolocation/geolocation_provider_impl.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/callback.h" 9 #include "base/callback.h"
10 #include "base/lazy_instance.h"
10 #include "base/location.h" 11 #include "base/location.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
13 #include "base/memory/singleton.h" 14 #include "base/memory/singleton.h"
14 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
15 #include "content/browser/geolocation/location_arbitrator_impl.h" 16 #include "content/browser/geolocation/location_arbitrator_impl.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/content_browser_client.h" 18 #include "content/public/browser/content_browser_client.h"
18 #include "content/public/browser/geolocation_delegate.h" 19 #include "content/public/browser/geolocation_delegate.h"
19 20
20 namespace content { 21 namespace content {
21 22
23 namespace {
24 base::LazyInstance<std::unique_ptr<GeolocationDelegate>>::Leaky g_delegate =
25 LAZY_INSTANCE_INITIALIZER;
26 } // anonymous namespace
27
28 // static
22 GeolocationProvider* GeolocationProvider::GetInstance() { 29 GeolocationProvider* GeolocationProvider::GetInstance() {
23 return GeolocationProviderImpl::GetInstance(); 30 return GeolocationProviderImpl::GetInstance();
24 } 31 }
25 32
33 // static
34 void GeolocationProvider::SetGeolocationDelegate(
35 GeolocationDelegate* delegate) {
36 DCHECK(!g_delegate.Get());
37 g_delegate.Get().reset(delegate);
38 }
39
26 std::unique_ptr<GeolocationProvider::Subscription> 40 std::unique_ptr<GeolocationProvider::Subscription>
27 GeolocationProviderImpl::AddLocationUpdateCallback( 41 GeolocationProviderImpl::AddLocationUpdateCallback(
28 const LocationUpdateCallback& callback, 42 const LocationUpdateCallback& callback,
29 bool enable_high_accuracy) { 43 bool enable_high_accuracy) {
30 DCHECK_CURRENTLY_ON(BrowserThread::UI); 44 DCHECK_CURRENTLY_ON(BrowserThread::UI);
31 std::unique_ptr<GeolocationProvider::Subscription> subscription; 45 std::unique_ptr<GeolocationProvider::Subscription> subscription;
32 if (enable_high_accuracy) { 46 if (enable_high_accuracy) {
33 subscription = high_accuracy_callbacks_.Add(callback); 47 subscription = high_accuracy_callbacks_.Add(callback);
34 } else { 48 } else {
35 subscription = low_accuracy_callbacks_.Add(callback); 49 subscription = low_accuracy_callbacks_.Add(callback);
(...skipping 27 matching lines...) Expand all
63 DCHECK(OnGeolocationThread()); 77 DCHECK(OnGeolocationThread());
64 // Will be true only in testing. 78 // Will be true only in testing.
65 if (ignore_location_updates_) 79 if (ignore_location_updates_)
66 return; 80 return;
67 BrowserThread::PostTask(BrowserThread::UI, 81 BrowserThread::PostTask(BrowserThread::UI,
68 FROM_HERE, 82 FROM_HERE,
69 base::Bind(&GeolocationProviderImpl::NotifyClients, 83 base::Bind(&GeolocationProviderImpl::NotifyClients,
70 base::Unretained(this), position)); 84 base::Unretained(this), position));
71 } 85 }
72 86
87 // static
73 GeolocationProviderImpl* GeolocationProviderImpl::GetInstance() { 88 GeolocationProviderImpl* GeolocationProviderImpl::GetInstance() {
74 DCHECK_CURRENTLY_ON(BrowserThread::UI); 89 DCHECK_CURRENTLY_ON(BrowserThread::UI);
75 return base::Singleton<GeolocationProviderImpl>::get(); 90 return base::Singleton<GeolocationProviderImpl>::get();
76 } 91 }
77 92
78 GeolocationProviderImpl::GeolocationProviderImpl() 93 GeolocationProviderImpl::GeolocationProviderImpl()
79 : base::Thread("Geolocation"), 94 : base::Thread("Geolocation"),
80 user_did_opt_into_location_services_(false), 95 user_did_opt_into_location_services_(false),
81 ignore_location_updates_(false) { 96 ignore_location_updates_(false) {
82 DCHECK_CURRENTLY_ON(BrowserThread::UI); 97 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 184
170 void GeolocationProviderImpl::CleanUp() { 185 void GeolocationProviderImpl::CleanUp() {
171 DCHECK(OnGeolocationThread()); 186 DCHECK(OnGeolocationThread());
172 arbitrator_.reset(); 187 arbitrator_.reset();
173 } 188 }
174 189
175 std::unique_ptr<LocationArbitrator> 190 std::unique_ptr<LocationArbitrator>
176 GeolocationProviderImpl::CreateArbitrator() { 191 GeolocationProviderImpl::CreateArbitrator() {
177 LocationArbitratorImpl::LocationUpdateCallback callback = base::Bind( 192 LocationArbitratorImpl::LocationUpdateCallback callback = base::Bind(
178 &GeolocationProviderImpl::OnLocationUpdate, base::Unretained(this)); 193 &GeolocationProviderImpl::OnLocationUpdate, base::Unretained(this));
179 194 // Use the embedder's |g_delegate| or fall back to the default one.
180 // Use the embedder's Delegate or fall back to the default one. 195 if (!g_delegate.Get())
181 delegate_.reset(GetContentClient()->browser()->CreateGeolocationDelegate()); 196 g_delegate.Get().reset(new GeolocationDelegate);
182 if (!delegate_)
183 delegate_.reset(new GeolocationDelegate);
184 197
185 return base::WrapUnique( 198 return base::WrapUnique(
186 new LocationArbitratorImpl(callback, delegate_.get())); 199 new LocationArbitratorImpl(callback, g_delegate.Get().get()));
187 } 200 }
188 201
189 } // namespace content 202 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/geolocation/geolocation_provider_impl.h ('k') | content/public/browser/geolocation_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698