Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: chrome/browser/geolocation/chrome_access_token_store.cc

Issue 11179003: Reapply geolocation network protocol changes. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1271/src/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/geolocation/location_arbitrator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/prefs/pref_service.h" 12 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/prefs/scoped_user_pref_update.h" 13 #include "chrome/browser/prefs/scoped_user_pref_update.h"
14 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 #include "googleurl/src/gurl.h" 16 #include "googleurl/src/gurl.h"
17 17
18 using content::AccessTokenStore; 18 using content::AccessTokenStore;
19 using content::BrowserThread; 19 using content::BrowserThread;
20 20
21 namespace { 21 namespace {
22 22
23 // This was the default location service url for Chrome versions 14 and earlier 23 bool IsUnsupportedNetworkProviderUrl(const GURL& url) {
24 // but is no longer supported. 24 const std::string& spec = url.spec();
25 const char* kOldDefaultNetworkProviderUrl = "https://www.google.com/loc/json"; 25
26 // Unsupported after Chrome v14.
27 if (spec == "https://www.google.com/loc/json")
28 return true;
29
30 // Unsupported after Chrome v22.
31 if (spec == "https://maps.googleapis.com/maps/api/browserlocation/json")
32 return true;
33
34 return false;
35 }
26 36
27 // Loads access tokens and other necessary data on the UI thread, and 37 // Loads access tokens and other necessary data on the UI thread, and
28 // calls back to the originator on the originating threaad. 38 // calls back to the originator on the originating threaad.
29 class TokenLoadingJob : public base::RefCountedThreadSafe<TokenLoadingJob> { 39 class TokenLoadingJob : public base::RefCountedThreadSafe<TokenLoadingJob> {
30 public: 40 public:
31 TokenLoadingJob( 41 TokenLoadingJob(
32 const AccessTokenStore::LoadAccessTokensCallbackType& callback) 42 const AccessTokenStore::LoadAccessTokensCallbackType& callback)
33 : callback_(callback), 43 : callback_(callback),
34 system_request_context_(NULL) { 44 system_request_context_(NULL) {
35 } 45 }
(...skipping 10 matching lines...) Expand all
46 friend class base::RefCountedThreadSafe<TokenLoadingJob>; 56 friend class base::RefCountedThreadSafe<TokenLoadingJob>;
47 57
48 ~TokenLoadingJob() {} 58 ~TokenLoadingJob() {}
49 59
50 void PerformWorkOnUIThread() { 60 void PerformWorkOnUIThread() {
51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
52 DictionaryPrefUpdate update(g_browser_process->local_state(), 62 DictionaryPrefUpdate update(g_browser_process->local_state(),
53 prefs::kGeolocationAccessToken); 63 prefs::kGeolocationAccessToken);
54 DictionaryValue* token_dictionary = update.Get(); 64 DictionaryValue* token_dictionary = update.Get();
55 65
56 bool has_old_network_provider_url = false; 66 std::vector<std::string> providers_to_remove;
57 // The dictionary value could be NULL if the pref has never been set. 67 // The dictionary value could be NULL if the pref has never been set.
58 if (token_dictionary != NULL) { 68 if (token_dictionary != NULL) {
59 for (DictionaryValue::key_iterator it = token_dictionary->begin_keys(); 69 for (DictionaryValue::key_iterator it = token_dictionary->begin_keys();
60 it != token_dictionary->end_keys(); ++it) { 70 it != token_dictionary->end_keys(); ++it) {
61 GURL url(*it); 71 GURL url(*it);
62 if (!url.is_valid()) 72 if (!url.is_valid())
63 continue; 73 continue;
64 if (url.spec() == kOldDefaultNetworkProviderUrl) { 74 if (IsUnsupportedNetworkProviderUrl(url)) {
65 has_old_network_provider_url = true; 75 providers_to_remove.push_back(*it);
66 continue; 76 continue;
67 } 77 }
68 token_dictionary->GetStringWithoutPathExpansion( 78 token_dictionary->GetStringWithoutPathExpansion(
69 *it, &access_token_set_[url]); 79 *it, &access_token_set_[url]);
70 } 80 }
71 if (has_old_network_provider_url) 81 for (size_t i = 0; i < providers_to_remove.size(); ++i) {
72 token_dictionary->RemoveWithoutPathExpansion( 82 token_dictionary->RemoveWithoutPathExpansion(
73 kOldDefaultNetworkProviderUrl, NULL); 83 providers_to_remove[i], NULL);
84 }
74 } 85 }
75 86
76 system_request_context_ = g_browser_process->system_request_context(); 87 system_request_context_ = g_browser_process->system_request_context();
77 } 88 }
78 89
79 void RespondOnOriginatingThread() { 90 void RespondOnOriginatingThread() {
80 callback_.Run(access_token_set_, system_request_context_); 91 callback_.Run(access_token_set_, system_request_context_);
81 } 92 }
82 93
83 AccessTokenStore::LoadAccessTokensCallbackType callback_; 94 AccessTokenStore::LoadAccessTokensCallbackType callback_;
(...skipping 26 matching lines...) Expand all
110 access_token_dictionary->SetWithoutPathExpansion( 121 access_token_dictionary->SetWithoutPathExpansion(
111 server_url.spec(), Value::CreateStringValue(token)); 122 server_url.spec(), Value::CreateStringValue(token));
112 } 123 }
113 124
114 void ChromeAccessTokenStore::SaveAccessToken(const GURL& server_url, 125 void ChromeAccessTokenStore::SaveAccessToken(const GURL& server_url,
115 const string16& access_token) { 126 const string16& access_token) {
116 BrowserThread::PostTask( 127 BrowserThread::PostTask(
117 BrowserThread::UI, FROM_HERE, 128 BrowserThread::UI, FROM_HERE,
118 base::Bind(&SetAccessTokenOnUIThread, server_url, access_token)); 129 base::Bind(&SetAccessTokenOnUIThread, server_url, access_token));
119 } 130 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/geolocation/location_arbitrator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698