summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--webkit/blob/blob_data.h19
-rw-r--r--webkit/blob/blob_storage_controller.cc96
-rw-r--r--webkit/blob/blob_storage_controller.h7
-rw-r--r--webkit/tools/test_shell/test_shell_webblobregistry_impl.cc13
4 files changed, 84 insertions, 51 deletions
diff --git a/webkit/blob/blob_data.h b/webkit/blob/blob_data.h
index ddd0e65..3be694f 100644
--- a/webkit/blob/blob_data.h
+++ b/webkit/blob/blob_data.h
@@ -12,6 +12,7 @@
#include "base/ref_counted.h"
#include "base/time.h"
#include "googleurl/src/gurl.h"
+#include "webkit/blob/deletable_file_reference.h"
namespace WebKit {
class WebBlobData;
@@ -117,14 +118,12 @@ class BlobData : public base::RefCounted<BlobData> {
items_.back().SetToBlob(blob_url, offset, length);
}
- const std::vector<Item>& items() const { return items_; }
- void set_items(const std::vector<Item>& items) {
- items_ = items;
- }
- void swap_items(std::vector<Item>* items) {
- items_.swap(*items);
+ void AttachDeletableFileReference(DeletableFileReference* reference) {
+ deletable_files_.push_back(reference);
}
+ const std::vector<Item>& items() const { return items_; }
+
const std::string& content_type() const { return content_type_; }
void set_content_type(const std::string& content_type) {
content_type_ = content_type;
@@ -137,6 +136,11 @@ class BlobData : public base::RefCounted<BlobData> {
content_disposition_ = content_disposition;
}
+ // Should only be called by the IPC ParamTraits for this class.
+ void swap_items(std::vector<Item>* items) {
+ items_.swap(*items);
+ }
+
private:
friend class base::RefCounted<BlobData>;
@@ -145,6 +149,9 @@ class BlobData : public base::RefCounted<BlobData> {
std::string content_type_;
std::string content_disposition_;
std::vector<Item> items_;
+ std::vector<scoped_refptr<DeletableFileReference> > deletable_files_;
+
+ DISALLOW_COPY_AND_ASSIGN(BlobData);
};
#if defined(UNIT_TEST)
diff --git a/webkit/blob/blob_storage_controller.cc b/webkit/blob/blob_storage_controller.cc
index 274c381..e813be2 100644
--- a/webkit/blob/blob_storage_controller.cc
+++ b/webkit/blob/blob_storage_controller.cc
@@ -17,42 +17,6 @@ BlobStorageController::BlobStorageController() {
BlobStorageController::~BlobStorageController() {
}
-void BlobStorageController::AppendStorageItems(
- BlobData* target_blob_data, BlobData* src_blob_data,
- uint64 offset, uint64 length) {
- DCHECK(target_blob_data && src_blob_data &&
- length != static_cast<uint64>(-1));
-
- std::vector<BlobData::Item>::const_iterator iter =
- src_blob_data->items().begin();
- if (offset) {
- for (; iter != src_blob_data->items().end(); ++iter) {
- if (offset >= iter->length())
- offset -= iter->length();
- else
- break;
- }
- }
-
- for (; iter != src_blob_data->items().end() && length > 0; ++iter) {
- uint64 current_length = iter->length() - offset;
- uint64 new_length = current_length > length ? length : current_length;
- if (iter->type() == BlobData::TYPE_DATA) {
- target_blob_data->AppendData(iter->data(),
- static_cast<uint32>(iter->offset() + offset),
- static_cast<uint32>(new_length));
- } else {
- DCHECK(iter->type() == BlobData::TYPE_FILE);
- target_blob_data->AppendFile(iter->file_path(),
- iter->offset() + offset,
- new_length,
- iter->expected_modification_time());
- }
- length -= new_length;
- offset = 0;
- }
-}
-
void BlobStorageController::RegisterBlobUrl(
const GURL& url, const BlobData* blob_data) {
scoped_refptr<BlobData> target_blob_data = new BlobData();
@@ -78,10 +42,11 @@ void BlobStorageController::RegisterBlobUrl(
break;
}
case BlobData::TYPE_FILE:
- target_blob_data->AppendFile(iter->file_path(),
- iter->offset(),
- iter->length(),
- iter->expected_modification_time());
+ AppendFileItem(target_blob_data,
+ iter->file_path(),
+ iter->offset(),
+ iter->length(),
+ iter->expected_modification_time());
break;
case BlobData::TYPE_BLOB: {
BlobData* src_blob_data = GetBlobDataFromUrl(iter->blob_url());
@@ -179,4 +144,55 @@ void BlobStorageController::ResolveBlobReferencesInUploadData(
}
}
+void BlobStorageController::AppendStorageItems(
+ BlobData* target_blob_data, BlobData* src_blob_data,
+ uint64 offset, uint64 length) {
+ DCHECK(target_blob_data && src_blob_data &&
+ length != static_cast<uint64>(-1));
+
+ std::vector<BlobData::Item>::const_iterator iter =
+ src_blob_data->items().begin();
+ if (offset) {
+ for (; iter != src_blob_data->items().end(); ++iter) {
+ if (offset >= iter->length())
+ offset -= iter->length();
+ else
+ break;
+ }
+ }
+
+ for (; iter != src_blob_data->items().end() && length > 0; ++iter) {
+ uint64 current_length = iter->length() - offset;
+ uint64 new_length = current_length > length ? length : current_length;
+ if (iter->type() == BlobData::TYPE_DATA) {
+ target_blob_data->AppendData(iter->data(),
+ static_cast<uint32>(iter->offset() + offset),
+ static_cast<uint32>(new_length));
+ } else {
+ DCHECK(iter->type() == BlobData::TYPE_FILE);
+ AppendFileItem(target_blob_data,
+ iter->file_path(),
+ iter->offset() + offset,
+ new_length,
+ iter->expected_modification_time());
+ }
+ length -= new_length;
+ offset = 0;
+ }
+}
+
+void BlobStorageController::AppendFileItem(
+ BlobData* target_blob_data,
+ const FilePath& file_path, uint64 offset, uint64 length,
+ const base::Time& expected_modification_time) {
+ target_blob_data->AppendFile(file_path, offset, length,
+ expected_modification_time);
+
+ // It may be a temporary file that should be deleted when no longer needed.
+ scoped_refptr<DeletableFileReference> deletable_file =
+ DeletableFileReference::Get(file_path);
+ if (deletable_file)
+ target_blob_data->AttachDeletableFileReference(deletable_file);
+}
+
} // namespace webkit_blob
diff --git a/webkit/blob/blob_storage_controller.h b/webkit/blob/blob_storage_controller.h
index 1f0b25e..74bc131b 100644
--- a/webkit/blob/blob_storage_controller.h
+++ b/webkit/blob/blob_storage_controller.h
@@ -10,7 +10,11 @@
#include "base/ref_counted.h"
class GURL;
+class FilePath;
+namespace base {
+class Time;
+}
namespace net {
class UploadData;
}
@@ -41,6 +45,9 @@ class BlobStorageController {
BlobData* src_blob_data,
uint64 offset,
uint64 length);
+ void AppendFileItem(BlobData* target_blob_data,
+ const FilePath& file_path, uint64 offset, uint64 length,
+ const base::Time& expected_modification_time);
typedef base::hash_map<std::string, scoped_refptr<BlobData> > BlobMap;
BlobMap blob_map_;
diff --git a/webkit/tools/test_shell/test_shell_webblobregistry_impl.cc b/webkit/tools/test_shell/test_shell_webblobregistry_impl.cc
index 4689da5..65596ae 100644
--- a/webkit/tools/test_shell/test_shell_webblobregistry_impl.cc
+++ b/webkit/tools/test_shell/test_shell_webblobregistry_impl.cc
@@ -16,9 +16,13 @@ using WebKit::WebBlobData;
using WebKit::WebString;
using WebKit::WebURL;
+namespace {
+
MessageLoop* g_io_thread;
webkit_blob::BlobStorageController* g_blob_storage_controller;
+} // namespace
+
/* static */
void TestShellWebBlobRegistryImpl::InitializeOnIOThread(
webkit_blob::BlobStorageController* blob_storage_controller) {
@@ -38,15 +42,14 @@ TestShellWebBlobRegistryImpl::TestShellWebBlobRegistryImpl() {
void TestShellWebBlobRegistryImpl::registerBlobURL(
const WebURL& url, WebBlobData& data) {
DCHECK(g_io_thread);
+ // Note: BlobData is not refcounted thread safe.
scoped_refptr<webkit_blob::BlobData> blob_data(
new webkit_blob::BlobData(data));
- blob_data->AddRef(); // Release on DoRegisterBlobURL.
g_io_thread->PostTask(
FROM_HERE,
- NewRunnableMethod(this,
- &TestShellWebBlobRegistryImpl::DoRegisterBlobUrl,
- url,
- blob_data.get()));
+ NewRunnableMethod(
+ this, &TestShellWebBlobRegistryImpl::DoRegisterBlobUrl, url,
+ blob_data.release())); // Released in DoRegisterBlobUrl.
}
void TestShellWebBlobRegistryImpl::registerBlobURL(