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

Side by Side Diff: webkit/tools/test_shell/simple_resource_loader_bridge.cc

Issue 7602023: Use a monotonic clock (TimeTicks) to report network times to WebCore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use strong typing Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // This file contains an implementation of the ResourceLoaderBridge class. 5 // This file contains an implementation of the ResourceLoaderBridge class.
6 // The class is implemented using net::URLRequest, meaning it is a "simple" 6 // The class is implemented using net::URLRequest, meaning it is a "simple"
7 // version that directly issues requests. The more complicated one used in the 7 // version that directly issues requests. The more complicated one used in the
8 // browser uses IPC. 8 // browser uses IPC.
9 // 9 //
10 // Because net::URLRequest only provides an asynchronous resource loading API, 10 // Because net::URLRequest only provides an asynchronous resource loading API,
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 // -------------------------------------------------------------------------- 228 // --------------------------------------------------------------------------
229 // The following methods are called on the owner's thread in response to 229 // The following methods are called on the owner's thread in response to
230 // various net::URLRequest callbacks. The event hooks, defined below, trigger 230 // various net::URLRequest callbacks. The event hooks, defined below, trigger
231 // these methods asynchronously. 231 // these methods asynchronously.
232 232
233 void NotifyReceivedRedirect(const GURL& new_url, 233 void NotifyReceivedRedirect(const GURL& new_url,
234 const ResourceResponseInfo& info) { 234 const ResourceResponseInfo& info) {
235 bool has_new_first_party_for_cookies = false; 235 bool has_new_first_party_for_cookies = false;
236 GURL new_first_party_for_cookies; 236 GURL new_first_party_for_cookies;
237 if (peer_ && peer_->OnReceivedRedirect(new_url, info, 237 if (peer_ && peer_->OnReceivedRedirect(new_url, info,
238 base::TimeTicks(), base::TimeTicks(),
238 &has_new_first_party_for_cookies, 239 &has_new_first_party_for_cookies,
239 &new_first_party_for_cookies)) { 240 &new_first_party_for_cookies)) {
240 g_io_thread->message_loop()->PostTask( 241 g_io_thread->message_loop()->PostTask(
241 FROM_HERE, 242 FROM_HERE,
242 base::Bind(&RequestProxy::AsyncFollowDeferredRedirect, this, 243 base::Bind(&RequestProxy::AsyncFollowDeferredRedirect, this,
243 has_new_first_party_for_cookies, 244 has_new_first_party_for_cookies,
244 new_first_party_for_cookies)); 245 new_first_party_for_cookies));
245 } else { 246 } else {
246 Cancel(); 247 Cancel();
247 } 248 }
248 } 249 }
249 250
250 void NotifyReceivedResponse(const ResourceResponseInfo& info) { 251 void NotifyReceivedResponse(const ResourceResponseInfo& info) {
251 if (peer_) 252 if (peer_)
252 peer_->OnReceivedResponse(info); 253 peer_->OnReceivedResponse(info, base::TimeTicks(), base::TimeTicks());
253 } 254 }
254 255
255 void NotifyReceivedData(int bytes_read) { 256 void NotifyReceivedData(int bytes_read) {
256 if (!peer_) 257 if (!peer_)
257 return; 258 return;
258 259
259 // Make a local copy of buf_, since AsyncReadData reuses it. 260 // Make a local copy of buf_, since AsyncReadData reuses it.
260 scoped_array<char> buf_copy(new char[bytes_read]); 261 scoped_array<char> buf_copy(new char[bytes_read]);
261 memcpy(buf_copy.get(), buf_->data(), bytes_read); 262 memcpy(buf_copy.get(), buf_->data(), bytes_read);
262 263
(...skipping 18 matching lines...) Expand all
281 // Continue reading more data, see the comment in NotifyReceivedData. 282 // Continue reading more data, see the comment in NotifyReceivedData.
282 g_io_thread->message_loop()->PostTask( 283 g_io_thread->message_loop()->PostTask(
283 FROM_HERE, 284 FROM_HERE,
284 base::Bind(&RequestProxy::AsyncReadData, this)); 285 base::Bind(&RequestProxy::AsyncReadData, this));
285 286
286 peer_->OnDownloadedData(bytes_read); 287 peer_->OnDownloadedData(bytes_read);
287 } 288 }
288 289
289 void NotifyCompletedRequest(const net::URLRequestStatus& status, 290 void NotifyCompletedRequest(const net::URLRequestStatus& status,
290 const std::string& security_info, 291 const std::string& security_info,
291 const base::Time& complete_time) { 292 const base::TimeTicks& complete_time) {
292 if (peer_) { 293 if (peer_) {
293 peer_->OnCompletedRequest(status, security_info, complete_time); 294 peer_->OnCompletedRequest(status, security_info, complete_time);
294 DropPeer(); // ensure no further notifications 295 DropPeer(); // ensure no further notifications
295 } 296 }
296 } 297 }
297 298
298 void NotifyUploadProgress(uint64 position, uint64 size) { 299 void NotifyUploadProgress(uint64 position, uint64 size) {
299 if (peer_) 300 if (peer_)
300 peer_->OnUploadProgress(position, size); 301 peer_->OnUploadProgress(position, size);
301 } 302 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 return; 417 return;
417 } 418 }
418 419
419 owner_loop_->PostTask( 420 owner_loop_->PostTask(
420 FROM_HERE, 421 FROM_HERE,
421 base::Bind(&RequestProxy::NotifyReceivedData, this, bytes_read)); 422 base::Bind(&RequestProxy::NotifyReceivedData, this, bytes_read));
422 } 423 }
423 424
424 virtual void OnCompletedRequest(const net::URLRequestStatus& status, 425 virtual void OnCompletedRequest(const net::URLRequestStatus& status,
425 const std::string& security_info, 426 const std::string& security_info,
426 const base::Time& complete_time) { 427 const base::TimeTicks& complete_time) {
427 if (download_to_file_) 428 if (download_to_file_)
428 file_stream_.Close(); 429 file_stream_.Close();
429 owner_loop_->PostTask( 430 owner_loop_->PostTask(
430 FROM_HERE, 431 FROM_HERE,
431 base::Bind(&RequestProxy::NotifyCompletedRequest, this, status, 432 base::Bind(&RequestProxy::NotifyCompletedRequest, this, status,
432 security_info, complete_time)); 433 security_info, complete_time));
433 } 434 }
434 435
435 // -------------------------------------------------------------------------- 436 // --------------------------------------------------------------------------
436 // net::URLRequest::Delegate implementation: 437 // net::URLRequest::Delegate implementation:
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 if (upload_progress_timer_.IsRunning()) { 513 if (upload_progress_timer_.IsRunning()) {
513 MaybeUpdateUploadProgress(); 514 MaybeUpdateUploadProgress();
514 upload_progress_timer_.Stop(); 515 upload_progress_timer_.Stop();
515 } 516 }
516 DCHECK(request_.get()); 517 DCHECK(request_.get());
517 // If |failed_file_request_status_| is not empty, which means the request 518 // If |failed_file_request_status_| is not empty, which means the request
518 // was a file request and encountered an error, then we need to use the 519 // was a file request and encountered an error, then we need to use the
519 // |failed_file_request_status_|. Otherwise use request_'s status. 520 // |failed_file_request_status_|. Otherwise use request_'s status.
520 OnCompletedRequest(failed_file_request_status_.get() ? 521 OnCompletedRequest(failed_file_request_status_.get() ?
521 *failed_file_request_status_ : request_->status(), 522 *failed_file_request_status_ : request_->status(),
522 std::string(), base::Time()); 523 std::string(), base::TimeTicks());
523 request_.reset(); // destroy on the io thread 524 request_.reset(); // destroy on the io thread
524 } 525 }
525 526
526 // Called on the IO thread. 527 // Called on the IO thread.
527 void MaybeUpdateUploadProgress() { 528 void MaybeUpdateUploadProgress() {
528 // If a redirect is received upload is cancelled in net::URLRequest, we 529 // If a redirect is received upload is cancelled in net::URLRequest, we
529 // should try to stop the |upload_progress_timer_| timer and return. 530 // should try to stop the |upload_progress_timer_| timer and return.
530 if (!request_->has_upload()) { 531 if (!request_->has_upload()) {
531 if (upload_progress_timer_.IsRunning()) 532 if (upload_progress_timer_.IsRunning())
532 upload_progress_timer_.Stop(); 533 upload_progress_timer_.Stop();
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 virtual void OnReceivedData(int bytes_read) { 725 virtual void OnReceivedData(int bytes_read) {
725 if (download_to_file_) 726 if (download_to_file_)
726 file_stream_.Write(buf_->data(), bytes_read, net::CompletionCallback()); 727 file_stream_.Write(buf_->data(), bytes_read, net::CompletionCallback());
727 else 728 else
728 result_->data.append(buf_->data(), bytes_read); 729 result_->data.append(buf_->data(), bytes_read);
729 AsyncReadData(); // read more (may recurse) 730 AsyncReadData(); // read more (may recurse)
730 } 731 }
731 732
732 virtual void OnCompletedRequest(const net::URLRequestStatus& status, 733 virtual void OnCompletedRequest(const net::URLRequestStatus& status,
733 const std::string& security_info, 734 const std::string& security_info,
734 const base::Time& complete_time) { 735 const base::TimeTicks& complete_time) {
735 if (download_to_file_) 736 if (download_to_file_)
736 file_stream_.Close(); 737 file_stream_.Close();
737 result_->status = status; 738 result_->status = status;
738 event_.Signal(); 739 event_.Signal();
739 } 740 }
740 741
741 private: 742 private:
742 ResourceLoaderBridge::SyncLoadResponse* result_; 743 ResourceLoaderBridge::SyncLoadResponse* result_;
743 base::WaitableEvent event_; 744 base::WaitableEvent event_;
744 }; 745 };
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 1041
1041 // static 1042 // static
1042 void SimpleResourceLoaderBridge::AllowFileOverHTTP( 1043 void SimpleResourceLoaderBridge::AllowFileOverHTTP(
1043 const std::string& file_path_template, const GURL& http_prefix) { 1044 const std::string& file_path_template, const GURL& http_prefix) {
1044 DCHECK(!file_path_template.empty()); 1045 DCHECK(!file_path_template.empty());
1045 DCHECK(http_prefix.is_valid() && 1046 DCHECK(http_prefix.is_valid() &&
1046 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https"))); 1047 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https")));
1047 g_file_over_http_params = new FileOverHTTPParams(file_path_template, 1048 g_file_over_http_params = new FileOverHTTPParams(file_path_template,
1048 http_prefix); 1049 http_prefix);
1049 } 1050 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698