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

Unified Diff: net/tools/quic/quic_in_memory_cache.cc

Issue 2322233004: Landing Recent QUIC changes until Sun Sep 4 03:41:00 (Closed)
Patch Set: Remove simulation files from the build. Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/tools/quic/quic_in_memory_cache.h ('k') | net/tools/quic/quic_per_connection_packet_writer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/quic/quic_in_memory_cache.cc
diff --git a/net/tools/quic/quic_in_memory_cache.cc b/net/tools/quic/quic_in_memory_cache.cc
index 00b3e72f8be8bf388749de012966bf7c880d5ea6..ab2ad1e6c4026f3209583e1cc5eb0e99dfce0504 100644
--- a/net/tools/quic/quic_in_memory_cache.cc
+++ b/net/tools/quic/quic_in_memory_cache.cc
@@ -142,6 +142,8 @@ QuicInMemoryCache* QuicInMemoryCache::GetInstance() {
const QuicInMemoryCache::Response* QuicInMemoryCache::GetResponse(
StringPiece host,
StringPiece path) const {
+ base::AutoLock lock(response_mutex_);
+
ResponseMap::const_iterator it = responses_.find(GetKey(host, path));
if (it == responses_.end()) {
DVLOG(1) << "Get response for resource failed: host " << host << " path "
@@ -178,6 +180,7 @@ void QuicInMemoryCache::AddSimpleResponseWithServerPushResources(
}
void QuicInMemoryCache::AddDefaultResponse(Response* response) {
+ base::AutoLock lock(response_mutex_);
default_response_.reset(response);
}
@@ -208,6 +211,7 @@ void QuicInMemoryCache::AddSpecialResponse(StringPiece host,
QuicInMemoryCache::QuicInMemoryCache() {}
void QuicInMemoryCache::ResetForTests() {
+ base::AutoLock lock(response_mutex_);
base::STLDeleteValues(&responses_);
server_push_resources_.clear();
}
@@ -268,6 +272,8 @@ void QuicInMemoryCache::InitializeFromDirectory(const string& cache_directory) {
list<ServerPushInfo> QuicInMemoryCache::GetServerPushResources(
string request_url) {
+ base::AutoLock lock(response_mutex_);
+
list<ServerPushInfo> resources;
auto resource_range = server_push_resources_.equal_range(request_url);
for (auto it = resource_range.first; it != resource_range.second; ++it) {
@@ -279,7 +285,10 @@ list<ServerPushInfo> QuicInMemoryCache::GetServerPushResources(
}
QuicInMemoryCache::~QuicInMemoryCache() {
- base::STLDeleteValues(&responses_);
+ {
+ base::AutoLock lock(response_mutex_);
+ base::STLDeleteValues(&responses_);
+ }
}
void QuicInMemoryCache::AddResponseImpl(StringPiece host,
@@ -288,6 +297,8 @@ void QuicInMemoryCache::AddResponseImpl(StringPiece host,
SpdyHeaderBlock response_headers,
StringPiece response_body,
SpdyHeaderBlock response_trailers) {
+ base::AutoLock lock(response_mutex_);
+
DCHECK(!host.empty()) << "Host must be populated, e.g. \"www.google.com\"";
string key = GetKey(host, path);
if (base::ContainsKey(responses_, key)) {
@@ -321,13 +332,22 @@ void QuicInMemoryCache::MaybeAddServerPushResources(
DVLOG(1) << "Add request-resource association: request url " << request_url
<< " push url " << push_resource.request_url
<< " response headers " << push_resource.headers.DebugString();
- server_push_resources_.insert(std::make_pair(request_url, push_resource));
+ {
+ base::AutoLock lock(response_mutex_);
+ server_push_resources_.insert(std::make_pair(request_url, push_resource));
+ }
string host = push_resource.request_url.host();
if (host.empty()) {
host = request_host.as_string();
}
string path = push_resource.request_url.path();
- if (responses_.find(GetKey(host, path)) == responses_.end()) {
+ bool found_existing_response = false;
+ {
+ base::AutoLock lock(response_mutex_);
+ found_existing_response =
+ base::ContainsKey(responses_, GetKey(host, path));
+ }
+ if (!found_existing_response) {
// Add a server push response to responses map, if it is not in the map.
StringPiece body = push_resource.body;
DVLOG(1) << "Add response for push resource: host " << host << " path "
@@ -339,6 +359,7 @@ void QuicInMemoryCache::MaybeAddServerPushResources(
bool QuicInMemoryCache::PushResourceExistsInCache(string original_request_url,
ServerPushInfo resource) {
+ base::AutoLock lock(response_mutex_);
auto resource_range =
server_push_resources_.equal_range(original_request_url);
for (auto it = resource_range.first; it != resource_range.second; ++it) {
« no previous file with comments | « net/tools/quic/quic_in_memory_cache.h ('k') | net/tools/quic/quic_per_connection_packet_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698