| Index: chrome/common/resource_dispatcher.cc
|
| ===================================================================
|
| --- chrome/common/resource_dispatcher.cc (revision 60837)
|
| +++ chrome/common/resource_dispatcher.cc (working copy)
|
| @@ -143,6 +143,11 @@
|
| // this operation may fail, as the dispatcher will have preemptively
|
| // removed us when the renderer sends the ReceivedAllData message.
|
| dispatcher_->RemovePendingRequest(request_id_);
|
| +
|
| + if (request_.download_to_file) {
|
| + dispatcher_->message_sender()->Send(
|
| + new ViewHostMsg_ReleaseDownloadedFile(request_id_));
|
| + }
|
| }
|
| }
|
|
|
| @@ -260,6 +265,7 @@
|
| response->connection_reused = result.connection_reused;
|
| response->load_timing = result.load_timing;
|
| response->data.swap(result.data);
|
| + response->download_file_path = result.download_file_path;
|
| }
|
|
|
| } // namespace webkit_glue
|
| @@ -289,30 +295,26 @@
|
| return true;
|
| }
|
|
|
| - PendingRequestList::iterator it = pending_requests_.find(request_id);
|
| - if (it == pending_requests_.end()) {
|
| - // This might happen for kill()ed requests on the webkit end, so perhaps it
|
| - // shouldn't be a warning...
|
| - DLOG(WARNING) << "Got response for a nonexistent or finished request";
|
| + PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
|
| + if (!request_info) {
|
| // Release resources in the message if it is a data message.
|
| ReleaseResourcesInDataMessage(message);
|
| return true;
|
| }
|
|
|
| - PendingRequestInfo& request_info = it->second;
|
| - if (request_info.is_deferred) {
|
| - request_info.deferred_message_queue.push_back(new IPC::Message(message));
|
| + if (request_info->is_deferred) {
|
| + request_info->deferred_message_queue.push_back(new IPC::Message(message));
|
| return true;
|
| }
|
| // Make sure any deferred messages are dispatched before we dispatch more.
|
| - if (!request_info.deferred_message_queue.empty()) {
|
| + if (!request_info->deferred_message_queue.empty()) {
|
| FlushDeferredMessages(request_id);
|
| // The request could have been deferred now. If yes then the current
|
| // message has to be queued up. The request_info instance should remain
|
| // valid here as there are pending messages for it.
|
| DCHECK(pending_requests_.find(request_id) != pending_requests_.end());
|
| - if (request_info.is_deferred) {
|
| - request_info.deferred_message_queue.push_back(new IPC::Message(message));
|
| + if (request_info->is_deferred) {
|
| + request_info->deferred_message_queue.push_back(new IPC::Message(message));
|
| return true;
|
| }
|
| }
|
| @@ -321,22 +323,27 @@
|
| return true;
|
| }
|
|
|
| -void ResourceDispatcher::OnUploadProgress(
|
| - const IPC::Message& message, int request_id, int64 position, int64 size) {
|
| +ResourceDispatcher::PendingRequestInfo*
|
| +ResourceDispatcher::GetPendingRequestInfo(int request_id) {
|
| PendingRequestList::iterator it = pending_requests_.find(request_id);
|
| if (it == pending_requests_.end()) {
|
| - // this might happen for kill()ed requests on the webkit end, so perhaps
|
| - // it shouldn't be a warning...
|
| - DLOG(WARNING) << "Got upload progress for a nonexistent or "
|
| - "finished request";
|
| - return;
|
| + // This might happen for kill()ed requests on the webkit end, so perhaps it
|
| + // shouldn't be a warning...
|
| + DLOG(WARNING) << "Received message for a nonexistent or finished request";
|
| + return NULL;
|
| }
|
| + return &(it->second);
|
| +}
|
|
|
| - PendingRequestInfo& request_info = it->second;
|
| +void ResourceDispatcher::OnUploadProgress(
|
| + const IPC::Message& message, int request_id, int64 position, int64 size) {
|
| + PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
|
| + if (!request_info)
|
| + return;
|
|
|
| RESOURCE_LOG("Dispatching upload progress for " <<
|
| - request_info.peer->GetURLForDebugging().possibly_invalid_spec());
|
| - request_info.peer->OnUploadProgress(position, size);
|
| + request_info->peer->GetURLForDebugging().possibly_invalid_spec());
|
| + request_info->peer->OnUploadProgress(position, size);
|
|
|
| // Acknowledge receipt
|
| message_sender()->Send(
|
| @@ -345,44 +352,34 @@
|
|
|
| void ResourceDispatcher::OnReceivedResponse(
|
| int request_id, const ResourceResponseHead& response_head) {
|
| - PendingRequestList::iterator it = pending_requests_.find(request_id);
|
| - if (it == pending_requests_.end()) {
|
| - // This might happen for kill()ed requests on the webkit end, so perhaps it
|
| - // shouldn't be a warning...
|
| - DLOG(WARNING) << "Got response for a nonexistent or finished request";
|
| + PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
|
| + if (!request_info)
|
| return;
|
| - }
|
|
|
| - PendingRequestInfo& request_info = it->second;
|
| if (response_head.replace_extension_localization_templates) {
|
| webkit_glue::ResourceLoaderBridge::Peer* new_peer =
|
| ExtensionLocalizationPeer::CreateExtensionLocalizationPeer(
|
| - request_info.peer, message_sender(), response_head.mime_type,
|
| - request_info.url);
|
| + request_info->peer, message_sender(), response_head.mime_type,
|
| + request_info->url);
|
| if (new_peer)
|
| - request_info.peer = new_peer;
|
| + request_info->peer = new_peer;
|
| }
|
|
|
| RESOURCE_LOG("Dispatching response for " <<
|
| - request_info.peer->GetURLForDebugging().possibly_invalid_spec());
|
| - request_info.peer->OnReceivedResponse(response_head, false);
|
| + request_info->peer->GetURLForDebugging().possibly_invalid_spec());
|
| + request_info->peer->OnReceivedResponse(response_head, false);
|
| }
|
|
|
| void ResourceDispatcher::OnReceivedCachedMetadata(
|
| int request_id, const std::vector<char>& data) {
|
| - PendingRequestList::iterator it = pending_requests_.find(request_id);
|
| - if (it == pending_requests_.end()) {
|
| - // this might happen for kill()ed requests on the webkit end, so perhaps
|
| - // it shouldn't be a warning...
|
| - DLOG(WARNING) << "Got metadata for a nonexistent or finished request";
|
| + PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
|
| + if (!request_info)
|
| return;
|
| - }
|
|
|
| if (data.size()) {
|
| - PendingRequestInfo& request_info = it->second;
|
| RESOURCE_LOG("Dispatching " << data.size() << " metadata bytes for " <<
|
| - request_info.peer->GetURLForDebugging().possibly_invalid_spec());
|
| - request_info.peer->OnReceivedCachedMetadata(&data.front(), data.size());
|
| + request_info->peer->GetURLForDebugging().possibly_invalid_spec());
|
| + request_info->peer->OnReceivedCachedMetadata(&data.front(), data.size());
|
| }
|
| }
|
|
|
| @@ -398,45 +395,50 @@
|
| DCHECK((shm_valid && data_len > 0) || (!shm_valid && !data_len));
|
| base::SharedMemory shared_mem(shm_handle, true); // read only
|
|
|
| - PendingRequestList::iterator it = pending_requests_.find(request_id);
|
| - if (it == pending_requests_.end()) {
|
| - // this might happen for kill()ed requests on the webkit end, so perhaps
|
| - // it shouldn't be a warning...
|
| - DLOG(WARNING) << "Got data for a nonexistent or finished request";
|
| + PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
|
| + if (!request_info)
|
| return;
|
| - }
|
|
|
| - PendingRequestInfo& request_info = it->second;
|
| -
|
| if (data_len > 0 && shared_mem.Map(data_len)) {
|
| RESOURCE_LOG("Dispatching " << data_len << " bytes for " <<
|
| - request_info.peer->GetURLForDebugging().possibly_invalid_spec());
|
| + request_info->peer->GetURLForDebugging().possibly_invalid_spec());
|
| const char* data = static_cast<char*>(shared_mem.memory());
|
| - request_info.peer->OnReceivedData(data, data_len);
|
| + request_info->peer->OnReceivedData(data, data_len);
|
| }
|
| }
|
|
|
| +void ResourceDispatcher::OnDownloadedData(const IPC::Message& message,
|
| + int request_id,
|
| + int data_len) {
|
| + // Acknowledge the reception of this message.
|
| + message_sender()->Send(
|
| + new ViewHostMsg_DataDownloaded_ACK(message.routing_id(), request_id));
|
| +
|
| + PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
|
| + if (!request_info)
|
| + return;
|
| +
|
| + RESOURCE_LOG("Dispatching " << data_len << " downloaded for " <<
|
| + request_info->peer->GetURLForDebugging().possibly_invalid_spec());
|
| + request_info->peer->OnDownloadedData(data_len);
|
| +}
|
| +
|
| void ResourceDispatcher::OnReceivedRedirect(
|
| const IPC::Message& message,
|
| int request_id,
|
| const GURL& new_url,
|
| const webkit_glue::ResourceLoaderBridge::ResponseInfo& info) {
|
| - PendingRequestList::iterator it = pending_requests_.find(request_id);
|
| - if (it == pending_requests_.end()) {
|
| - // this might happen for kill()ed requests on the webkit end, so perhaps
|
| - // it shouldn't be a warning...
|
| - DLOG(WARNING) << "Got data for a nonexistent or finished request";
|
| + PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
|
| + if (!request_info)
|
| return;
|
| - }
|
|
|
| - PendingRequestInfo& request_info = it->second;
|
| + RESOURCE_LOG(
|
| + "Dispatching redirect for " <<
|
| + request_info->peer->GetURLForDebugging().possibly_invalid_spec());
|
|
|
| - RESOURCE_LOG("Dispatching redirect for " <<
|
| - request_info.peer->GetURLForDebugging().possibly_invalid_spec());
|
| -
|
| bool has_new_first_party_for_cookies = false;
|
| GURL new_first_party_for_cookies;
|
| - if (request_info.peer->OnReceivedRedirect(new_url, info,
|
| + if (request_info->peer->OnReceivedRedirect(new_url, info,
|
| &has_new_first_party_for_cookies,
|
| &new_first_party_for_cookies)) {
|
| message_sender()->Send(
|
| @@ -452,30 +454,25 @@
|
| const URLRequestStatus& status,
|
| const std::string& security_info,
|
| const base::Time& completion_time) {
|
| - PendingRequestList::iterator it = pending_requests_.find(request_id);
|
| - if (it == pending_requests_.end()) {
|
| - // this might happen for kill()ed requests on the webkit end, so perhaps
|
| - // it shouldn't be a warning...
|
| - DLOG(WARNING) << "Got 'complete' for a nonexistent or finished request";
|
| + PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
|
| + if (!request_info)
|
| return;
|
| - }
|
|
|
| - PendingRequestInfo& request_info = it->second;
|
| - webkit_glue::ResourceLoaderBridge::Peer* peer = request_info.peer;
|
| + webkit_glue::ResourceLoaderBridge::Peer* peer = request_info->peer;
|
|
|
| RESOURCE_LOG("Dispatching complete for " <<
|
| - request_info.peer->GetURLForDebugging().possibly_invalid_spec());
|
| + peer->GetURLForDebugging().possibly_invalid_spec());
|
|
|
| if (status.status() == URLRequestStatus::CANCELED &&
|
| status.os_error() != net::ERR_ABORTED) {
|
| // Resource canceled with a specific error are filtered.
|
| SecurityFilterPeer* new_peer =
|
| SecurityFilterPeer::CreateSecurityFilterPeerForDeniedRequest(
|
| - request_info.resource_type,
|
| - request_info.peer,
|
| + request_info->resource_type,
|
| + request_info->peer,
|
| status.os_error());
|
| if (new_peer) {
|
| - request_info.peer = new_peer;
|
| + request_info->peer = new_peer;
|
| peer = new_peer;
|
| }
|
| }
|
| @@ -552,6 +549,7 @@
|
| ViewMsg_Resource_ReceivedCachedMetadata, OnReceivedCachedMetadata)
|
| IPC_MESSAGE_HANDLER(ViewMsg_Resource_ReceivedRedirect, OnReceivedRedirect)
|
| IPC_MESSAGE_HANDLER(ViewMsg_Resource_DataReceived, OnReceivedData)
|
| + IPC_MESSAGE_HANDLER(ViewMsg_Resource_DataDownloaded, OnDownloadedData)
|
| IPC_MESSAGE_HANDLER(ViewMsg_Resource_RequestComplete, OnRequestComplete)
|
| IPC_END_MESSAGE_MAP()
|
| }
|
| @@ -604,6 +602,7 @@
|
| case ViewMsg_Resource_ReceivedCachedMetadata::ID:
|
| case ViewMsg_Resource_ReceivedRedirect::ID:
|
| case ViewMsg_Resource_DataReceived::ID:
|
| + case ViewMsg_Resource_DataDownloaded::ID:
|
| case ViewMsg_Resource_RequestComplete::ID:
|
| return true;
|
|
|
|
|