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

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

Issue 935963002: Use int64 time stamp when storing metadata to the HTTP cache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test case 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, 214 void Write(const GURL& url,
215 double expected_response_time, 215 base::Time expected_response_time,
216 IOBuffer* buf, 216 IOBuffer* buf,
217 int buf_len); 217 int buf_len);
218 218
219 private: 219 private:
220 void VerifyResponse(int result); 220 void VerifyResponse(int result);
221 void SelfDestroy(); 221 void SelfDestroy();
222 void OnIOComplete(int result); 222 void OnIOComplete(int result);
223 223
224 scoped_ptr<HttpCache::Transaction> transaction_; 224 scoped_ptr<HttpCache::Transaction> transaction_;
225 bool verified_; 225 bool verified_;
226 scoped_refptr<IOBuffer> buf_; 226 scoped_refptr<IOBuffer> buf_;
227 int buf_len_; 227 int buf_len_;
228 double expected_response_time_; 228 base::Time expected_response_time_;
229 HttpRequestInfo request_info_; 229 HttpRequestInfo request_info_;
230 DISALLOW_COPY_AND_ASSIGN(MetadataWriter); 230 DISALLOW_COPY_AND_ASSIGN(MetadataWriter);
231 }; 231 };
232 232
233 void HttpCache::MetadataWriter::Write(const GURL& url, 233 void HttpCache::MetadataWriter::Write(const GURL& url,
234 double expected_response_time, 234 base::Time expected_response_time,
235 IOBuffer* buf, 235 IOBuffer* buf,
236 int buf_len) { 236 int buf_len) {
237 DCHECK_GT(buf_len, 0); 237 DCHECK_GT(buf_len, 0);
238 DCHECK(buf); 238 DCHECK(buf);
239 DCHECK(buf->data()); 239 DCHECK(buf->data());
240 request_info_.url = url; 240 request_info_.url = url;
241 request_info_.method = "GET"; 241 request_info_.method = "GET";
242 request_info_.load_flags = LOAD_ONLY_FROM_CACHE; 242 request_info_.load_flags = LOAD_ONLY_FROM_CACHE;
243 243
244 expected_response_time_ = expected_response_time; 244 expected_response_time_ = expected_response_time;
245 buf_ = buf; 245 buf_ = buf;
246 buf_len_ = buf_len; 246 buf_len_ = buf_len;
247 verified_ = false; 247 verified_ = false;
248 248
249 int rv = transaction_->Start( 249 int rv = transaction_->Start(
250 &request_info_, 250 &request_info_,
251 base::Bind(&MetadataWriter::OnIOComplete, base::Unretained(this)), 251 base::Bind(&MetadataWriter::OnIOComplete, base::Unretained(this)),
252 BoundNetLog()); 252 BoundNetLog());
253 if (rv != ERR_IO_PENDING) 253 if (rv != ERR_IO_PENDING)
254 VerifyResponse(rv); 254 VerifyResponse(rv);
255 } 255 }
256 256
257 void HttpCache::MetadataWriter::VerifyResponse(int result) { 257 void HttpCache::MetadataWriter::VerifyResponse(int result) {
258 verified_ = true; 258 verified_ = true;
259 if (result != OK) 259 if (result != OK)
260 return SelfDestroy(); 260 return SelfDestroy();
261 261
262 const HttpResponseInfo* response_info = transaction_->GetResponseInfo(); 262 const HttpResponseInfo* response_info = transaction_->GetResponseInfo();
263 DCHECK(response_info->was_cached); 263 DCHECK(response_info->was_cached);
264 if (response_info->response_time.ToDoubleT() != expected_response_time_) 264 if (response_info->response_time != expected_response_time_)
265 return SelfDestroy(); 265 return SelfDestroy();
266 266
267 result = transaction_->WriteMetadata( 267 result = transaction_->WriteMetadata(
268 buf_.get(), 268 buf_.get(),
269 buf_len_, 269 buf_len_,
270 base::Bind(&MetadataWriter::OnIOComplete, base::Unretained(this))); 270 base::Bind(&MetadataWriter::OnIOComplete, base::Unretained(this)));
271 if (result != ERR_IO_PENDING) 271 if (result != ERR_IO_PENDING)
272 SelfDestroy(); 272 SelfDestroy();
273 } 273 }
274 274
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 // static 572 // static
573 bool HttpCache::ParseResponseInfo(const char* data, int len, 573 bool HttpCache::ParseResponseInfo(const char* data, int len,
574 HttpResponseInfo* response_info, 574 HttpResponseInfo* response_info,
575 bool* response_truncated) { 575 bool* response_truncated) {
576 Pickle pickle(data, len); 576 Pickle pickle(data, len);
577 return response_info->InitFromPickle(pickle, response_truncated); 577 return response_info->InitFromPickle(pickle, response_truncated);
578 } 578 }
579 579
580 void HttpCache::WriteMetadata(const GURL& url, 580 void HttpCache::WriteMetadata(const GURL& url,
581 RequestPriority priority, 581 RequestPriority priority,
582 double expected_response_time, 582 base::Time expected_response_time,
583 IOBuffer* buf, 583 IOBuffer* buf,
584 int buf_len) { 584 int buf_len) {
585 if (!buf_len) 585 if (!buf_len)
586 return; 586 return;
587 587
588 // Do lazy initialization of disk cache if needed. 588 // Do lazy initialization of disk cache if needed.
589 if (!disk_cache_.get()) { 589 if (!disk_cache_.get()) {
590 // We don't care about the result. 590 // We don't care about the result.
591 CreateBackend(NULL, net::CompletionCallback()); 591 CreateBackend(NULL, net::CompletionCallback());
592 } 592 }
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 building_backend_ = false; 1418 building_backend_ = false;
1419 DeletePendingOp(pending_op); 1419 DeletePendingOp(pending_op);
1420 } 1420 }
1421 1421
1422 // The cache may be gone when we return from the callback. 1422 // The cache may be gone when we return from the callback.
1423 if (!item->DoCallback(result, disk_cache_.get())) 1423 if (!item->DoCallback(result, disk_cache_.get()))
1424 item->NotifyTransaction(result, NULL); 1424 item->NotifyTransaction(result, NULL);
1425 } 1425 }
1426 1426
1427 } // 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