summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-24 05:19:13 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-24 05:19:13 +0000
commit61b4a61bf1ea2a610c076cb28de59aa1137b3c4f (patch)
tree4a2b6465bcea096b8410c1e0a5dbb279fa34c1ba /chrome/browser
parent4e5ae20ff403cdcd14d3b86b18a0d0bcec2f47cc (diff)
downloadchromium_src-61b4a61bf1ea2a610c076cb28de59aa1137b3c4f.zip
chromium_src-61b4a61bf1ea2a610c076cb28de59aa1137b3c4f.tar.gz
chromium_src-61b4a61bf1ea2a610c076cb28de59aa1137b3c4f.tar.bz2
Revert 60378 (trying to track down http://crbug.com/56752 )- Flesh out URLLoader's download_to_file function.
* tie the lifetime of the resulting temp file to the lifetime of the URLLoader (the plan is to later extend the lifetime of the temp file to support xhr.responseBlob) * make it work in test_shell * make it work for sync requests * added OnDataDownloaded messages to report progress A related BlobURL loading change. * grab a reference to the blob early on to ensure it's still there when the 'job' is finally started. TEST=manual and deletable_file_reference_unittest.cc BUG=52486 Review URL: http://codereview.chromium.org/3165062 TBR=michaeln@chromium.org Review URL: http://codereview.chromium.org/3455022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60425 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/net/blob_url_request_job_factory.cc20
-rw-r--r--chrome/browser/renderer_host/async_resource_handler.cc6
-rw-r--r--chrome/browser/renderer_host/async_resource_handler.h1
-rw-r--r--chrome/browser/renderer_host/redirect_to_file_resource_handler.cc32
-rw-r--r--chrome/browser/renderer_host/redirect_to_file_resource_handler.h9
-rw-r--r--chrome/browser/renderer_host/resource_dispatcher_host.cc50
-rw-r--r--chrome/browser/renderer_host/resource_dispatcher_host.h24
-rw-r--r--chrome/browser/renderer_host/resource_dispatcher_host_request_info.cc6
-rw-r--r--chrome/browser/renderer_host/resource_dispatcher_host_request_info.h12
-rw-r--r--chrome/browser/renderer_host/resource_handler.h6
-rw-r--r--chrome/browser/renderer_host/sync_resource_handler.cc1
11 files changed, 24 insertions, 143 deletions
diff --git a/chrome/browser/net/blob_url_request_job_factory.cc b/chrome/browser/net/blob_url_request_job_factory.cc
index 7297795..dab29d5 100644
--- a/chrome/browser/net/blob_url_request_job_factory.cc
+++ b/chrome/browser/net/blob_url_request_job_factory.cc
@@ -7,8 +7,6 @@
#include "chrome/browser/chrome_blob_storage_context.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/net/chrome_url_request_context.h"
-#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
-#include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h"
#include "chrome/common/url_constants.h"
#include "webkit/blob/blob_storage_controller.h"
#include "webkit/blob/blob_url_request_job.h"
@@ -17,20 +15,12 @@ namespace {
URLRequestJob* BlobURLRequestJobFactory(URLRequest* request,
const std::string& scheme) {
- scoped_refptr<webkit_blob::BlobData> data;
- ResourceDispatcherHostRequestInfo* info =
- ResourceDispatcherHost::InfoForRequest(request);
- if (info) {
- // Resource dispatcher host already looked up the blob data.
- data = info->requested_blob_data();
- } else {
- // This request is not coming thru resource dispatcher host.
- data = static_cast<ChromeURLRequestContext*>(request->context())->
- blob_storage_context()->
- controller()->GetBlobDataFromUrl(request->url());
- }
+ webkit_blob::BlobStorageController* blob_storage_controller =
+ static_cast<ChromeURLRequestContext*>(request->context())->
+ blob_storage_context()->controller();
return new webkit_blob::BlobURLRequestJob(
- request, data,
+ request,
+ blob_storage_controller->GetBlobDataFromUrl(request->url()),
ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE));
}
diff --git a/chrome/browser/renderer_host/async_resource_handler.cc b/chrome/browser/renderer_host/async_resource_handler.cc
index 803b91b..5e5dfa5 100644
--- a/chrome/browser/renderer_host/async_resource_handler.cc
+++ b/chrome/browser/renderer_host/async_resource_handler.cc
@@ -217,12 +217,6 @@ bool AsyncResourceHandler::OnReadCompleted(int request_id, int* bytes_read) {
return true;
}
-void AsyncResourceHandler::OnDataDownloaded(
- int request_id, int bytes_downloaded) {
- receiver_->Send(new ViewMsg_Resource_DataDownloaded(
- routing_id_, request_id, bytes_downloaded));
-}
-
bool AsyncResourceHandler::OnResponseCompleted(
int request_id,
const URLRequestStatus& status,
diff --git a/chrome/browser/renderer_host/async_resource_handler.h b/chrome/browser/renderer_host/async_resource_handler.h
index be89d87..191fdb8 100644
--- a/chrome/browser/renderer_host/async_resource_handler.h
+++ b/chrome/browser/renderer_host/async_resource_handler.h
@@ -38,7 +38,6 @@ class AsyncResourceHandler : public ResourceHandler {
const URLRequestStatus& status,
const std::string& security_info);
void OnRequestClosed();
- void OnDataDownloaded(int request_id, int bytes_downloaded);
static void GlobalCleanup();
diff --git a/chrome/browser/renderer_host/redirect_to_file_resource_handler.cc b/chrome/browser/renderer_host/redirect_to_file_resource_handler.cc
index 94a5c77..b1470b1 100644
--- a/chrome/browser/renderer_host/redirect_to_file_resource_handler.cc
+++ b/chrome/browser/renderer_host/redirect_to_file_resource_handler.cc
@@ -16,9 +16,6 @@
#include "net/base/io_buffer.h"
#include "net/base/mime_sniffer.h"
#include "net/base/net_errors.h"
-#include "webkit/blob/deletable_file_reference.h"
-
-using webkit_blob::DeletableFileReference;
// TODO(darin): Use the buffer sizing algorithm from AsyncResourceHandler.
static const int kReadBufSize = 32768;
@@ -59,8 +56,8 @@ bool RedirectToFileResourceHandler::OnResponseStarted(
int request_id,
ResourceResponse* response) {
if (response->response_head.status.is_success()) {
- DCHECK(deletable_file_ && !deletable_file_->path().empty());
- response->response_head.download_file_path = deletable_file_->path();
+ DCHECK(!file_path_.empty());
+ response->response_head.download_file_path = file_path_;
}
return next_handler_->OnResponseStarted(request_id, response);
}
@@ -69,7 +66,7 @@ bool RedirectToFileResourceHandler::OnWillStart(int request_id,
const GURL& url,
bool* defer) {
request_id_ = request_id;
- if (!deletable_file_) {
+ if (file_path_.empty()) {
// Defer starting the request until we have created the temporary file.
// TODO(darin): This is sub-optimal. We should not delay starting the
// network request like this.
@@ -126,9 +123,6 @@ bool RedirectToFileResourceHandler::OnReadCompleted(int request_id,
if (BufIsFull())
host_->PauseRequest(process_id_, request_id, true);
- if (*bytes_read > 0)
- next_handler_->OnDataDownloaded(request_id, *bytes_read);
-
return WriteMore();
}
@@ -140,13 +134,21 @@ bool RedirectToFileResourceHandler::OnResponseCompleted(
}
void RedirectToFileResourceHandler::OnRequestClosed() {
+ next_handler_->OnRequestClosed();
+
+ // The renderer no longer has a WebURLLoader open to this request, so we can
+ // close and unlink the file.
+
// We require this explicit call to Close since file_stream_ was constructed
// directly from a PlatformFile.
file_stream_->Close();
file_stream_.reset();
- deletable_file_ = NULL;
- next_handler_->OnRequestClosed();
+ // TODO(dumi): delete the temp file when it's no longer needed.
+ // TODO(dumi): revoke the privilege to upload this file.
+ // base::FileUtilProxy::Delete(
+ // ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
+ // file_path_, NULL);
}
RedirectToFileResourceHandler::~RedirectToFileResourceHandler() {
@@ -157,14 +159,12 @@ void RedirectToFileResourceHandler::DidCreateTemporaryFile(
base::PlatformFileError /*error_code*/,
base::PassPlatformFile file_handle,
FilePath file_path) {
- deletable_file_ = DeletableFileReference::GetOrCreate(
- file_path,
- ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE));
+ file_path_ = file_path;
file_stream_.reset(new net::FileStream(file_handle.ReleaseValue(),
base::PLATFORM_FILE_WRITE |
base::PLATFORM_FILE_ASYNC));
- host_->RegisterDownloadedTempFile(
- process_id_, request_id_, deletable_file_.get());
+ ChildProcessSecurityPolicy::GetInstance()->GrantUploadFile(
+ process_id_, file_path);
host_->StartDeferredRequest(process_id_, request_id_);
}
diff --git a/chrome/browser/renderer_host/redirect_to_file_resource_handler.h b/chrome/browser/renderer_host/redirect_to_file_resource_handler.h
index 4929711..0e82e3b 100644
--- a/chrome/browser/renderer_host/redirect_to_file_resource_handler.h
+++ b/chrome/browser/renderer_host/redirect_to_file_resource_handler.h
@@ -21,10 +21,6 @@ class FileStream;
class GrowableIOBuffer;
}
-namespace webkit_blob {
-class DeletableFileReference;
-}
-
// Redirects network data to a file. This is intended to be layered in front
// of either the AsyncResourceHandler or the SyncResourceHandler.
class RedirectToFileResourceHandler : public ResourceHandler {
@@ -75,14 +71,11 @@ class RedirectToFileResourceHandler : public ResourceHandler {
bool buf_write_pending_;
int write_cursor_;
+ FilePath file_path_;
scoped_ptr<net::FileStream> file_stream_;
net::CompletionCallbackImpl<RedirectToFileResourceHandler> write_callback_;
bool write_callback_pending_;
- // We create a DeletableFileReference for the temp file created as
- // a result of the download.
- scoped_refptr<webkit_blob::DeletableFileReference> deletable_file_;
-
DISALLOW_COPY_AND_ASSIGN(RedirectToFileResourceHandler);
};
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc
index 0cd78d59..899f077 100644
--- a/chrome/browser/renderer_host/resource_dispatcher_host.cc
+++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc
@@ -71,7 +71,6 @@
#include "webkit/appcache/appcache_interceptor.h"
#include "webkit/appcache/appcache_interfaces.h"
#include "webkit/blob/blob_storage_controller.h"
-#include "webkit/blob/deletable_file_reference.h"
// TODO(oshima): Enable this for other platforms.
#if defined(OS_CHROMEOS)
@@ -90,7 +89,6 @@
using base::Time;
using base::TimeDelta;
using base::TimeTicks;
-using webkit_blob::DeletableFileReference;
// ----------------------------------------------------------------------------
@@ -323,10 +321,7 @@ bool ResourceDispatcherHost::OnMessageReceived(const IPC::Message& message,
IPC_BEGIN_MESSAGE_MAP_EX(ResourceDispatcherHost, message, *message_was_ok)
IPC_MESSAGE_HANDLER(ViewHostMsg_RequestResource, OnRequestResource)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SyncLoad, OnSyncLoad)
- IPC_MESSAGE_HANDLER(ViewHostMsg_ResourceLoaderDeleted,
- OnResourceLoaderDeleted)
IPC_MESSAGE_HANDLER(ViewHostMsg_DataReceived_ACK, OnDataReceivedACK)
- IPC_MESSAGE_HANDLER(ViewHostMsg_DataDownloaded_ACK, OnDataDownloadedACK)
IPC_MESSAGE_HANDLER(ViewHostMsg_UploadProgress_ACK, OnUploadProgressACK)
IPC_MESSAGE_HANDLER(ViewHostMsg_CancelRequest, OnCancelRequest)
IPC_MESSAGE_HANDLER(ViewHostMsg_FollowRedirect, OnFollowRedirect)
@@ -380,7 +375,7 @@ void ResourceDispatcherHost::BeginRequest(
}
// Might need to resolve the blob references in the upload data.
- if (request_data.upload_data && context) {
+ if (request_data.upload_data) {
context->blob_storage_context()->controller()->
ResolveBlobReferencesInUploadData(request_data.upload_data.get());
}
@@ -428,7 +423,6 @@ void ResourceDispatcherHost::BeginRequest(
this);
}
- // The RedirectToFileResourceHandler depends on being next in the chain.
if (request_data.download_to_file)
handler = new RedirectToFileResourceHandler(handler, child_id, this);
@@ -523,15 +517,6 @@ void ResourceDispatcherHost::BeginRequest(
chrome_browser_net::SetOriginProcessUniqueIDForRequest(
request_data.origin_child_id, request);
- if (request->url().SchemeIs(chrome::kBlobScheme) && context) {
- // Hang on to a reference to ensure the blob is not released prior
- // to the job being started.
- webkit_blob::BlobStorageController* controller =
- context->blob_storage_context()->controller();
- extra_info->set_requested_blob_data(
- controller->GetBlobDataFromUrl(request->url()));
- }
-
// Have the appcache associate its extra info with the request.
appcache::AppCacheInterceptor::SetExtraRequestInfo(
request, context ? context->appcache_service() : NULL, child_id,
@@ -540,12 +525,6 @@ void ResourceDispatcherHost::BeginRequest(
BeginRequestInternal(request);
}
-void ResourceDispatcherHost::OnResourceLoaderDeleted(int request_id) {
- DCHECK(pending_requests_.end() ==
- pending_requests_.find(GlobalRequestID(receiver_->id(), request_id)));
- UnregisterDownloadedTempFile(receiver_->id(), request_id);
-}
-
void ResourceDispatcherHost::OnDataReceivedACK(int request_id) {
DataReceivedACK(receiver_->id(), request_id);
}
@@ -573,29 +552,6 @@ void ResourceDispatcherHost::DataReceivedACK(int child_id,
}
}
-void ResourceDispatcherHost::OnDataDownloadedACK(int request_id) {
- // TODO(michaeln): maybe throttle DataDownloaded messages
-}
-
-void ResourceDispatcherHost::RegisterDownloadedTempFile(
- int receiver_id, int request_id, DeletableFileReference* reference) {
- // Note: receiver_id is the child_id is the render_process_id...
- registered_temp_files_[receiver_id][request_id] = reference;
- ChildProcessSecurityPolicy::GetInstance()->GrantUploadFile(
- receiver_id, reference->path());
-}
-
-void ResourceDispatcherHost::UnregisterDownloadedTempFile(
- int receiver_id, int request_id) {
- DeletableFilesMap& map = registered_temp_files_[receiver_id];
- DeletableFilesMap::iterator found = map.find(request_id);
- if (found == map.end())
- return;
- map.erase(found);
- // TODO(michaeln): revoke access to this file upon the file's deletion.
-}
-
-
bool ResourceDispatcherHost::Send(IPC::Message* message) {
delete message;
return false;
@@ -891,7 +847,6 @@ int ResourceDispatcherHost::GetOutstandingRequestsMemoryCost(
void ResourceDispatcherHost::CancelRequestsForProcess(int child_id) {
socket_stream_dispatcher_host_->CancelRequestsForProcess(child_id);
CancelRequestsForRoute(child_id, -1 /* cancel all */);
- registered_temp_files_.erase(child_id);
}
void ResourceDispatcherHost::CancelRequestsForRoute(int child_id,
@@ -1843,9 +1798,8 @@ bool ResourceDispatcherHost::IsResourceDispatcherHostMessage(
case ViewHostMsg_CancelRequest::ID:
case ViewHostMsg_FollowRedirect::ID:
case ViewHostMsg_ClosePage_ACK::ID:
- case ViewHostMsg_ResourceLoaderDeleted::ID:
case ViewHostMsg_DataReceived_ACK::ID:
- case ViewHostMsg_DataDownloaded_ACK::ID:
+ case ViewHostMsg_DownloadProgress_ACK::ID:
case ViewHostMsg_UploadProgress_ACK::ID:
case ViewHostMsg_SyncLoad::ID:
return true;
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.h b/chrome/browser/renderer_host/resource_dispatcher_host.h
index 76b8df5..1878177 100644
--- a/chrome/browser/renderer_host/resource_dispatcher_host.h
+++ b/chrome/browser/renderer_host/resource_dispatcher_host.h
@@ -47,10 +47,6 @@ struct GlobalRequestID;
struct ViewHostMsg_Resource_Request;
struct ViewMsg_ClosePage_Params;
-namespace webkit_blob {
-class DeletableFileReference;
-}
-
class ResourceDispatcherHost : public URLRequest::Delegate {
public:
// Implemented by the client of ResourceDispatcherHost to receive messages in
@@ -268,15 +264,6 @@ class ResourceDispatcherHost : public URLRequest::Delegate {
// messages sent.
void DataReceivedACK(int process_unique_id, int request_id);
- // Maintains a collection of temp files created in support of
- // the download_to_file capability. Used to grant access to the
- // child process and to defer deletion of the file until it's
- // no longer needed.
- void RegisterDownloadedTempFile(
- int receiver_id, int request_id,
- webkit_blob::DeletableFileReference* reference);
- void UnregisterDownloadedTempFile(int receiver_id, int request_id);
-
// Needed for the sync IPC message dispatcher macros.
bool Send(IPC::Message* message);
@@ -410,13 +397,11 @@ class ResourceDispatcherHost : public URLRequest::Delegate {
IPC::Message* sync_result, // only valid for sync
int route_id); // only valid for async
void OnDataReceivedACK(int request_id);
- void OnDataDownloadedACK(int request_id);
void OnUploadProgressACK(int request_id);
void OnCancelRequest(int request_id);
void OnFollowRedirect(int request_id,
bool has_new_first_party_for_cookies,
const GURL& new_first_party_for_cookies);
- void OnResourceLoaderDeleted(int request_id);
ResourceHandler* CreateSafeBrowsingResourceHandler(
ResourceHandler* handler, int child_id, int route_id,
@@ -447,15 +432,6 @@ class ResourceDispatcherHost : public URLRequest::Delegate {
PendingRequestList pending_requests_;
- // Collection of temp files downloaded for child processes via
- // the download_to_file mechanism. We avoid deleting them until
- // the loader in the client has been deleted.
- typedef std::map<int, scoped_refptr<webkit_blob::DeletableFileReference> >
- DeletableFilesMap; // key is request id
- typedef std::map<int, DeletableFilesMap>
- RegisteredTempFiles; // key is child process id
- RegisteredTempFiles registered_temp_files_;
-
// A timer that periodically calls UpdateLoadStates while pending_requests_
// is not empty.
base::RepeatingTimer<ResourceDispatcherHost> update_load_states_timer_;
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host_request_info.cc b/chrome/browser/renderer_host/resource_dispatcher_host_request_info.cc
index 30ca189..eeac6f0 100644
--- a/chrome/browser/renderer_host/resource_dispatcher_host_request_info.cc
+++ b/chrome/browser/renderer_host/resource_dispatcher_host_request_info.cc
@@ -7,7 +7,6 @@
#include "chrome/browser/login_prompt.h"
#include "chrome/browser/renderer_host/resource_handler.h"
#include "chrome/browser/ssl/ssl_client_auth_handler.h"
-#include "webkit/blob/blob_data.h"
ResourceDispatcherHostRequestInfo::ResourceDispatcherHostRequestInfo(
ResourceHandler* handler,
@@ -62,8 +61,3 @@ void ResourceDispatcherHostRequestInfo::set_ssl_client_auth_handler(
SSLClientAuthHandler* s) {
ssl_client_auth_handler_ = s;
}
-
-void ResourceDispatcherHostRequestInfo::set_requested_blob_data(
- webkit_blob::BlobData* data) {
- requested_blob_data_ = data;
-}
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host_request_info.h b/chrome/browser/renderer_host/resource_dispatcher_host_request_info.h
index 9d5e386..f5b7535 100644
--- a/chrome/browser/renderer_host/resource_dispatcher_host_request_info.h
+++ b/chrome/browser/renderer_host/resource_dispatcher_host_request_info.h
@@ -21,10 +21,6 @@ class ResourceDispatcherHost;
class ResourceHandler;
class SSLClientAuthHandler;
-namespace webkit_blob {
-class BlobData;
-}
-
// Holds the data ResourceDispatcherHost associates with each request.
// Retrieve this data by calling ResourceDispatcherHost::InfoForRequest.
class ResourceDispatcherHostRequestInfo : public URLRequest::UserData {
@@ -164,13 +160,6 @@ class ResourceDispatcherHostRequestInfo : public URLRequest::UserData {
int host_renderer_id() const { return host_renderer_id_; }
int host_render_view_id() const { return host_render_view_id_; }
- // We hold a reference to the requested blob data to ensure it doesn't
- // get finally released prior to the URLRequestJob being started.
- webkit_blob::BlobData* requested_blob_data() const {
- return requested_blob_data_.get();
- }
- void set_requested_blob_data(webkit_blob::BlobData* data);
-
private:
friend class ResourceDispatcherHost;
@@ -225,7 +214,6 @@ class ResourceDispatcherHostRequestInfo : public URLRequest::UserData {
base::TimeTicks last_upload_ticks_;
bool waiting_for_upload_progress_ack_;
int memory_cost_;
- scoped_refptr<webkit_blob::BlobData> requested_blob_data_;
// "Private" data accessible only to ResourceDispatcherHost (use the
// accessors above for consistency).
diff --git a/chrome/browser/renderer_host/resource_handler.h b/chrome/browser/renderer_host/resource_handler.h
index b6758ae..a03e50d 100644
--- a/chrome/browser/renderer_host/resource_handler.h
+++ b/chrome/browser/renderer_host/resource_handler.h
@@ -80,12 +80,6 @@ class ResourceHandler
// This is a signal that the associated URLRequest isn't valid anymore.
virtual void OnRequestClosed() = 0;
- // This notification is synthesized by the RedirectToFileResourceHandler
- // to indicate progress of 'download_to_file' requests. OnReadCompleted
- // calls are consumed by the RedirectToFileResourceHandler and replaced
- // with OnDataDownloaded calls.
- virtual void OnDataDownloaded(int request_id, int bytes_downloaded) {}
-
protected:
friend class ChromeThread;
friend class DeleteTask<ResourceHandler>;
diff --git a/chrome/browser/renderer_host/sync_resource_handler.cc b/chrome/browser/renderer_host/sync_resource_handler.cc
index 16c057a..6638084 100644
--- a/chrome/browser/renderer_host/sync_resource_handler.cc
+++ b/chrome/browser/renderer_host/sync_resource_handler.cc
@@ -63,7 +63,6 @@ bool SyncResourceHandler::OnResponseStarted(int request_id,
result_.headers = response->response_head.headers;
result_.mime_type = response->response_head.mime_type;
result_.charset = response->response_head.charset;
- result_.download_file_path = response->response_head.download_file_path;
result_.request_time = response->response_head.request_time;
result_.response_time = response->response_head.response_time;
result_.connection_id = response->response_head.connection_id;