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

Side by Side Diff: net/http/http_cache.cc

Issue 895853003: Update from https://crrev.com/314320 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « net/http/http_cache.h ('k') | net/http/http_cache_unittest.cc » ('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 "net/http/http_cache.h" 5 #include "net/http/http_cache.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 10
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 public: 204 public:
205 explicit MetadataWriter(HttpCache::Transaction* trans) 205 explicit MetadataWriter(HttpCache::Transaction* trans)
206 : transaction_(trans), 206 : transaction_(trans),
207 verified_(false), 207 verified_(false),
208 buf_len_(0) { 208 buf_len_(0) {
209 } 209 }
210 210
211 ~MetadataWriter() {} 211 ~MetadataWriter() {}
212 212
213 // Implements the bulk of HttpCache::WriteMetadata. 213 // Implements the bulk of HttpCache::WriteMetadata.
214 void Write(const GURL& url, base::Time expected_response_time, IOBuffer* buf, 214 void Write(const GURL& url,
215 double expected_response_time,
216 IOBuffer* buf,
215 int buf_len); 217 int buf_len);
216 218
217 private: 219 private:
218 void VerifyResponse(int result); 220 void VerifyResponse(int result);
219 void SelfDestroy(); 221 void SelfDestroy();
220 void OnIOComplete(int result); 222 void OnIOComplete(int result);
221 223
222 scoped_ptr<HttpCache::Transaction> transaction_; 224 scoped_ptr<HttpCache::Transaction> transaction_;
223 bool verified_; 225 bool verified_;
224 scoped_refptr<IOBuffer> buf_; 226 scoped_refptr<IOBuffer> buf_;
225 int buf_len_; 227 int buf_len_;
226 base::Time expected_response_time_; 228 double expected_response_time_;
227 HttpRequestInfo request_info_; 229 HttpRequestInfo request_info_;
228 DISALLOW_COPY_AND_ASSIGN(MetadataWriter); 230 DISALLOW_COPY_AND_ASSIGN(MetadataWriter);
229 }; 231 };
230 232
231 void HttpCache::MetadataWriter::Write(const GURL& url, 233 void HttpCache::MetadataWriter::Write(const GURL& url,
232 base::Time expected_response_time, 234 double expected_response_time,
233 IOBuffer* buf, int buf_len) { 235 IOBuffer* buf,
236 int buf_len) {
234 DCHECK_GT(buf_len, 0); 237 DCHECK_GT(buf_len, 0);
235 DCHECK(buf); 238 DCHECK(buf);
236 DCHECK(buf->data()); 239 DCHECK(buf->data());
237 request_info_.url = url; 240 request_info_.url = url;
238 request_info_.method = "GET"; 241 request_info_.method = "GET";
239 request_info_.load_flags = LOAD_ONLY_FROM_CACHE; 242 request_info_.load_flags = LOAD_ONLY_FROM_CACHE;
240 243
241 expected_response_time_ = expected_response_time; 244 expected_response_time_ = expected_response_time;
242 buf_ = buf; 245 buf_ = buf;
243 buf_len_ = buf_len; 246 buf_len_ = buf_len;
244 verified_ = false; 247 verified_ = false;
245 248
246 int rv = transaction_->Start( 249 int rv = transaction_->Start(
247 &request_info_, 250 &request_info_,
248 base::Bind(&MetadataWriter::OnIOComplete, base::Unretained(this)), 251 base::Bind(&MetadataWriter::OnIOComplete, base::Unretained(this)),
249 BoundNetLog()); 252 BoundNetLog());
250 if (rv != ERR_IO_PENDING) 253 if (rv != ERR_IO_PENDING)
251 VerifyResponse(rv); 254 VerifyResponse(rv);
252 } 255 }
253 256
254 void HttpCache::MetadataWriter::VerifyResponse(int result) { 257 void HttpCache::MetadataWriter::VerifyResponse(int result) {
255 verified_ = true; 258 verified_ = true;
256 if (result != OK) 259 if (result != OK)
257 return SelfDestroy(); 260 return SelfDestroy();
258 261
259 const HttpResponseInfo* response_info = transaction_->GetResponseInfo(); 262 const HttpResponseInfo* response_info = transaction_->GetResponseInfo();
260 DCHECK(response_info->was_cached); 263 DCHECK(response_info->was_cached);
261 if (response_info->response_time != expected_response_time_) 264 if (response_info->response_time.ToDoubleT() != expected_response_time_)
262 return SelfDestroy(); 265 return SelfDestroy();
263 266
264 result = transaction_->WriteMetadata( 267 result = transaction_->WriteMetadata(
265 buf_.get(), 268 buf_.get(),
266 buf_len_, 269 buf_len_,
267 base::Bind(&MetadataWriter::OnIOComplete, base::Unretained(this))); 270 base::Bind(&MetadataWriter::OnIOComplete, base::Unretained(this)));
268 if (result != ERR_IO_PENDING) 271 if (result != ERR_IO_PENDING)
269 SelfDestroy(); 272 SelfDestroy();
270 } 273 }
271 274
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 // static 572 // static
570 bool HttpCache::ParseResponseInfo(const char* data, int len, 573 bool HttpCache::ParseResponseInfo(const char* data, int len,
571 HttpResponseInfo* response_info, 574 HttpResponseInfo* response_info,
572 bool* response_truncated) { 575 bool* response_truncated) {
573 Pickle pickle(data, len); 576 Pickle pickle(data, len);
574 return response_info->InitFromPickle(pickle, response_truncated); 577 return response_info->InitFromPickle(pickle, response_truncated);
575 } 578 }
576 579
577 void HttpCache::WriteMetadata(const GURL& url, 580 void HttpCache::WriteMetadata(const GURL& url,
578 RequestPriority priority, 581 RequestPriority priority,
579 base::Time expected_response_time, 582 double expected_response_time,
580 IOBuffer* buf, 583 IOBuffer* buf,
581 int buf_len) { 584 int buf_len) {
582 if (!buf_len) 585 if (!buf_len)
583 return; 586 return;
584 587
585 // Do lazy initialization of disk cache if needed. 588 // Do lazy initialization of disk cache if needed.
586 if (!disk_cache_.get()) { 589 if (!disk_cache_.get()) {
587 // We don't care about the result. 590 // We don't care about the result.
588 CreateBackend(NULL, net::CompletionCallback()); 591 CreateBackend(NULL, net::CompletionCallback());
589 } 592 }
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 building_backend_ = false; 1418 building_backend_ = false;
1416 DeletePendingOp(pending_op); 1419 DeletePendingOp(pending_op);
1417 } 1420 }
1418 1421
1419 // The cache may be gone when we return from the callback. 1422 // The cache may be gone when we return from the callback.
1420 if (!item->DoCallback(result, disk_cache_.get())) 1423 if (!item->DoCallback(result, disk_cache_.get()))
1421 item->NotifyTransaction(result, NULL); 1424 item->NotifyTransaction(result, NULL);
1422 } 1425 }
1423 1426
1424 } // namespace net 1427 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_cache.h ('k') | net/http/http_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698