Skip to content

Commit

Permalink
Merge pull request #7154 from deepak1556/chrome53_geo_crash_patch
Browse files Browse the repository at this point in the history
fix crash when using geolocation api with enableHighAccuracy option
  • Loading branch information
zcbenz authored Sep 12, 2016
2 parents 652563e + 8872900 commit c03feaf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 30 deletions.
72 changes: 47 additions & 25 deletions atom/browser/atom_access_token_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/geolocation_provider.h"

using content::BrowserThread;

namespace atom {

namespace {
Expand All @@ -22,6 +24,49 @@ const char* kGeolocationProviderURL =
"https://www.googleapis.com/geolocation/v1/geolocate?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

AtomAccessTokenStore::AtomAccessTokenStore() {
Expand All @@ -33,35 +78,12 @@ AtomAccessTokenStore::~AtomAccessTokenStore() {

void AtomAccessTokenStore::LoadAccessTokens(
const LoadAccessTokensCallback& callback) {
content::BrowserThread::PostTaskAndReply(
content::BrowserThread::UI,
FROM_HERE,
base::Bind(&AtomAccessTokenStore::GetRequestContextOnUIThread, this),
base::Bind(&AtomAccessTokenStore::RespondOnOriginatingThread,
this, callback));
scoped_refptr<TokenLoadingJob> job(new TokenLoadingJob(callback));
job->Run();
}

void AtomAccessTokenStore::SaveAccessToken(const GURL& server_url,
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
5 changes: 0 additions & 5 deletions atom/browser/atom_access_token_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ class AtomAccessTokenStore : public content::AccessTokenStore {
const base::string16& access_token) override;

private:
void GetRequestContextOnUIThread();
void RespondOnOriginatingThread(const LoadAccessTokensCallback& callback);

scoped_refptr<net::URLRequestContextGetter> request_context_getter_;

DISALLOW_COPY_AND_ASSIGN(AtomAccessTokenStore);
};

Expand Down

0 comments on commit c03feaf

Please sign in to comment.