OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/geolocation/chrome_access_token_store.h" |
| 6 |
| 7 #include "base/string_piece.h" |
| 8 #include "base/utf_string_conversions.h" |
| 9 #include "base/values.h" |
| 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/prefs/pref_service.h" |
| 12 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 13 #include "chrome/common/pref_names.h" |
| 14 #include "content/browser/browser_thread.h" |
| 15 #include "googleurl/src/gurl.h" |
| 16 |
| 17 void ChromeAccessTokenStore::RegisterPrefs(PrefService* prefs) { |
| 18 prefs->RegisterDictionaryPref(prefs::kGeolocationAccessToken); |
| 19 } |
| 20 |
| 21 ChromeAccessTokenStore::ChromeAccessTokenStore() { |
| 22 } |
| 23 |
| 24 void ChromeAccessTokenStore::LoadDictionaryStoreInUIThread( |
| 25 scoped_refptr<CancelableRequest<LoadAccessTokensCallbackType> > request) { |
| 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 27 if (request->canceled()) |
| 28 return; |
| 29 const DictionaryValue* token_dictionary = |
| 30 g_browser_process->local_state()->GetDictionary( |
| 31 prefs::kGeolocationAccessToken); |
| 32 |
| 33 AccessTokenStore::AccessTokenSet access_token_set; |
| 34 // The dictionary value could be NULL if the pref has never been set. |
| 35 if (token_dictionary != NULL) { |
| 36 for (DictionaryValue::key_iterator it = token_dictionary->begin_keys(); |
| 37 it != token_dictionary->end_keys(); ++it) { |
| 38 GURL url(*it); |
| 39 if (!url.is_valid()) |
| 40 continue; |
| 41 token_dictionary->GetStringWithoutPathExpansion(*it, |
| 42 &access_token_set[url]); |
| 43 } |
| 44 } |
| 45 request->ForwardResultAsync(MakeTuple(access_token_set)); |
| 46 } |
| 47 |
| 48 void ChromeAccessTokenStore::DoLoadAccessTokens( |
| 49 scoped_refptr<CancelableRequest<LoadAccessTokensCallbackType> > request) { |
| 50 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod( |
| 51 this, &ChromeAccessTokenStore::LoadDictionaryStoreInUIThread, |
| 52 request)); |
| 53 } |
| 54 |
| 55 void SetAccessTokenOnUIThread(const GURL& server_url, const string16& token) { |
| 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 57 DictionaryPrefUpdate update(g_browser_process->local_state(), |
| 58 prefs::kGeolocationAccessToken); |
| 59 DictionaryValue* access_token_dictionary = update.Get(); |
| 60 access_token_dictionary->SetWithoutPathExpansion( |
| 61 server_url.spec(), Value::CreateStringValue(token)); |
| 62 } |
| 63 |
| 64 void ChromeAccessTokenStore::SaveAccessToken( |
| 65 const GURL& server_url, const string16& access_token) { |
| 66 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableFunction( |
| 67 &SetAccessTokenOnUIThread, server_url, access_token)); |
| 68 } |
OLD | NEW |