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

Side by Side Diff: content/common/resource_dispatcher.cc

Issue 7601011: Fix resource loads dropped when iframe is transferred to a new window and original window closes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix crash in tests (RenderThread::current() is NULL) Created 9 years, 4 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
« no previous file with comments | « content/common/resource_dispatcher.h ('k') | content/common/resource_dispatcher_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) 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading
6 6
7 #include "content/common/resource_dispatcher.h" 7 #include "content/common/resource_dispatcher.h"
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 // it's guaranteed to outlive the bridge. 61 // it's guaranteed to outlive the bridge.
62 ResourceDispatcher* dispatcher_; 62 ResourceDispatcher* dispatcher_;
63 63
64 // The request to send, created on initialization for modification and 64 // The request to send, created on initialization for modification and
65 // appending data. 65 // appending data.
66 ResourceHostMsg_Request request_; 66 ResourceHostMsg_Request request_;
67 67
68 // ID for the request, valid once Start()ed, -1 if not valid yet. 68 // ID for the request, valid once Start()ed, -1 if not valid yet.
69 int request_id_; 69 int request_id_;
70 70
71 // For some requests, WebKit assigns an identifier which is used in certain
72 // callbacks. Example: when a loading resource is transferred between pages.
73 int webkit_request_identifier_;
74
71 // The routing id used when sending IPC messages. 75 // The routing id used when sending IPC messages.
72 int routing_id_; 76 int routing_id_;
73 }; 77 };
74 78
75 IPCResourceLoaderBridge::IPCResourceLoaderBridge( 79 IPCResourceLoaderBridge::IPCResourceLoaderBridge(
76 ResourceDispatcher* dispatcher, 80 ResourceDispatcher* dispatcher,
77 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) 81 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info)
78 : peer_(NULL), 82 : peer_(NULL),
79 dispatcher_(dispatcher), 83 dispatcher_(dispatcher),
80 request_id_(-1), 84 request_id_(-1),
85 webkit_request_identifier_(request_info.identifier),
81 routing_id_(request_info.routing_id) { 86 routing_id_(request_info.routing_id) {
82 DCHECK(dispatcher_) << "no resource dispatcher"; 87 DCHECK(dispatcher_) << "no resource dispatcher";
83 request_.method = request_info.method; 88 request_.method = request_info.method;
84 request_.url = request_info.url; 89 request_.url = request_info.url;
85 request_.first_party_for_cookies = request_info.first_party_for_cookies; 90 request_.first_party_for_cookies = request_info.first_party_for_cookies;
86 request_.referrer = request_info.referrer; 91 request_.referrer = request_info.referrer;
87 request_.headers = request_info.headers; 92 request_.headers = request_info.headers;
88 request_.load_flags = request_info.load_flags; 93 request_.load_flags = request_info.load_flags;
89 request_.origin_pid = request_info.requestor_pid; 94 request_.origin_pid = request_info.requestor_pid;
90 request_.resource_type = request_info.request_type; 95 request_.resource_type = request_info.request_type;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 bool IPCResourceLoaderBridge::Start(Peer* peer) { 160 bool IPCResourceLoaderBridge::Start(Peer* peer) {
156 if (request_id_ != -1) { 161 if (request_id_ != -1) {
157 NOTREACHED() << "Starting a request twice"; 162 NOTREACHED() << "Starting a request twice";
158 return false; 163 return false;
159 } 164 }
160 165
161 peer_ = peer; 166 peer_ = peer;
162 167
163 // generate the request ID, and append it to the message 168 // generate the request ID, and append it to the message
164 request_id_ = dispatcher_->AddPendingRequest( 169 request_id_ = dispatcher_->AddPendingRequest(
165 peer_, request_.resource_type, request_.url); 170 webkit_request_identifier_, peer_, request_.resource_type, request_.url);
166 171
167 return dispatcher_->message_sender()->Send( 172 return dispatcher_->message_sender()->Send(
168 new ResourceHostMsg_RequestResource(routing_id_, request_id_, request_)); 173 new ResourceHostMsg_RequestResource(routing_id_, request_id_, request_));
169 } 174 }
170 175
171 void IPCResourceLoaderBridge::Cancel() { 176 void IPCResourceLoaderBridge::Cancel() {
172 if (request_id_ < 0) { 177 if (request_id_ < 0) {
173 NOTREACHED() << "Trying to cancel an unstarted request"; 178 NOTREACHED() << "Trying to cancel an unstarted request";
174 return; 179 return;
175 } 180 }
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 request_info->peer = new_peer; 432 request_info->peer = new_peer;
428 } 433 }
429 434
430 // The request ID will be removed from our pending list in the destructor. 435 // The request ID will be removed from our pending list in the destructor.
431 // Normally, dispatching this message causes the reference-counted request to 436 // Normally, dispatching this message causes the reference-counted request to
432 // die immediately. 437 // die immediately.
433 peer->OnCompletedRequest(status, security_info, completion_time); 438 peer->OnCompletedRequest(status, security_info, completion_time);
434 } 439 }
435 440
436 int ResourceDispatcher::AddPendingRequest( 441 int ResourceDispatcher::AddPendingRequest(
442 int webkit_request_id,
437 webkit_glue::ResourceLoaderBridge::Peer* callback, 443 webkit_glue::ResourceLoaderBridge::Peer* callback,
438 ResourceType::Type resource_type, 444 ResourceType::Type resource_type,
439 const GURL& request_url) { 445 const GURL& request_url) {
440 // Compute a unique request_id for this renderer process. 446 // Compute a unique request_id for this renderer process.
441 int id = MakeRequestID(); 447 int id = MakeRequestID();
442 pending_requests_[id] = 448 pending_requests_[id] =
443 PendingRequestInfo(callback, resource_type, request_url); 449 PendingRequestInfo(webkit_request_id,
450 callback,
451 resource_type,
452 request_url);
444 return id; 453 return id;
445 } 454 }
446 455
447 bool ResourceDispatcher::RemovePendingRequest(int request_id) { 456 bool ResourceDispatcher::RemovePendingRequest(int request_id) {
448 PendingRequestList::iterator it = pending_requests_.find(request_id); 457 PendingRequestList::iterator it = pending_requests_.find(request_id);
449 if (it == pending_requests_.end()) 458 if (it == pending_requests_.end())
450 return false; 459 return false;
451 460
452 PendingRequestInfo& request_info = it->second; 461 PendingRequestInfo& request_info = it->second;
453 ReleaseResourcesInMessageQueue(&request_info.deferred_message_queue); 462 ReleaseResourcesInMessageQueue(&request_info.deferred_message_queue);
(...skipping 11 matching lines...) Expand all
465 } 474 }
466 475
467 PendingRequestInfo& request_info = it->second; 476 PendingRequestInfo& request_info = it->second;
468 ReleaseResourcesInMessageQueue(&request_info.deferred_message_queue); 477 ReleaseResourcesInMessageQueue(&request_info.deferred_message_queue);
469 pending_requests_.erase(it); 478 pending_requests_.erase(it);
470 479
471 message_sender()->Send( 480 message_sender()->Send(
472 new ResourceHostMsg_CancelRequest(routing_id, request_id)); 481 new ResourceHostMsg_CancelRequest(routing_id, request_id));
473 } 482 }
474 483
484 void ResourceDispatcher::TransferRequestToNewPage(int webkit_identifier,
485 int new_routing_id) {
486 DCHECK(webkit_identifier > 0) << "Attempt to transfer request w/o identifier";
487 for(PendingRequestList::iterator it = pending_requests_.begin();
488 it != pending_requests_.end(); ++it) {
489 PendingRequestInfo& request_info = it->second;
490 if (request_info.webkit_request_id == webkit_identifier) {
491 int request_id = it->first;
492 message_sender()->Send(
493 new ResourceHostMsg_TransferRequestToNewPage(new_routing_id,
494 request_id));
495 }
496 }
497 }
498
475 void ResourceDispatcher::SetDefersLoading(int request_id, bool value) { 499 void ResourceDispatcher::SetDefersLoading(int request_id, bool value) {
476 PendingRequestList::iterator it = pending_requests_.find(request_id); 500 PendingRequestList::iterator it = pending_requests_.find(request_id);
477 if (it == pending_requests_.end()) { 501 if (it == pending_requests_.end()) {
478 DLOG(ERROR) << "unknown request"; 502 DLOG(ERROR) << "unknown request";
479 return; 503 return;
480 } 504 }
481 PendingRequestInfo& request_info = it->second; 505 PendingRequestInfo& request_info = it->second;
482 if (value) { 506 if (value) {
483 request_info.is_deferred = value; 507 request_info.is_deferred = value;
484 } else if (request_info.is_deferred) { 508 } else if (request_info.is_deferred) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 608
585 // static 609 // static
586 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { 610 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) {
587 while (!queue->empty()) { 611 while (!queue->empty()) {
588 IPC::Message* message = queue->front(); 612 IPC::Message* message = queue->front();
589 ReleaseResourcesInDataMessage(*message); 613 ReleaseResourcesInDataMessage(*message);
590 queue->pop_front(); 614 queue->pop_front();
591 delete message; 615 delete message;
592 } 616 }
593 } 617 }
OLDNEW
« no previous file with comments | « content/common/resource_dispatcher.h ('k') | content/common/resource_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698