| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 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/access_token_store.h" |
| 6 |
| 7 #include "base/utf_string_conversions.h" |
| 8 #include "base/values.h" |
| 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/common/pref_names.h" |
| 11 #include "chrome/common/pref_service.h" |
| 12 #include "googleurl/src/gurl.h" |
| 13 |
| 14 namespace { |
| 15 // Implementation of the geolocation access token store using chrome's prefs |
| 16 // store (local_state) to persist these tokens. |
| 17 // TODO(joth): Calls APIs which probably can't be used from the thread that it |
| 18 // will be run on; needs prefs access bounced via UI thread. |
| 19 class ChromePrefsAccessTokenStore : public AccessTokenStore { |
| 20 public: |
| 21 // AccessTokenStore |
| 22 virtual bool SetAccessToken(const GURL& url, |
| 23 const string16& access_token) { |
| 24 DictionaryValue* access_token_dictionary = |
| 25 g_browser_process->local_state()->GetMutableDictionary( |
| 26 prefs::kGeolocationAccessToken); |
| 27 access_token_dictionary->SetWithoutPathExpansion( |
| 28 UTF8ToWide(url.spec()), |
| 29 Value::CreateStringValueFromUTF16(access_token)); |
| 30 return true; |
| 31 } |
| 32 |
| 33 virtual bool GetAccessToken(const GURL& url, string16* access_token) { |
| 34 const DictionaryValue* access_token_dictionary = |
| 35 g_browser_process->local_state()->GetDictionary( |
| 36 prefs::kGeolocationAccessToken); |
| 37 // Careful: The returned value could be NULL if the pref has never been set. |
| 38 if (access_token_dictionary == NULL) |
| 39 return false; |
| 40 return access_token_dictionary->GetStringAsUTF16WithoutPathExpansion( |
| 41 UTF8ToWide(url.spec()), access_token); |
| 42 } |
| 43 }; |
| 44 |
| 45 } // namespace |
| 46 |
| 47 void AccessTokenStore::RegisterPrefs(PrefService* prefs) { |
| 48 prefs->RegisterDictionaryPref(prefs::kGeolocationAccessToken); |
| 49 } |
| 50 |
| 51 AccessTokenStore* NewChromePrefsAccessTokenStore(); |
| OLD | NEW |