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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/geolocation/geolocation_provider_impl.cc
diff --git a/content/browser/geolocation/geolocation_provider_impl.cc b/content/browser/geolocation/geolocation_provider_impl.cc
index 2343fa7d816464d9c637db2ed8a709e229f73283..4a35358e948df93e0522b316c6bd96b4c7acaad8 100644
--- a/content/browser/geolocation/geolocation_provider_impl.cc
+++ b/content/browser/geolocation/geolocation_provider_impl.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
+#include "base/lazy_instance.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
@@ -19,10 +20,23 @@
namespace content {
+namespace {
+base::LazyInstance<std::unique_ptr<GeolocationDelegate>>::Leaky g_delegate =
+ LAZY_INSTANCE_INITIALIZER;
Wez 2016/07/25 22:25:35 Why do we need a LazyInstance here, rather than a
mcasas 2016/07/26 18:46:34 Essentially, because I wanted the |g_delegate| to
Wez 2016/07/26 19:08:31 If you want it cleaned up on shutdown then you eit
+} // anonymous namespace
+
+// static
GeolocationProvider* GeolocationProvider::GetInstance() {
return GeolocationProviderImpl::GetInstance();
}
+// static
+void GeolocationProvider::SetGeolocationDelegate(
+ GeolocationDelegate* delegate) {
+ if (!g_delegate.Pointer())
Ken Rockot(use gerrit already) 2016/07/20 17:47:52 g_delegate.Pointer() is always true. It's the addr
mcasas 2016/07/20 20:47:08 Done.
+ g_delegate.Pointer()->reset(delegate);
Ken Rockot(use gerrit already) 2016/07/20 17:47:52 optional nit: I think the above is evidence that u
mcasas 2016/07/20 20:47:08 Done.
+}
+
std::unique_ptr<GeolocationProvider::Subscription>
GeolocationProviderImpl::AddLocationUpdateCallback(
const LocationUpdateCallback& callback,
@@ -70,6 +84,7 @@ void GeolocationProviderImpl::OnLocationUpdate(const Geoposition& position) {
base::Unretained(this), position));
}
+// static
GeolocationProviderImpl* GeolocationProviderImpl::GetInstance() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
return base::Singleton<GeolocationProviderImpl>::get();
@@ -176,14 +191,12 @@ std::unique_ptr<LocationArbitrator>
GeolocationProviderImpl::CreateArbitrator() {
LocationArbitratorImpl::LocationUpdateCallback callback = base::Bind(
&GeolocationProviderImpl::OnLocationUpdate, base::Unretained(this));
-
- // Use the embedder's Delegate or fall back to the default one.
- delegate_.reset(GetContentClient()->browser()->CreateGeolocationDelegate());
- if (!delegate_)
- delegate_.reset(new GeolocationDelegate);
+ // Use the embedder's |g_delegate| or fall back to the default one.
+ if (!g_delegate.Get())
+ g_delegate.Pointer()->reset(new GeolocationDelegate);
return base::WrapUnique(
- new LocationArbitratorImpl(callback, delegate_.get()));
+ new LocationArbitratorImpl(callback, g_delegate.Pointer()->get()));
}
} // namespace content
« 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