OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/geolocation/chrome_access_token_store.h" | 5 #include "chrome/browser/geolocation/chrome_access_token_store.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/string_piece.h" | 8 #include "base/string_piece.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 void Run() { | 37 void Run() { |
38 BrowserThread::PostTaskAndReply( | 38 BrowserThread::PostTaskAndReply( |
39 BrowserThread::UI, | 39 BrowserThread::UI, |
40 FROM_HERE, | 40 FROM_HERE, |
41 base::Bind(&TokenLoadingJob::PerformWorkOnUIThread, this), | 41 base::Bind(&TokenLoadingJob::PerformWorkOnUIThread, this), |
42 base::Bind(&TokenLoadingJob::RespondOnOriginatingThread, this)); | 42 base::Bind(&TokenLoadingJob::RespondOnOriginatingThread, this)); |
43 } | 43 } |
44 | 44 |
45 private: | 45 private: |
| 46 friend class base::RefCountedThreadSafe<TokenLoadingJob>; |
| 47 |
| 48 ~TokenLoadingJob() {} |
| 49 |
46 void PerformWorkOnUIThread() { | 50 void PerformWorkOnUIThread() { |
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
48 DictionaryPrefUpdate update(g_browser_process->local_state(), | 52 DictionaryPrefUpdate update(g_browser_process->local_state(), |
49 prefs::kGeolocationAccessToken); | 53 prefs::kGeolocationAccessToken); |
50 DictionaryValue* token_dictionary = update.Get(); | 54 DictionaryValue* token_dictionary = update.Get(); |
51 | 55 |
52 bool has_old_network_provider_url = false; | 56 bool has_old_network_provider_url = false; |
53 // The dictionary value could be NULL if the pref has never been set. | 57 // The dictionary value could be NULL if the pref has never been set. |
54 if (token_dictionary != NULL) { | 58 if (token_dictionary != NULL) { |
55 for (DictionaryValue::key_iterator it = token_dictionary->begin_keys(); | 59 for (DictionaryValue::key_iterator it = token_dictionary->begin_keys(); |
(...skipping 24 matching lines...) Expand all Loading... |
80 AccessTokenStore::AccessTokenSet access_token_set_; | 84 AccessTokenStore::AccessTokenSet access_token_set_; |
81 net::URLRequestContextGetter* system_request_context_; | 85 net::URLRequestContextGetter* system_request_context_; |
82 }; | 86 }; |
83 | 87 |
84 } // namespace | 88 } // namespace |
85 | 89 |
86 void ChromeAccessTokenStore::RegisterPrefs(PrefService* prefs) { | 90 void ChromeAccessTokenStore::RegisterPrefs(PrefService* prefs) { |
87 prefs->RegisterDictionaryPref(prefs::kGeolocationAccessToken); | 91 prefs->RegisterDictionaryPref(prefs::kGeolocationAccessToken); |
88 } | 92 } |
89 | 93 |
90 ChromeAccessTokenStore::ChromeAccessTokenStore() { | 94 ChromeAccessTokenStore::ChromeAccessTokenStore() {} |
91 } | |
92 | |
93 ChromeAccessTokenStore::~ChromeAccessTokenStore() { | |
94 } | |
95 | 95 |
96 void ChromeAccessTokenStore::LoadAccessTokens( | 96 void ChromeAccessTokenStore::LoadAccessTokens( |
97 const LoadAccessTokensCallbackType& callback) { | 97 const LoadAccessTokensCallbackType& callback) { |
98 scoped_refptr<TokenLoadingJob> job(new TokenLoadingJob(callback)); | 98 scoped_refptr<TokenLoadingJob> job(new TokenLoadingJob(callback)); |
99 job->Run(); | 99 job->Run(); |
100 } | 100 } |
101 | 101 |
102 void SetAccessTokenOnUIThread(const GURL& server_url, const string16& token) { | 102 ChromeAccessTokenStore::~ChromeAccessTokenStore() {} |
| 103 |
| 104 static void SetAccessTokenOnUIThread(const GURL& server_url, |
| 105 const string16& token) { |
103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
104 DictionaryPrefUpdate update(g_browser_process->local_state(), | 107 DictionaryPrefUpdate update(g_browser_process->local_state(), |
105 prefs::kGeolocationAccessToken); | 108 prefs::kGeolocationAccessToken); |
106 DictionaryValue* access_token_dictionary = update.Get(); | 109 DictionaryValue* access_token_dictionary = update.Get(); |
107 access_token_dictionary->SetWithoutPathExpansion( | 110 access_token_dictionary->SetWithoutPathExpansion( |
108 server_url.spec(), Value::CreateStringValue(token)); | 111 server_url.spec(), Value::CreateStringValue(token)); |
109 } | 112 } |
110 | 113 |
111 void ChromeAccessTokenStore::SaveAccessToken(const GURL& server_url, | 114 void ChromeAccessTokenStore::SaveAccessToken(const GURL& server_url, |
112 const string16& access_token) { | 115 const string16& access_token) { |
113 BrowserThread::PostTask( | 116 BrowserThread::PostTask( |
114 BrowserThread::UI, FROM_HERE, | 117 BrowserThread::UI, FROM_HERE, |
115 base::Bind(&SetAccessTokenOnUIThread, server_url, access_token)); | 118 base::Bind(&SetAccessTokenOnUIThread, server_url, access_token)); |
116 } | 119 } |
OLD | NEW |