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

Side by Side Diff: content/browser/cache_storage/cache_storage_dispatcher_host.cc

Issue 1768063002: Introduce String::fromUTF8Lenient() and use it for cache_name in CacheStorage API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: incorporated jsbell's comment Created 4 years, 9 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/cache_storage/cache_storage_dispatcher_host.h" 5 #include "content/browser/cache_storage/cache_storage_dispatcher_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/strings/string16.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.h"
16 #include "content/browser/bad_message.h" 14 #include "content/browser/bad_message.h"
17 #include "content/browser/cache_storage/cache_storage_cache.h" 15 #include "content/browser/cache_storage/cache_storage_cache.h"
18 #include "content/browser/cache_storage/cache_storage_context_impl.h" 16 #include "content/browser/cache_storage/cache_storage_context_impl.h"
19 #include "content/browser/cache_storage/cache_storage_manager.h" 17 #include "content/browser/cache_storage/cache_storage_manager.h"
20 #include "content/common/cache_storage/cache_storage_messages.h" 18 #include "content/common/cache_storage/cache_storage_messages.h"
21 #include "content/public/browser/content_browser_client.h" 19 #include "content/public/browser/content_browser_client.h"
22 #include "content/public/common/origin_util.h" 20 #include "content/public/common/origin_util.h"
23 #include "storage/browser/blob/blob_data_handle.h" 21 #include "storage/browser/blob/blob_data_handle.h"
24 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerCacheError.h" 22 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerCacheError.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 void CacheStorageDispatcherHost::CreateCacheListener( 106 void CacheStorageDispatcherHost::CreateCacheListener(
109 CacheStorageContextImpl* context) { 107 CacheStorageContextImpl* context) {
110 DCHECK_CURRENTLY_ON(BrowserThread::IO); 108 DCHECK_CURRENTLY_ON(BrowserThread::IO);
111 context_ = context; 109 context_ = context;
112 } 110 }
113 111
114 void CacheStorageDispatcherHost::OnCacheStorageHas( 112 void CacheStorageDispatcherHost::OnCacheStorageHas(
115 int thread_id, 113 int thread_id,
116 int request_id, 114 int request_id,
117 const GURL& origin, 115 const GURL& origin,
118 const base::string16& cache_name) { 116 const std::string& cache_name) {
119 TRACE_EVENT0("CacheStorage", "CacheStorageDispatcherHost::OnCacheStorageHas"); 117 TRACE_EVENT0("CacheStorage", "CacheStorageDispatcherHost::OnCacheStorageHas");
120 if (!OriginCanAccessCacheStorage(origin)) { 118 if (!OriginCanAccessCacheStorage(origin)) {
121 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); 119 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN);
122 return; 120 return;
123 } 121 }
124 context_->cache_manager()->HasCache( 122 context_->cache_manager()->HasCache(
125 origin, base::UTF16ToUTF8(cache_name), 123 origin, cache_name,
126 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageHasCallback, this, 124 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageHasCallback, this,
127 thread_id, request_id)); 125 thread_id, request_id));
128 } 126 }
129 127
130 void CacheStorageDispatcherHost::OnCacheStorageOpen( 128 void CacheStorageDispatcherHost::OnCacheStorageOpen(
131 int thread_id, 129 int thread_id,
132 int request_id, 130 int request_id,
133 const GURL& origin, 131 const GURL& origin,
134 const base::string16& cache_name) { 132 const std::string& cache_name) {
135 TRACE_EVENT0("CacheStorage", 133 TRACE_EVENT0("CacheStorage",
136 "CacheStorageDispatcherHost::OnCacheStorageOpen"); 134 "CacheStorageDispatcherHost::OnCacheStorageOpen");
137 if (!OriginCanAccessCacheStorage(origin)) { 135 if (!OriginCanAccessCacheStorage(origin)) {
138 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); 136 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN);
139 return; 137 return;
140 } 138 }
141 context_->cache_manager()->OpenCache( 139 context_->cache_manager()->OpenCache(
142 origin, base::UTF16ToUTF8(cache_name), 140 origin, cache_name,
143 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageOpenCallback, this, 141 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageOpenCallback, this,
144 thread_id, request_id)); 142 thread_id, request_id));
145 } 143 }
146 144
147 void CacheStorageDispatcherHost::OnCacheStorageDelete( 145 void CacheStorageDispatcherHost::OnCacheStorageDelete(
148 int thread_id, 146 int thread_id,
149 int request_id, 147 int request_id,
150 const GURL& origin, 148 const GURL& origin,
151 const base::string16& cache_name) { 149 const std::string& cache_name) {
152 TRACE_EVENT0("CacheStorage", 150 TRACE_EVENT0("CacheStorage",
153 "CacheStorageDispatcherHost::OnCacheStorageDelete"); 151 "CacheStorageDispatcherHost::OnCacheStorageDelete");
154 if (!OriginCanAccessCacheStorage(origin)) { 152 if (!OriginCanAccessCacheStorage(origin)) {
155 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); 153 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN);
156 return; 154 return;
157 } 155 }
158 context_->cache_manager()->DeleteCache( 156 context_->cache_manager()->DeleteCache(
159 origin, base::UTF16ToUTF8(cache_name), 157 origin, cache_name,
160 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageDeleteCallback, 158 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageDeleteCallback,
161 this, thread_id, request_id)); 159 this, thread_id, request_id));
162 } 160 }
163 161
164 void CacheStorageDispatcherHost::OnCacheStorageKeys(int thread_id, 162 void CacheStorageDispatcherHost::OnCacheStorageKeys(int thread_id,
165 int request_id, 163 int request_id,
166 const GURL& origin) { 164 const GURL& origin) {
167 TRACE_EVENT0("CacheStorage", 165 TRACE_EVENT0("CacheStorage",
168 "CacheStorageDispatcherHost::OnCacheStorageKeys"); 166 "CacheStorageDispatcherHost::OnCacheStorageKeys");
169 if (!OriginCanAccessCacheStorage(origin)) { 167 if (!OriginCanAccessCacheStorage(origin)) {
(...skipping 24 matching lines...) Expand all
194 request.is_reload)); 192 request.is_reload));
195 193
196 if (match_params.cache_name.empty()) { 194 if (match_params.cache_name.empty()) {
197 context_->cache_manager()->MatchAllCaches( 195 context_->cache_manager()->MatchAllCaches(
198 origin, std::move(scoped_request), 196 origin, std::move(scoped_request),
199 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, 197 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback,
200 this, thread_id, request_id)); 198 this, thread_id, request_id));
201 return; 199 return;
202 } 200 }
203 context_->cache_manager()->MatchCache( 201 context_->cache_manager()->MatchCache(
204 origin, base::UTF16ToUTF8(match_params.cache_name), 202 origin, match_params.cache_name, std::move(scoped_request),
205 std::move(scoped_request),
206 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, this, 203 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, this,
207 thread_id, request_id)); 204 thread_id, request_id));
208 } 205 }
209 206
210 void CacheStorageDispatcherHost::OnCacheMatch( 207 void CacheStorageDispatcherHost::OnCacheMatch(
211 int thread_id, 208 int thread_id,
212 int request_id, 209 int request_id,
213 int cache_id, 210 int cache_id,
214 const ServiceWorkerFetchRequest& request, 211 const ServiceWorkerFetchRequest& request,
215 const CacheStorageCacheQueryParams& match_params) { 212 const CacheStorageCacheQueryParams& match_params) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 int thread_id, 360 int thread_id,
364 int request_id, 361 int request_id,
365 const std::vector<std::string>& strings, 362 const std::vector<std::string>& strings,
366 CacheStorageError error) { 363 CacheStorageError error) {
367 if (error != CACHE_STORAGE_OK) { 364 if (error != CACHE_STORAGE_OK) {
368 Send(new CacheStorageMsg_CacheStorageKeysError( 365 Send(new CacheStorageMsg_CacheStorageKeysError(
369 thread_id, request_id, ToWebServiceWorkerCacheError(error))); 366 thread_id, request_id, ToWebServiceWorkerCacheError(error)));
370 return; 367 return;
371 } 368 }
372 369
373 std::vector<base::string16> string16s;
374 for (size_t i = 0, max = strings.size(); i < max; ++i) {
375 string16s.push_back(base::UTF8ToUTF16(strings[i]));
376 }
377 Send(new CacheStorageMsg_CacheStorageKeysSuccess(thread_id, request_id, 370 Send(new CacheStorageMsg_CacheStorageKeysSuccess(thread_id, request_id,
378 string16s)); 371 strings));
379 } 372 }
380 373
381 void CacheStorageDispatcherHost::OnCacheStorageMatchCallback( 374 void CacheStorageDispatcherHost::OnCacheStorageMatchCallback(
382 int thread_id, 375 int thread_id,
383 int request_id, 376 int request_id,
384 CacheStorageError error, 377 CacheStorageError error,
385 scoped_ptr<ServiceWorkerResponse> response, 378 scoped_ptr<ServiceWorkerResponse> response,
386 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { 379 scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
387 if (error != CACHE_STORAGE_OK) { 380 if (error != CACHE_STORAGE_OK) {
388 Send(new CacheStorageMsg_CacheStorageMatchError( 381 Send(new CacheStorageMsg_CacheStorageMatchError(
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); 512 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid);
520 if (it == blob_handle_store_.end()) 513 if (it == blob_handle_store_.end())
521 return; 514 return;
522 DCHECK(!it->second.empty()); 515 DCHECK(!it->second.empty());
523 it->second.pop_front(); 516 it->second.pop_front();
524 if (it->second.empty()) 517 if (it->second.empty())
525 blob_handle_store_.erase(it); 518 blob_handle_store_.erase(it);
526 } 519 }
527 520
528 } // namespace content 521 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage_dispatcher_host.h ('k') | content/common/cache_storage/cache_storage_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698