diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-28 08:04:45 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-28 08:04:45 +0000 |
commit | c0dac327638b6e975dda0dc9d4d538f07ea161e5 (patch) | |
tree | 31830e8c9bd558ba8b1812701ced769d632255b1 /webkit/glue | |
parent | b29bd2338b14010216c273595bb15401f2382342 (diff) | |
download | chromium_src-c0dac327638b6e975dda0dc9d4d538f07ea161e5.zip chromium_src-c0dac327638b6e975dda0dc9d4d538f07ea161e5.tar.gz chromium_src-c0dac327638b6e975dda0dc9d4d538f07ea161e5.tar.bz2 |
Initial stream to file implementation.
This patch excludes one important detail. This code does not cleanup temp
files yet. That will be added in a subsequent CL.
R=brettw
BUG=49789
TEST=third_party/ppapi/tests/test_url_loader.cc:TestStreamToFile
Review URL: http://codereview.chromium.org/2806079
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53923 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r-- | webkit/glue/plugins/pepper_url_loader.cc | 42 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_url_loader.h | 3 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_url_response_info.cc | 2 |
3 files changed, 38 insertions, 9 deletions
diff --git a/webkit/glue/plugins/pepper_url_loader.cc b/webkit/glue/plugins/pepper_url_loader.cc index 669ce0d..26dadad 100644 --- a/webkit/glue/plugins/pepper_url_loader.cc +++ b/webkit/glue/plugins/pepper_url_loader.cc @@ -122,6 +122,15 @@ int32_t ReadResponseBody(PP_Resource loader_id, return loader->ReadResponseBody(buffer, bytes_to_read, callback); } +int32_t FinishStreamingToFile(PP_Resource loader_id, + PP_CompletionCallback callback) { + scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); + if (!loader) + return PP_ERROR_BADRESOURCE; + + return loader->FinishStreamingToFile(callback); +} + void Close(PP_Resource loader_id) { scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); if (!loader) @@ -139,6 +148,7 @@ const PPB_URLLoader ppb_urlloader = { &GetDownloadProgress, &GetResponseInfo, &ReadResponseBody, + &FinishStreamingToFile, &Close }; @@ -154,7 +164,7 @@ URLLoader::URLLoader(PluginInstance* instance) total_bytes_to_be_received_(-1), user_buffer_(NULL), user_buffer_size_(0), - done_(false) { + done_status_(PP_ERROR_WOULDBLOCK) { } URLLoader::~URLLoader() { @@ -200,6 +210,8 @@ int32_t URLLoader::FollowRedirect(PP_CompletionCallback callback) { int32_t URLLoader::ReadResponseBody(char* buffer, int32_t bytes_to_read, PP_CompletionCallback callback) { + if (!response_info_ || response_info_->body()) + return PP_ERROR_FAILED; if (bytes_to_read <= 0 || !buffer) return PP_ERROR_BADARGUMENT; if (pending_callback_.func) @@ -215,16 +227,32 @@ int32_t URLLoader::ReadResponseBody(char* buffer, int32_t bytes_to_read, if (!buffer_.empty()) return FillUserBuffer(); - if (done_) { + // We may have already reached EOF. + if (done_status_ != PP_ERROR_WOULDBLOCK) { user_buffer_ = NULL; user_buffer_size_ = 0; - return 0; + return done_status_; } pending_callback_ = callback; return PP_ERROR_WOULDBLOCK; } +int32_t URLLoader::FinishStreamingToFile(PP_CompletionCallback callback) { + if (!response_info_ || !response_info_->body()) + return PP_ERROR_FAILED; + if (pending_callback_.func) + return PP_ERROR_INPROGRESS; + + // We may have already reached EOF. + if (done_status_ != PP_ERROR_WOULDBLOCK) + return done_status_; + + // Wait for didFinishLoading / didFail. + pending_callback_ = callback; + return PP_ERROR_WOULDBLOCK; +} + void URLLoader::Close() { NOTIMPLEMENTED(); // TODO(darin): Implement me. } @@ -274,14 +302,14 @@ void URLLoader::didReceiveData(WebURLLoader* loader, } void URLLoader::didFinishLoading(WebURLLoader* loader) { - done_ = true; - RunCallback(PP_OK); + done_status_ = PP_OK; + RunCallback(done_status_); } void URLLoader::didFail(WebURLLoader* loader, const WebURLError& error) { - done_ = true; // TODO(darin): Provide more detailed error information. - RunCallback(PP_ERROR_FAILED); + done_status_ = PP_ERROR_FAILED; + RunCallback(done_status_); } void URLLoader::RunCallback(int32_t result) { diff --git a/webkit/glue/plugins/pepper_url_loader.h b/webkit/glue/plugins/pepper_url_loader.h index d0d70f1..5cf3e81 100644 --- a/webkit/glue/plugins/pepper_url_loader.h +++ b/webkit/glue/plugins/pepper_url_loader.h @@ -38,6 +38,7 @@ class URLLoader : public Resource, public WebKit::WebURLLoaderClient { int32_t FollowRedirect(PP_CompletionCallback callback); int32_t ReadResponseBody(char* buffer, int32_t bytes_to_read, PP_CompletionCallback callback); + int32_t FinishStreamingToFile(PP_CompletionCallback callback); void Close(); // WebKit::WebURLLoaderClient implementation. @@ -83,7 +84,7 @@ class URLLoader : public Resource, public WebKit::WebURLLoaderClient { int64_t total_bytes_to_be_received_; char* user_buffer_; size_t user_buffer_size_; - bool done_; + int32_t done_status_; }; } // namespace pepper diff --git a/webkit/glue/plugins/pepper_url_response_info.cc b/webkit/glue/plugins/pepper_url_response_info.cc index fab8cae..878fed5 100644 --- a/webkit/glue/plugins/pepper_url_response_info.cc +++ b/webkit/glue/plugins/pepper_url_response_info.cc @@ -110,7 +110,7 @@ bool URLResponseInfo::Initialize(const WebURLResponse& response) { headers_ = flattener.buffer(); WebString file_path = response.downloadFilePath(); - if (!file_path.isNull()) + if (!file_path.isEmpty()) body_ = new FileRef(module(), webkit_glue::WebStringToFilePath(file_path)); return true; } |