Commit ce4c522e authored by Andrew Moylan's avatar Andrew Moylan Committed by Commit Bot

Remove shell & webview AccessTokenStores

Content shell and Android webview don't make network geolocation
requests. Previously these embedders had dummy (no-op) implementations
of AccessTokenStore. This CL removes the dummy implementations and
instead uses the existing UseNetworkLocationProviders flag in
GeolocationDelegate as a gate.

This is part of the removal of all AccessTokenStores. Overall design:
https://docs.google.com/document/d/1A-ZYMadJkwdQad_pC3MbpuCVNOOnRP_UZjGnXl-FOqE

Details of reasoning why this is safe:

Content shell:
AccessTokenStore was being created but LoadAccessTokens was not being
called on it (after crrev.com/c/641175).

Android webview:
AccessTokenStore was being created and LoadAccessTokens was being called
on it, but to no consequence due to an "#if defined(OS_ANDROID)" block at
location_arbitrator.cc:174.

Bug: 748921
Change-Id: I10ed3668ee015f855acf604e445643617bbe7713
Reviewed-on: https://chromium-review.googlesource.com/658010
Commit-Queue: Andrew Moylan <amoylan@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarSelim Gurun <sgurun@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501494}
parent fa312b77
...@@ -48,33 +48,18 @@ ...@@ -48,33 +48,18 @@
namespace android_webview { namespace android_webview {
namespace { namespace {
class AwAccessTokenStore : public device::AccessTokenStore {
public:
AwAccessTokenStore() { }
// device::AccessTokenStore implementation
void LoadAccessTokens(const LoadAccessTokensCallback& request) override {
AccessTokenStore::AccessTokenMap access_token_map;
// AccessTokenMap and net::URLRequestContextGetter not used on Android,
// but Run needs to be called to finish the geolocation setup.
request.Run(access_token_map, NULL);
}
void SaveAccessToken(const GURL& server_url,
const base::string16& access_token) override {}
private:
~AwAccessTokenStore() override {}
DISALLOW_COPY_AND_ASSIGN(AwAccessTokenStore);
};
// A provider of Geolocation services to override AccessTokenStore. // A provider of Geolocation services to override AccessTokenStore.
class AwGeolocationDelegate : public device::GeolocationDelegate { class AwGeolocationDelegate : public device::GeolocationDelegate {
public: public:
AwGeolocationDelegate() = default; AwGeolocationDelegate() = default;
// Android doesn't use NetworkLocationProvider (the capability is folded into
// the system location provider).
bool UseNetworkLocationProviders() override { return false; }
scoped_refptr<device::AccessTokenStore> CreateAccessTokenStore() final { scoped_refptr<device::AccessTokenStore> CreateAccessTokenStore() final {
return new AwAccessTokenStore(); NOTREACHED() << "No network geolocation for Android webview";
return nullptr;
} }
private: private:
......
...@@ -102,8 +102,6 @@ static_library("content_shell_lib") { ...@@ -102,8 +102,6 @@ static_library("content_shell_lib") {
"browser/renderer_host/shell_render_widget_host_view_mac_delegate.mm", "browser/renderer_host/shell_render_widget_host_view_mac_delegate.mm",
"browser/shell.cc", "browser/shell.cc",
"browser/shell.h", "browser/shell.h",
"browser/shell_access_token_store.cc",
"browser/shell_access_token_store.h",
"browser/shell_android.cc", "browser/shell_android.cc",
"browser/shell_application_mac.h", "browser/shell_application_mac.h",
"browser/shell_application_mac.mm", "browser/shell_application_mac.mm",
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/shell/browser/shell_access_token_store.h"
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "content/shell/browser/shell_browser_context.h"
namespace content {
ShellAccessTokenStore::ShellAccessTokenStore(
content::ShellBrowserContext* shell_browser_context)
: shell_browser_context_(shell_browser_context),
system_request_context_(NULL) {
}
ShellAccessTokenStore::~ShellAccessTokenStore() {
}
void ShellAccessTokenStore::LoadAccessTokens(
const LoadAccessTokensCallback& callback) {
BrowserThread::PostTaskAndReply(
BrowserThread::UI, FROM_HERE,
base::BindOnce(&ShellAccessTokenStore::GetRequestContextOnUIThread, this,
shell_browser_context_),
base::BindOnce(&ShellAccessTokenStore::RespondOnOriginatingThread, this,
callback));
}
void ShellAccessTokenStore::GetRequestContextOnUIThread(
content::ShellBrowserContext* shell_browser_context) {
system_request_context_ =
BrowserContext::GetDefaultStoragePartition(shell_browser_context)->
GetURLRequestContext();
}
void ShellAccessTokenStore::RespondOnOriginatingThread(
const LoadAccessTokensCallback& callback) {
callback.Run(AccessTokenMap(), system_request_context_);
system_request_context_ = NULL;
}
void ShellAccessTokenStore::SaveAccessToken(
const GURL& server_url, const base::string16& access_token) {
}
} // namespace content
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_SHELL_BROWSER_SHELL_ACCESS_TOKEN_STORE_H_
#define CONTENT_SHELL_BROWSER_SHELL_ACCESS_TOKEN_STORE_H_
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "device/geolocation/access_token_store.h"
#include "net/url_request/url_request_context_getter.h"
namespace content {
class ShellBrowserContext;
// Dummy access token store used to initialise the network location provider.
class ShellAccessTokenStore : public device::AccessTokenStore {
public:
explicit ShellAccessTokenStore(
content::ShellBrowserContext* shell_browser_context);
private:
~ShellAccessTokenStore() override;
void GetRequestContextOnUIThread(
content::ShellBrowserContext* shell_browser_context);
void RespondOnOriginatingThread(const LoadAccessTokensCallback& callback);
// AccessTokenStore
void LoadAccessTokens(const LoadAccessTokensCallback& callback) override;
void SaveAccessToken(const GURL& server_url,
const base::string16& access_token) override;
content::ShellBrowserContext* shell_browser_context_;
scoped_refptr<net::URLRequestContextGetter> system_request_context_;
DISALLOW_COPY_AND_ASSIGN(ShellAccessTokenStore);
};
} // namespace content
#endif // CONTENT_SHELL_BROWSER_SHELL_ACCESS_TOKEN_STORE_H_
...@@ -20,12 +20,12 @@ ...@@ -20,12 +20,12 @@
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "content/shell/android/shell_descriptors.h" #include "content/shell/android/shell_descriptors.h"
#include "content/shell/browser/shell.h" #include "content/shell/browser/shell.h"
#include "content/shell/browser/shell_access_token_store.h"
#include "content/shell/browser/shell_browser_context.h" #include "content/shell/browser/shell_browser_context.h"
#include "content/shell/browser/shell_devtools_manager_delegate.h" #include "content/shell/browser/shell_devtools_manager_delegate.h"
#include "content/shell/browser/shell_net_log.h" #include "content/shell/browser/shell_net_log.h"
#include "content/shell/common/shell_switches.h" #include "content/shell/common/shell_switches.h"
#include "device/bluetooth/bluetooth_adapter_factory.h" #include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/geolocation/access_token_store.h"
#include "device/geolocation/geolocation_delegate.h" #include "device/geolocation/geolocation_delegate.h"
#include "device/geolocation/geolocation_provider.h" #include "device/geolocation/geolocation_provider.h"
#include "net/base/filename_util.h" #include "net/base/filename_util.h"
...@@ -66,19 +66,18 @@ namespace { ...@@ -66,19 +66,18 @@ namespace {
// A provider of services for Geolocation. // A provider of services for Geolocation.
class ShellGeolocationDelegate : public device::GeolocationDelegate { class ShellGeolocationDelegate : public device::GeolocationDelegate {
public: public:
explicit ShellGeolocationDelegate(ShellBrowserContext* context) ShellGeolocationDelegate() = default;
: context_(context) {}
// Since content shell is a test executable, rather than an end-user program, // Since content shell is a test executable, rather than an end-user program,
// don't make calls to the network geolocation API. // don't make calls to the network geolocation API.
bool UseNetworkLocationProviders() override { return false; } bool UseNetworkLocationProviders() override { return false; }
scoped_refptr<device::AccessTokenStore> CreateAccessTokenStore() final { scoped_refptr<device::AccessTokenStore> CreateAccessTokenStore() final {
return new ShellAccessTokenStore(context_); NOTREACHED() << "No network geolocation for content shell";
return nullptr;
} }
private: private:
ShellBrowserContext* context_;
DISALLOW_COPY_AND_ASSIGN(ShellGeolocationDelegate); DISALLOW_COPY_AND_ASSIGN(ShellGeolocationDelegate);
}; };
...@@ -196,7 +195,7 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() { ...@@ -196,7 +195,7 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
net_log_.reset(new ShellNetLog("content_shell")); net_log_.reset(new ShellNetLog("content_shell"));
InitializeBrowserContexts(); InitializeBrowserContexts();
device::GeolocationProvider::SetGeolocationDelegate( device::GeolocationProvider::SetGeolocationDelegate(
new ShellGeolocationDelegate(browser_context())); new ShellGeolocationDelegate());
Shell::Initialize(); Shell::Initialize();
net::NetModule::SetResourceProvider(PlatformResourceProvider); net::NetModule::SetResourceProvider(PlatformResourceProvider);
ShellDevToolsManagerDelegate::StartHttpHandler(browser_context_.get()); ShellDevToolsManagerDelegate::StartHttpHandler(browser_context_.get());
......
...@@ -25,6 +25,7 @@ class DEVICE_GEOLOCATION_EXPORT GeolocationDelegate { ...@@ -25,6 +25,7 @@ class DEVICE_GEOLOCATION_EXPORT GeolocationDelegate {
virtual bool UseNetworkLocationProviders(); virtual bool UseNetworkLocationProviders();
// Creates a new AccessTokenStore for geolocation. May return nullptr. // Creates a new AccessTokenStore for geolocation. May return nullptr.
// Won't be called unless UseNetworkLocationProviders() is true.
virtual scoped_refptr<AccessTokenStore> CreateAccessTokenStore(); virtual scoped_refptr<AccessTokenStore> CreateAccessTokenStore();
// Allows an embedder to return its own LocationProvider implementation. // Allows an embedder to return its own LocationProvider implementation.
......
...@@ -60,15 +60,17 @@ bool LocationArbitrator::StartProvider(bool enable_high_accuracy) { ...@@ -60,15 +60,17 @@ bool LocationArbitrator::StartProvider(bool enable_high_accuracy) {
if (providers_.empty()) { if (providers_.empty()) {
RegisterSystemProvider(); RegisterSystemProvider();
const scoped_refptr<AccessTokenStore> access_token_store = if (delegate_->UseNetworkLocationProviders()) {
GetAccessTokenStore(); const scoped_refptr<AccessTokenStore> access_token_store =
if (access_token_store && delegate_->UseNetworkLocationProviders()) { GetAccessTokenStore();
DCHECK(DefaultNetworkProviderURL().is_valid()); if (access_token_store) {
token_store_callback_.Reset( DCHECK(DefaultNetworkProviderURL().is_valid());
base::Bind(&LocationArbitrator::OnAccessTokenStoresLoaded, token_store_callback_.Reset(
base::Unretained(this))); base::Bind(&LocationArbitrator::OnAccessTokenStoresLoaded,
access_token_store->LoadAccessTokens(token_store_callback_.callback()); base::Unretained(this)));
return true; access_token_store->LoadAccessTokens(token_store_callback_.callback());
return true;
}
} }
} }
return DoStartProviders(); return DoStartProviders();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment