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

Side by Side Diff: net/tools/quic/quic_in_memory_cache.cc

Issue 2481923002: [WIP] make GURL::path() return a StringPiece (Closed)
Patch Set: thanks asan Created 4 years, 1 month 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 (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 "net/tools/quic/quic_in_memory_cache.h" 5 #include "net/tools/quic/quic_in_memory_cache.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/files/file_enumerator.h" 9 #include "base/files/file_enumerator.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 // Tease apart filename into host and path. 259 // Tease apart filename into host and path.
260 StringPiece base(resource_file->file_name()); 260 StringPiece base(resource_file->file_name());
261 base.remove_prefix(cache_directory.length()); 261 base.remove_prefix(cache_directory.length());
262 if (base[0] == '/') { 262 if (base[0] == '/') {
263 base.remove_prefix(1); 263 base.remove_prefix(1);
264 } 264 }
265 265
266 resource_file->SetHostPathFromBase(base); 266 resource_file->SetHostPathFromBase(base);
267 resource_file->Read(); 267 resource_file->Read();
268 268
269 AddResponse(resource_file->host(), resource_file->path(), 269 AddResponse(resource_file->host(), resource_file->path().as_string(),
270 resource_file->spdy_headers().Clone(), resource_file->body()); 270 resource_file->spdy_headers().Clone(), resource_file->body());
271 271
272 resource_files.push_back(std::move(resource_file)); 272 resource_files.push_back(std::move(resource_file));
273 } 273 }
274 274
275 for (const auto& resource_file : resource_files) { 275 for (const auto& resource_file : resource_files) {
276 std::list<ServerPushInfo> push_resources; 276 std::list<ServerPushInfo> push_resources;
277 for (const auto& push_url : resource_file->push_urls()) { 277 for (const auto& push_url : resource_file->push_urls()) {
278 GURL url(push_url); 278 GURL url(push_url);
279 const Response* response = GetResponse(url.host(), url.path()); 279 const Response* response =
280 GetResponse(url.host(), url.path().as_string());
280 if (!response) { 281 if (!response) {
281 QUIC_BUG << "Push URL '" << push_url << "' not found."; 282 QUIC_BUG << "Push URL '" << push_url << "' not found.";
282 return; 283 return;
283 } 284 }
284 push_resources.push_back(ServerPushInfo(url, response->headers().Clone(), 285 push_resources.push_back(ServerPushInfo(url, response->headers().Clone(),
285 net::kV3LowestPriority, 286 net::kV3LowestPriority,
286 response->body().as_string())); 287 response->body().as_string()));
287 } 288 }
288 MaybeAddServerPushResources(resource_file->host(), resource_file->path(), 289 MaybeAddServerPushResources(resource_file->host(),
290 resource_file->path().as_string(),
289 push_resources); 291 push_resources);
290 } 292 }
291 } 293 }
292 294
293 std::list<ServerPushInfo> QuicInMemoryCache::GetServerPushResources( 295 std::list<ServerPushInfo> QuicInMemoryCache::GetServerPushResources(
294 string request_url) { 296 string request_url) {
295 base::AutoLock lock(response_mutex_); 297 base::AutoLock lock(response_mutex_);
296 298
297 std::list<ServerPushInfo> resources; 299 std::list<ServerPushInfo> resources;
298 auto resource_range = server_push_resources_.equal_range(request_url); 300 auto resource_range = server_push_resources_.equal_range(request_url);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 << " push url " << push_resource.request_url 355 << " push url " << push_resource.request_url
354 << " response headers " << push_resource.headers.DebugString(); 356 << " response headers " << push_resource.headers.DebugString();
355 { 357 {
356 base::AutoLock lock(response_mutex_); 358 base::AutoLock lock(response_mutex_);
357 server_push_resources_.insert(std::make_pair(request_url, push_resource)); 359 server_push_resources_.insert(std::make_pair(request_url, push_resource));
358 } 360 }
359 string host = push_resource.request_url.host(); 361 string host = push_resource.request_url.host();
360 if (host.empty()) { 362 if (host.empty()) {
361 host = request_host.as_string(); 363 host = request_host.as_string();
362 } 364 }
363 string path = push_resource.request_url.path(); 365 string path = push_resource.request_url.path().as_string();
364 bool found_existing_response = false; 366 bool found_existing_response = false;
365 { 367 {
366 base::AutoLock lock(response_mutex_); 368 base::AutoLock lock(response_mutex_);
367 found_existing_response = 369 found_existing_response =
368 base::ContainsKey(responses_, GetKey(host, path)); 370 base::ContainsKey(responses_, GetKey(host, path));
369 } 371 }
370 if (!found_existing_response) { 372 if (!found_existing_response) {
371 // Add a server push response to responses map, if it is not in the map. 373 // Add a server push response to responses map, if it is not in the map.
372 StringPiece body = push_resource.body; 374 StringPiece body = push_resource.body;
373 DVLOG(1) << "Add response for push resource: host " << host << " path " 375 DVLOG(1) << "Add response for push resource: host " << host << " path "
(...skipping 11 matching lines...) Expand all
385 for (auto it = resource_range.first; it != resource_range.second; ++it) { 387 for (auto it = resource_range.first; it != resource_range.second; ++it) {
386 ServerPushInfo push_resource = it->second; 388 ServerPushInfo push_resource = it->second;
387 if (push_resource.request_url.spec() == resource.request_url.spec()) { 389 if (push_resource.request_url.spec() == resource.request_url.spec()) {
388 return true; 390 return true;
389 } 391 }
390 } 392 }
391 return false; 393 return false;
392 } 394 }
393 395
394 } // namespace net 396 } // namespace net
OLDNEW
« no previous file with comments | « net/test/url_request/url_request_mock_http_job.cc ('k') | net/tools/quic/quic_in_memory_cache_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698