fix crash when using geolocation api with enableHighAccuracy option
This commit is contained in:
parent
fbac635687
commit
eafb6307d5
2 changed files with 47 additions and 30 deletions
|
@ -11,6 +11,8 @@
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "content/public/browser/geolocation_provider.h"
|
#include "content/public/browser/geolocation_provider.h"
|
||||||
|
|
||||||
|
using content::BrowserThread;
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -22,6 +24,49 @@ const char* kGeolocationProviderURL =
|
||||||
"https://www.googleapis.com/geolocation/v1/geolocate?key="
|
"https://www.googleapis.com/geolocation/v1/geolocate?key="
|
||||||
GOOGLEAPIS_API_KEY;
|
GOOGLEAPIS_API_KEY;
|
||||||
|
|
||||||
|
// Loads access tokens and other necessary data on the UI thread, and
|
||||||
|
// calls back to the originator on the originating thread.
|
||||||
|
class TokenLoadingJob : public base::RefCountedThreadSafe<TokenLoadingJob> {
|
||||||
|
public:
|
||||||
|
explicit TokenLoadingJob(
|
||||||
|
const content::AccessTokenStore::LoadAccessTokensCallback& callback)
|
||||||
|
: callback_(callback), request_context_getter_(nullptr) {}
|
||||||
|
|
||||||
|
void Run() {
|
||||||
|
BrowserThread::PostTaskAndReply(
|
||||||
|
BrowserThread::UI,
|
||||||
|
FROM_HERE,
|
||||||
|
base::Bind(&TokenLoadingJob::PerformWorkOnUIThread, this),
|
||||||
|
base::Bind(&TokenLoadingJob::RespondOnOriginatingThread, this));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class base::RefCountedThreadSafe<TokenLoadingJob>;
|
||||||
|
|
||||||
|
~TokenLoadingJob() {}
|
||||||
|
|
||||||
|
void PerformWorkOnUIThread() {
|
||||||
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
|
auto browser_context = AtomBrowserContext::From("", false);
|
||||||
|
request_context_getter_ = browser_context->GetRequestContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RespondOnOriginatingThread() {
|
||||||
|
// Equivelent to access_token_map[kGeolocationProviderURL].
|
||||||
|
// Somehow base::string16 is causing compilation errors when used in a pair
|
||||||
|
// of std::map on Linux, this can work around it.
|
||||||
|
content::AccessTokenStore::AccessTokenMap access_token_map;
|
||||||
|
std::pair<GURL, base::string16> token_pair;
|
||||||
|
token_pair.first = GURL(kGeolocationProviderURL);
|
||||||
|
access_token_map.insert(token_pair);
|
||||||
|
|
||||||
|
callback_.Run(access_token_map, request_context_getter_);
|
||||||
|
}
|
||||||
|
|
||||||
|
content::AccessTokenStore::LoadAccessTokensCallback callback_;
|
||||||
|
net::URLRequestContextGetter* request_context_getter_;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
AtomAccessTokenStore::AtomAccessTokenStore() {
|
AtomAccessTokenStore::AtomAccessTokenStore() {
|
||||||
|
@ -33,35 +78,12 @@ AtomAccessTokenStore::~AtomAccessTokenStore() {
|
||||||
|
|
||||||
void AtomAccessTokenStore::LoadAccessTokens(
|
void AtomAccessTokenStore::LoadAccessTokens(
|
||||||
const LoadAccessTokensCallback& callback) {
|
const LoadAccessTokensCallback& callback) {
|
||||||
content::BrowserThread::PostTaskAndReply(
|
scoped_refptr<TokenLoadingJob> job(new TokenLoadingJob(callback));
|
||||||
content::BrowserThread::UI,
|
job->Run();
|
||||||
FROM_HERE,
|
|
||||||
base::Bind(&AtomAccessTokenStore::GetRequestContextOnUIThread, this),
|
|
||||||
base::Bind(&AtomAccessTokenStore::RespondOnOriginatingThread,
|
|
||||||
this, callback));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomAccessTokenStore::SaveAccessToken(const GURL& server_url,
|
void AtomAccessTokenStore::SaveAccessToken(const GURL& server_url,
|
||||||
const base::string16& access_token) {
|
const base::string16& access_token) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomAccessTokenStore::GetRequestContextOnUIThread() {
|
|
||||||
auto browser_context = AtomBrowserContext::From("", false);
|
|
||||||
request_context_getter_ = browser_context->GetRequestContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AtomAccessTokenStore::RespondOnOriginatingThread(
|
|
||||||
const LoadAccessTokensCallback& callback) {
|
|
||||||
// Equivelent to access_token_map[kGeolocationProviderURL].
|
|
||||||
// Somehow base::string16 is causing compilation errors when used in a pair
|
|
||||||
// of std::map on Linux, this can work around it.
|
|
||||||
AccessTokenMap access_token_map;
|
|
||||||
std::pair<GURL, base::string16> token_pair;
|
|
||||||
token_pair.first = GURL(kGeolocationProviderURL);
|
|
||||||
access_token_map.insert(token_pair);
|
|
||||||
|
|
||||||
callback.Run(access_token_map, request_context_getter_.get());
|
|
||||||
request_context_getter_ = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -21,11 +21,6 @@ class AtomAccessTokenStore : public content::AccessTokenStore {
|
||||||
const base::string16& access_token) override;
|
const base::string16& access_token) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void GetRequestContextOnUIThread();
|
|
||||||
void RespondOnOriginatingThread(const LoadAccessTokensCallback& callback);
|
|
||||||
|
|
||||||
scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
|
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(AtomAccessTokenStore);
|
DISALLOW_COPY_AND_ASSIGN(AtomAccessTokenStore);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue