2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-08-13 04:12:43 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "atom/browser/atom_access_token_store.h"
|
|
|
|
|
2014-08-13 06:43:21 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2014-08-13 04:12:43 +00:00
|
|
|
#include "atom/browser/atom_browser_context.h"
|
2014-10-08 10:27:39 +00:00
|
|
|
#include "atom/common/google_api_key.h"
|
2016-06-22 06:41:56 +00:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2015-08-27 14:50:40 +00:00
|
|
|
#include "content/public/browser/geolocation_provider.h"
|
2014-08-13 05:28:05 +00:00
|
|
|
|
2014-08-13 04:12:43 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2014-08-13 05:28:05 +00:00
|
|
|
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.
|
2015-11-13 08:03:40 +00:00
|
|
|
const char* kGeolocationProviderURL =
|
2014-08-13 05:28:05 +00:00
|
|
|
"https://www.googleapis.com/geolocation/v1/geolocate?key="
|
|
|
|
GOOGLEAPIS_API_KEY;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2014-08-13 04:12:43 +00:00
|
|
|
AtomAccessTokenStore::AtomAccessTokenStore() {
|
2015-08-27 14:50:40 +00:00
|
|
|
content::GeolocationProvider::GetInstance()->UserDidOptIntoLocationServices();
|
2014-08-13 04:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AtomAccessTokenStore::~AtomAccessTokenStore() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void AtomAccessTokenStore::LoadAccessTokens(
|
2016-04-27 17:59:46 +00:00
|
|
|
const LoadAccessTokensCallback& callback) {
|
2016-06-22 06:41:56 +00:00
|
|
|
content::BrowserThread::PostTaskAndReply(
|
|
|
|
content::BrowserThread::UI,
|
|
|
|
FROM_HERE,
|
|
|
|
base::Bind(&AtomAccessTokenStore::GetRequestContextOnUIThread, this),
|
|
|
|
base::Bind(&AtomAccessTokenStore::RespondOnOriginatingThread,
|
|
|
|
this, callback));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AtomAccessTokenStore::SaveAccessToken(const GURL& server_url,
|
|
|
|
const base::string16& access_token) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void AtomAccessTokenStore::GetRequestContextOnUIThread() {
|
|
|
|
auto browser_context = brightray::BrowserContext::From("", false);
|
|
|
|
request_context_getter_ = browser_context->GetRequestContext();
|
|
|
|
}
|
2014-08-13 06:43:21 +00:00
|
|
|
|
2016-06-22 06:41:56 +00:00
|
|
|
void AtomAccessTokenStore::RespondOnOriginatingThread(
|
|
|
|
const LoadAccessTokensCallback& callback) {
|
2016-04-27 18:35:21 +00:00
|
|
|
// Equivelent to access_token_map[kGeolocationProviderURL].
|
2014-08-13 06:43:21 +00:00
|
|
|
// Somehow base::string16 is causing compilation errors when used in a pair
|
|
|
|
// of std::map on Linux, this can work around it.
|
2016-06-22 06:41:56 +00:00
|
|
|
AccessTokenMap access_token_map;
|
2014-08-13 06:43:21 +00:00
|
|
|
std::pair<GURL, base::string16> token_pair;
|
2015-11-13 08:03:40 +00:00
|
|
|
token_pair.first = GURL(kGeolocationProviderURL);
|
2016-04-27 18:35:21 +00:00
|
|
|
access_token_map.insert(token_pair);
|
2014-08-13 06:43:21 +00:00
|
|
|
|
2016-06-22 06:41:56 +00:00
|
|
|
callback.Run(access_token_map, request_context_getter_.get());
|
|
|
|
request_context_getter_ = nullptr;
|
2014-08-13 04:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace atom
|