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

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: 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 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..1f263976a914460ccb26e73750177388c0b7f05e 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;
+} // anonymous namespace
+
+// static
GeolocationProvider* GeolocationProvider::GetInstance() {
return GeolocationProviderImpl::GetInstance();
}
+// static
+void GeolocationProvider::SetGeolocationDelegate(
+ GeolocationDelegate* delegate) {
+ DCHECK(!g_delegate.Get());
+ g_delegate.Get().reset(delegate);
+}
+
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.Get().reset(new GeolocationDelegate);
return base::WrapUnique(
- new LocationArbitratorImpl(callback, delegate_.get()));
+ new LocationArbitratorImpl(callback, g_delegate.Get().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