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

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

Issue 14625012: net: Return LoadTiming information in the case of a cache hit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix tests, add tests Created 7 years, 7 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 | Annotate | Revision Log
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_transaction.h" 5 #include "net/http/http_cache_transaction.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_POSIX) 9 #if defined(OS_POSIX)
10 #include <unistd.h> 10 #include <unistd.h>
11 #endif 11 #endif
12 12
13 #include <string> 13 #include <string>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/metrics/field_trial.h" 18 #include "base/metrics/field_trial.h"
19 #include "base/metrics/histogram.h" 19 #include "base/metrics/histogram.h"
20 #include "base/rand_util.h" 20 #include "base/rand_util.h"
21 #include "base/string_number_conversions.h" 21 #include "base/string_number_conversions.h"
22 #include "base/string_util.h" 22 #include "base/string_util.h"
23 #include "base/time.h" 23 #include "base/time.h"
24 #include "net/base/completion_callback.h" 24 #include "net/base/completion_callback.h"
25 #include "net/base/io_buffer.h" 25 #include "net/base/io_buffer.h"
26 #include "net/base/load_flags.h" 26 #include "net/base/load_flags.h"
27 #include "net/base/load_timing_info.h"
27 #include "net/base/net_errors.h" 28 #include "net/base/net_errors.h"
28 #include "net/base/net_log.h" 29 #include "net/base/net_log.h"
29 #include "net/base/upload_data_stream.h" 30 #include "net/base/upload_data_stream.h"
30 #include "net/cert/cert_status_flags.h" 31 #include "net/cert/cert_status_flags.h"
31 #include "net/disk_cache/disk_cache.h" 32 #include "net/disk_cache/disk_cache.h"
32 #include "net/http/http_network_session.h" 33 #include "net/http/http_network_session.h"
33 #include "net/http/http_request_info.h" 34 #include "net/http/http_request_info.h"
34 #include "net/http/http_response_headers.h" 35 #include "net/http/http_response_headers.h"
35 #include "net/http/http_transaction.h" 36 #include "net/http/http_transaction.h"
36 #include "net/http/http_transaction_delegate.h" 37 #include "net/http/http_transaction_delegate.h"
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 UploadProgress HttpCache::Transaction::GetUploadProgress() const { 482 UploadProgress HttpCache::Transaction::GetUploadProgress() const {
482 if (network_trans_.get()) 483 if (network_trans_.get())
483 return network_trans_->GetUploadProgress(); 484 return network_trans_->GetUploadProgress();
484 return final_upload_progress_; 485 return final_upload_progress_;
485 } 486 }
486 487
487 bool HttpCache::Transaction::GetLoadTimingInfo( 488 bool HttpCache::Transaction::GetLoadTimingInfo(
488 LoadTimingInfo* load_timing_info) const { 489 LoadTimingInfo* load_timing_info) const {
489 if (network_trans_) 490 if (network_trans_)
490 return network_trans_->GetLoadTimingInfo(load_timing_info); 491 return network_trans_->GetLoadTimingInfo(load_timing_info);
491 // Don't modify |load_timing_info| when reading from the cache instead of the 492
492 // network. 493 if (last_network_trans_load_timing_) {
493 return false; 494 *load_timing_info = *last_network_trans_load_timing_;
495 return true;
496 }
497
498 if (first_cache_access_since_.is_null())
499 return false;
500
501 // If the cache entry was opened, return that time.
502 load_timing_info->send_start = first_cache_access_since_;
503 // This time doesn't make much sense when reading from the cache, so just use
504 // the same time as send_start.
505 load_timing_info->send_end = first_cache_access_since_;
506 return true;
494 } 507 }
495 508
496 void HttpCache::Transaction::SetPriority(RequestPriority priority) { 509 void HttpCache::Transaction::SetPriority(RequestPriority priority) {
497 priority_ = priority; 510 priority_ = priority;
498 if (network_trans_) 511 if (network_trans_)
499 network_trans_->SetPriority(priority_); 512 network_trans_->SetPriority(priority_);
500 } 513 }
501 514
502 //----------------------------------------------------------------------------- 515 //-----------------------------------------------------------------------------
503 516
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 DCHECK(!network_trans_.get()); 832 DCHECK(!network_trans_.get());
820 833
821 send_request_since_ = TimeTicks::Now(); 834 send_request_since_ = TimeTicks::Now();
822 835
823 // Create a network transaction. 836 // Create a network transaction.
824 int rv = cache_->network_layer_->CreateTransaction( 837 int rv = cache_->network_layer_->CreateTransaction(
825 priority_, &network_trans_, NULL); 838 priority_, &network_trans_, NULL);
826 if (rv != OK) 839 if (rv != OK)
827 return rv; 840 return rv;
828 841
842 // Old load timing information, if any, is now obsolete.
843 last_network_trans_load_timing_.reset();
844
829 ReportNetworkActionStart(); 845 ReportNetworkActionStart();
830 next_state_ = STATE_SEND_REQUEST_COMPLETE; 846 next_state_ = STATE_SEND_REQUEST_COMPLETE;
831 rv = network_trans_->Start(request_, io_callback_, net_log_); 847 rv = network_trans_->Start(request_, io_callback_, net_log_);
832 return rv; 848 return rv;
833 } 849 }
834 850
835 int HttpCache::Transaction::DoSendRequestComplete(int result) { 851 int HttpCache::Transaction::DoSendRequestComplete(int result) {
836 ReportNetworkActionFinish(); 852 ReportNetworkActionFinish();
837 853
838 if (!cache_) 854 if (!cache_)
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 // the cached 200 response, is what will be returned to the user. 1268 // the cached 200 response, is what will be returned to the user.
1253 DoneWritingToEntry(true); 1269 DoneWritingToEntry(true);
1254 } else if (entry_ && !handling_206_) { 1270 } else if (entry_ && !handling_206_) {
1255 DCHECK_EQ(READ_WRITE, mode_); 1271 DCHECK_EQ(READ_WRITE, mode_);
1256 if (!partial_.get() || partial_->IsLastRange()) { 1272 if (!partial_.get() || partial_->IsLastRange()) {
1257 cache_->ConvertWriterToReader(entry_); 1273 cache_->ConvertWriterToReader(entry_);
1258 mode_ = READ; 1274 mode_ = READ;
1259 } 1275 }
1260 // We no longer need the network transaction, so destroy it. 1276 // We no longer need the network transaction, so destroy it.
1261 final_upload_progress_ = network_trans_->GetUploadProgress(); 1277 final_upload_progress_ = network_trans_->GetUploadProgress();
1278 CacheLoadTimingInformation();
1262 network_trans_.reset(); 1279 network_trans_.reset();
1263 } else if (entry_ && handling_206_ && truncated_ && 1280 } else if (entry_ && handling_206_ && truncated_ &&
1264 partial_->initial_validation()) { 1281 partial_->initial_validation()) {
1265 // We just finished the validation of a truncated entry, and the server 1282 // We just finished the validation of a truncated entry, and the server
1266 // is willing to resume the operation. Now we go back and start serving 1283 // is willing to resume the operation. Now we go back and start serving
1267 // the first part to the user. 1284 // the first part to the user.
1285 CacheLoadTimingInformation();
1268 network_trans_.reset(); 1286 network_trans_.reset();
1269 new_response_ = NULL; 1287 new_response_ = NULL;
1270 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; 1288 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION;
1271 partial_->SetRangeToStartDownload(); 1289 partial_->SetRangeToStartDownload();
1272 return OK; 1290 return OK;
1273 } 1291 }
1274 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE; 1292 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE;
1275 return OK; 1293 return OK;
1276 } 1294 }
1277 1295
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after
2312 is_sparse_ = false; 2330 is_sparse_ = false;
2313 if (delete_object) 2331 if (delete_object)
2314 partial_.reset(NULL); 2332 partial_.reset(NULL);
2315 } 2333 }
2316 2334
2317 int HttpCache::Transaction::DoPartialNetworkReadCompleted(int result) { 2335 int HttpCache::Transaction::DoPartialNetworkReadCompleted(int result) {
2318 partial_->OnNetworkReadCompleted(result); 2336 partial_->OnNetworkReadCompleted(result);
2319 2337
2320 if (result == 0) { 2338 if (result == 0) {
2321 // We need to move on to the next range. 2339 // We need to move on to the next range.
2340 CacheLoadTimingInformation();
2322 network_trans_.reset(); 2341 network_trans_.reset();
2323 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; 2342 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION;
2324 } 2343 }
2325 return result; 2344 return result;
2326 } 2345 }
2327 2346
2328 int HttpCache::Transaction::DoPartialCacheReadCompleted(int result) { 2347 int HttpCache::Transaction::DoPartialCacheReadCompleted(int result) {
2329 partial_->OnCacheReadCompleted(result); 2348 partial_->OnCacheReadCompleted(result);
2330 2349
2331 if (result == 0 && mode_ == READ_WRITE) { 2350 if (result == 0 && mode_ == READ_WRITE) {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
2554 } 2573 }
2555 } 2574 }
2556 2575
2557 int HttpCache::Transaction::ResetCacheIOStart(int return_value) { 2576 int HttpCache::Transaction::ResetCacheIOStart(int return_value) {
2558 DCHECK(cache_io_start_.is_null()); 2577 DCHECK(cache_io_start_.is_null());
2559 if (return_value == ERR_IO_PENDING) 2578 if (return_value == ERR_IO_PENDING)
2560 cache_io_start_ = base::TimeTicks::Now(); 2579 cache_io_start_ = base::TimeTicks::Now();
2561 return return_value; 2580 return return_value;
2562 } 2581 }
2563 2582
2583 void HttpCache::Transaction::CacheLoadTimingInformation() {
2584 DCHECK(!last_network_trans_load_timing_);
2585 last_network_trans_load_timing_.reset(new LoadTimingInfo());
2586 bool result =
2587 network_trans_->GetLoadTimingInfo(last_network_trans_load_timing_.get());
2588 // This is only called after getting a response from the transaction, so it
2589 // should have timing information.
2590 DCHECK(result);
2591 }
2592
2564 } // namespace net 2593 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698