summaryrefslogtreecommitdiffstats
path: root/chrome/browser/geolocation
diff options
context:
space:
mode:
authorjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-21 13:41:19 +0000
committerjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-21 13:41:19 +0000
commit0e034f73c6fd468599212186fc69644ef205cf11 (patch)
tree3eb74070e373c86fccfef9ca2c7f76e84c3e95e5 /chrome/browser/geolocation
parent75f2ab93270b7e41f43c874b4df8d596fa1170e6 (diff)
downloadchromium_src-0e034f73c6fd468599212186fc69644ef205cf11.zip
chromium_src-0e034f73c6fd468599212186fc69644ef205cf11.tar.gz
chromium_src-0e034f73c6fd468599212186fc69644ef205cf11.tar.bz2
Switch to PostTaskAndReply for AccessTokenStore.
This removes the only usage of the CancelableRequest class in content/, and is in preparation for moving the class back to chrome/browser. The ability to cancel requests to the AccessTokenStore was never used in production, so the interface now changes to a simpler non-cancelable one, and the browsertest GeolocationAccessTokenStoreTest.CancelRequest which tested the functionality is removed. BUG=98716 Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=114992 Reverted (ThreadChecker DCHECK on debug bots): r114997 Review URL: http://codereview.chromium.org/8996006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115325 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/geolocation')
-rw-r--r--chrome/browser/geolocation/access_token_store_browsertest.cc57
-rw-r--r--chrome/browser/geolocation/chrome_access_token_store.cc100
-rw-r--r--chrome/browser/geolocation/chrome_access_token_store.h10
3 files changed, 74 insertions, 93 deletions
diff --git a/chrome/browser/geolocation/access_token_store_browsertest.cc b/chrome/browser/geolocation/access_token_store_browsertest.cc
index 22729d5..b9ede22 100644
--- a/chrome/browser/geolocation/access_token_store_browsertest.cc
+++ b/chrome/browser/geolocation/access_token_store_browsertest.cc
@@ -38,7 +38,6 @@ class GeolocationAccessTokenStoreTest
net::URLRequestContextGetter* context_getter);
scoped_refptr<AccessTokenStore> token_store_;
- CancelableRequestConsumer request_consumer_;
GURL ref_url_;
const string16* token_to_expect_;
const string16* token_to_set_;
@@ -46,12 +45,11 @@ class GeolocationAccessTokenStoreTest
void StartTestStepFromClientThread(
scoped_refptr<AccessTokenStore>* store,
- CancelableRequestConsumerBase* consumer,
const AccessTokenStore::LoadAccessTokensCallbackType& callback) {
ASSERT_TRUE(BrowserThread::CurrentlyOn(kExpectedClientThreadId));
if (*store == NULL)
(*store) = new ChromeAccessTokenStore();
- (*store)->LoadAccessTokens(consumer, callback);
+ (*store)->LoadAccessTokens(callback);
}
struct TokenLoadClientForTest {
@@ -61,43 +59,6 @@ struct TokenLoadClientForTest {
}
};
-void RunCancelTestInClientTread() {
- ASSERT_TRUE(BrowserThread::CurrentlyOn(kExpectedClientThreadId));
- scoped_refptr<AccessTokenStore> store(new ChromeAccessTokenStore());
- CancelableRequestConsumer consumer;
- TokenLoadClientForTest load_client;
-
- // Single request, canceled explicitly
- CancelableRequestProvider::Handle first_handle =
- store->LoadAccessTokens(
- &consumer,
- base::Bind(&TokenLoadClientForTest::NotReachedCallback,
- base::Unretained(&load_client)));
- EXPECT_TRUE(consumer.HasPendingRequests());
- // Test this handle is valid.
- consumer.GetClientData(store.get(), first_handle);
- store->CancelRequest(first_handle);
- EXPECT_FALSE(consumer.HasPendingRequests());
-
- // 2 requests, canceled globally.
- store->LoadAccessTokens(
- &consumer,
- base::Bind(&TokenLoadClientForTest::NotReachedCallback,
- base::Unretained(&load_client)));
- store->LoadAccessTokens(
- &consumer,
- base::Bind(&TokenLoadClientForTest::NotReachedCallback,
- base::Unretained(&load_client)));
- EXPECT_TRUE(consumer.HasPendingRequests());
- EXPECT_EQ(2u, consumer.PendingRequestCount());
- consumer.CancelAllRequests();
- EXPECT_FALSE(consumer.HasPendingRequests());
- EXPECT_EQ(0u, consumer.PendingRequestCount());
-
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure());
-}
-
void GeolocationAccessTokenStoreTest::DoTestStepAndWaitForResults(
const char* ref_url, const string16* token_to_expect,
const string16* token_to_set) {
@@ -107,10 +68,12 @@ void GeolocationAccessTokenStoreTest::DoTestStepAndWaitForResults(
BrowserThread::PostTask(
kExpectedClientThreadId, FROM_HERE,
- base::Bind(&StartTestStepFromClientThread, &token_store_,
- &request_consumer_,
- base::Bind(&GeolocationAccessTokenStoreTest::
- OnAccessTokenStoresLoaded, base::Unretained(this))));
+ base::Bind(
+ &StartTestStepFromClientThread,
+ &token_store_,
+ base::Bind(
+ &GeolocationAccessTokenStoreTest::OnAccessTokenStoresLoaded,
+ base::Unretained(this))));
ui_test_utils::RunMessageLoop();
}
@@ -169,10 +132,4 @@ IN_PROC_BROWSER_TEST_F(GeolocationAccessTokenStoreTest, OldUrlRemoval) {
NULL, NULL);
}
-IN_PROC_BROWSER_TEST_F(GeolocationAccessTokenStoreTest, CancelRequest) {
- BrowserThread::PostTask(kExpectedClientThreadId, FROM_HERE,
- base::Bind(&RunCancelTestInClientTread));
- ui_test_utils::RunMessageLoop();
-}
-
} // namespace
diff --git a/chrome/browser/geolocation/chrome_access_token_store.cc b/chrome/browser/geolocation/chrome_access_token_store.cc
index d0fcd39..fb0c281 100644
--- a/chrome/browser/geolocation/chrome_access_token_store.cc
+++ b/chrome/browser/geolocation/chrome_access_token_store.cc
@@ -18,9 +18,67 @@
using content::BrowserThread;
namespace {
+
// This was the default location service url for Chrome versions 14 and earlier
// but is no longer supported.
const char* kOldDefaultNetworkProviderUrl = "https://www.google.com/loc/json";
+
+// Loads access tokens and other necessary data on the UI thread, and
+// calls back to the originator on the originating threaad.
+class TokenLoadingJob : public base::RefCountedThreadSafe<TokenLoadingJob> {
+ public:
+ TokenLoadingJob(
+ const AccessTokenStore::LoadAccessTokensCallbackType& callback)
+ : callback_(callback) {
+ }
+
+ void Run() {
+ BrowserThread::PostTaskAndReply(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&TokenLoadingJob::PerformWorkOnUIThread, this),
+ base::Bind(&TokenLoadingJob::RespondOnOriginatingThread, this));
+ }
+
+ private:
+ void PerformWorkOnUIThread() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DictionaryPrefUpdate update(g_browser_process->local_state(),
+ prefs::kGeolocationAccessToken);
+ DictionaryValue* token_dictionary = update.Get();
+
+ bool has_old_network_provider_url = false;
+ // The dictionary value could be NULL if the pref has never been set.
+ if (token_dictionary != NULL) {
+ for (DictionaryValue::key_iterator it = token_dictionary->begin_keys();
+ it != token_dictionary->end_keys(); ++it) {
+ GURL url(*it);
+ if (!url.is_valid())
+ continue;
+ if (url.spec() == kOldDefaultNetworkProviderUrl) {
+ has_old_network_provider_url = true;
+ continue;
+ }
+ token_dictionary->GetStringWithoutPathExpansion(
+ *it, &access_token_set_[url]);
+ }
+ if (has_old_network_provider_url)
+ token_dictionary->RemoveWithoutPathExpansion(
+ kOldDefaultNetworkProviderUrl, NULL);
+ }
+
+ system_request_context_ = g_browser_process->system_request_context();
+ }
+
+ void RespondOnOriginatingThread() {
+ callback_.Run(access_token_set_, system_request_context_);
+ }
+
+ AccessTokenStore::LoadAccessTokensCallbackType callback_;
+ AccessTokenStore::AccessTokenSet access_token_set_;
+ net::URLRequestContextGetter* system_request_context_;
+};
+
} // namespace
void ChromeAccessTokenStore::RegisterPrefs(PrefService* prefs) {
@@ -30,45 +88,13 @@ void ChromeAccessTokenStore::RegisterPrefs(PrefService* prefs) {
ChromeAccessTokenStore::ChromeAccessTokenStore() {
}
-void ChromeAccessTokenStore::LoadDictionaryStoreInUIThread(
- scoped_refptr<CancelableRequest<LoadAccessTokensCallbackType> > request) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (request->canceled())
- return;
- DictionaryPrefUpdate update(g_browser_process->local_state(),
- prefs::kGeolocationAccessToken);
- DictionaryValue* token_dictionary = update.Get();
-
- AccessTokenStore::AccessTokenSet access_token_set;
- bool has_old_network_provider_url = false;
- // The dictionary value could be NULL if the pref has never been set.
- if (token_dictionary != NULL) {
- for (DictionaryValue::key_iterator it = token_dictionary->begin_keys();
- it != token_dictionary->end_keys(); ++it) {
- GURL url(*it);
- if (!url.is_valid())
- continue;
- if (url.spec() == kOldDefaultNetworkProviderUrl) {
- has_old_network_provider_url = true;
- continue;
- }
- token_dictionary->GetStringWithoutPathExpansion(*it,
- &access_token_set[url]);
- }
- if (has_old_network_provider_url)
- token_dictionary->RemoveWithoutPathExpansion(
- kOldDefaultNetworkProviderUrl, NULL);
- }
- request->ForwardResultAsync(access_token_set,
- g_browser_process->system_request_context());
+ChromeAccessTokenStore::~ChromeAccessTokenStore() {
}
-void ChromeAccessTokenStore::DoLoadAccessTokens(
- scoped_refptr<CancelableRequest<LoadAccessTokensCallbackType> > request) {
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&ChromeAccessTokenStore::LoadDictionaryStoreInUIThread, this,
- request));
+void ChromeAccessTokenStore::LoadAccessTokens(
+ const LoadAccessTokensCallbackType& callback) {
+ scoped_refptr<TokenLoadingJob> job(new TokenLoadingJob(callback));
+ job->Run();
}
void SetAccessTokenOnUIThread(const GURL& server_url, const string16& token) {
diff --git a/chrome/browser/geolocation/chrome_access_token_store.h b/chrome/browser/geolocation/chrome_access_token_store.h
index f61d3976..49c143e 100644
--- a/chrome/browser/geolocation/chrome_access_token_store.h
+++ b/chrome/browser/geolocation/chrome_access_token_store.h
@@ -17,15 +17,13 @@ class ChromeAccessTokenStore : public AccessTokenStore {
static void RegisterPrefs(PrefService* prefs);
ChromeAccessTokenStore();
+ virtual ~ChromeAccessTokenStore();
- private:
- void LoadDictionaryStoreInUIThread(
- scoped_refptr<CancelableRequest<LoadAccessTokensCallbackType> > request);
+ virtual void LoadAccessTokens(
+ const LoadAccessTokensCallbackType& request) OVERRIDE;
+ private:
// AccessTokenStore
- virtual void DoLoadAccessTokens(
- scoped_refptr<CancelableRequest<LoadAccessTokensCallbackType> > request)
- OVERRIDE;
virtual void SaveAccessToken(
const GURL& server_url, const string16& access_token) OVERRIDE;