allow GOOGLE_API_KEY to be set in environment
This commit is contained in:
parent
dee383db07
commit
fa2aaa48b1
3 changed files with 11 additions and 8 deletions
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "atom/browser/atom_browser_context.h"
|
#include "atom/browser/atom_browser_context.h"
|
||||||
#include "atom/common/google_api_key.h"
|
#include "atom/common/google_api_key.h"
|
||||||
|
#include "base/environment.h"
|
||||||
#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"
|
||||||
|
|
||||||
|
@ -17,13 +18,6 @@ namespace atom {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Notice that we just combined the api key with the url together here, because
|
|
||||||
// if we use the standard {url: key} format Chromium would override our key with
|
|
||||||
// the predefined one in common.gypi of libchromiumcontent, which is empty.
|
|
||||||
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
|
// Loads access tokens and other necessary data on the UI thread, and
|
||||||
// calls back to the originator on the originating thread.
|
// calls back to the originator on the originating thread.
|
||||||
class TokenLoadingJob : public base::RefCountedThreadSafe<TokenLoadingJob> {
|
class TokenLoadingJob : public base::RefCountedThreadSafe<TokenLoadingJob> {
|
||||||
|
@ -57,7 +51,7 @@ class TokenLoadingJob : public base::RefCountedThreadSafe<TokenLoadingJob> {
|
||||||
// of std::map on Linux, this can work around it.
|
// of std::map on Linux, this can work around it.
|
||||||
content::AccessTokenStore::AccessTokenMap access_token_map;
|
content::AccessTokenStore::AccessTokenMap access_token_map;
|
||||||
std::pair<GURL, base::string16> token_pair;
|
std::pair<GURL, base::string16> token_pair;
|
||||||
token_pair.first = GURL(kGeolocationProviderURL);
|
token_pair.first = GURL(GOOGLEAPIS_ENDPOINT + api_key_);
|
||||||
access_token_map.insert(token_pair);
|
access_token_map.insert(token_pair);
|
||||||
|
|
||||||
callback_.Run(access_token_map, request_context_getter_);
|
callback_.Run(access_token_map, request_context_getter_);
|
||||||
|
@ -71,6 +65,9 @@ class TokenLoadingJob : public base::RefCountedThreadSafe<TokenLoadingJob> {
|
||||||
|
|
||||||
AtomAccessTokenStore::AtomAccessTokenStore() {
|
AtomAccessTokenStore::AtomAccessTokenStore() {
|
||||||
content::GeolocationProvider::GetInstance()->UserDidOptIntoLocationServices();
|
content::GeolocationProvider::GetInstance()->UserDidOptIntoLocationServices();
|
||||||
|
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
||||||
|
if (!env->GetVar("GOOGLE_API_KEY", &api_key_))
|
||||||
|
api_key_ = GOOGLEAPIS_API_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
AtomAccessTokenStore::~AtomAccessTokenStore() {
|
AtomAccessTokenStore::~AtomAccessTokenStore() {
|
||||||
|
|
|
@ -21,6 +21,7 @@ class AtomAccessTokenStore : public content::AccessTokenStore {
|
||||||
const base::string16& access_token) override;
|
const base::string16& access_token) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::string api_key_;
|
||||||
DISALLOW_COPY_AND_ASSIGN(AtomAccessTokenStore);
|
DISALLOW_COPY_AND_ASSIGN(AtomAccessTokenStore);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,11 @@
|
||||||
#ifndef ATOM_COMMON_GOOGLE_API_KEY_H_
|
#ifndef ATOM_COMMON_GOOGLE_API_KEY_H_
|
||||||
#define ATOM_COMMON_GOOGLE_API_KEY_H_
|
#define ATOM_COMMON_GOOGLE_API_KEY_H_
|
||||||
|
|
||||||
|
#ifndef GOOGLEAPIS_ENDPOINT
|
||||||
|
#define GOOGLEAPIS_ENDPOINT \
|
||||||
|
"https://www.googleapis.com/geolocation/v1/geolocate?key="
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef GOOGLEAPIS_API_KEY
|
#ifndef GOOGLEAPIS_API_KEY
|
||||||
#define GOOGLEAPIS_API_KEY "AIzaSyAQfxPJiounkhOjODEO5ZieffeBv6yft2Q"
|
#define GOOGLEAPIS_API_KEY "AIzaSyAQfxPJiounkhOjODEO5ZieffeBv6yft2Q"
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue