| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef WEBKIT_BLOB_BLOB_DATA_H_ | 5 #ifndef WEBKIT_BLOB_BLOB_DATA_H_ |
| 6 #define WEBKIT_BLOB_BLOB_DATA_H_ | 6 #define WEBKIT_BLOB_BLOB_DATA_H_ |
| 7 | 7 |
| 8 #include <string> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/time.h" | 14 #include "base/time.h" |
| 14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 15 #include "webkit/base/data_element.h" | 16 #include "webkit/base/data_element.h" |
| 16 #include "webkit/blob/shareable_file_reference.h" | 17 #include "webkit/blob/shareable_file_reference.h" |
| 17 #include "webkit/storage/webkit_storage_export.h" | 18 #include "webkit/storage/webkit_storage_export.h" |
| 18 | 19 |
| 19 namespace webkit_blob { | 20 namespace webkit_blob { |
| 20 | 21 |
| 21 class WEBKIT_STORAGE_EXPORT BlobData : public base::RefCounted<BlobData> { | 22 class WEBKIT_STORAGE_EXPORT BlobData : public base::RefCounted<BlobData> { |
| 22 public: | 23 public: |
| 23 typedef webkit_base::DataElement Item; | 24 typedef webkit_base::DataElement Item; |
| 24 | 25 |
| 26 // TODO(michaeln): remove the empty ctor when we fully transition to uuids. |
| 25 BlobData(); | 27 BlobData(); |
| 28 explicit BlobData(const std::string& uuid); |
| 26 | 29 |
| 27 void AppendData(const std::string& data) { | 30 void AppendData(const std::string& data) { |
| 28 AppendData(data.c_str(), data.size()); | 31 AppendData(data.c_str(), data.size()); |
| 29 } | 32 } |
| 30 | 33 |
| 31 void AppendData(const char* data, size_t length); | 34 void AppendData(const char* data, size_t length); |
| 32 | 35 |
| 33 void AppendFile(const base::FilePath& file_path, uint64 offset, uint64 length, | 36 void AppendFile(const base::FilePath& file_path, uint64 offset, uint64 length, |
| 34 const base::Time& expected_modification_time); | 37 const base::Time& expected_modification_time); |
| 35 | 38 |
| 39 // Note: Identifying blobs by url is being deprecated, but while transitioning |
| 40 // there's a little of both going on in the project. |
| 36 void AppendBlob(const GURL& blob_url, uint64 offset, uint64 length); | 41 void AppendBlob(const GURL& blob_url, uint64 offset, uint64 length); |
| 42 void AppendBlob(const std::string& uuid, uint64 offset, uint64 length); |
| 37 | 43 |
| 38 void AppendFileSystemFile(const GURL& url, uint64 offset, uint64 length, | 44 void AppendFileSystemFile(const GURL& url, uint64 offset, uint64 length, |
| 39 const base::Time& expected_modification_time); | 45 const base::Time& expected_modification_time); |
| 40 | 46 |
| 41 void AttachShareableFileReference(ShareableFileReference* reference) { | 47 void AttachShareableFileReference(ShareableFileReference* reference) { |
| 42 shareable_files_.push_back(reference); | 48 shareable_files_.push_back(reference); |
| 43 } | 49 } |
| 44 | 50 |
| 51 const std::string& uuid() const { return uuid_; } |
| 45 const std::vector<Item>& items() const { return items_; } | 52 const std::vector<Item>& items() const { return items_; } |
| 46 | |
| 47 const std::string& content_type() const { return content_type_; } | 53 const std::string& content_type() const { return content_type_; } |
| 48 void set_content_type(const std::string& content_type) { | 54 void set_content_type(const std::string& content_type) { |
| 49 content_type_ = content_type; | 55 content_type_ = content_type; |
| 50 } | 56 } |
| 51 | 57 |
| 52 const std::string& content_disposition() const { | 58 const std::string& content_disposition() const { |
| 53 return content_disposition_; | 59 return content_disposition_; |
| 54 } | 60 } |
| 55 void set_content_disposition(const std::string& content_disposition) { | 61 void set_content_disposition(const std::string& content_disposition) { |
| 56 content_disposition_ = content_disposition; | 62 content_disposition_ = content_disposition; |
| 57 } | 63 } |
| 58 | 64 |
| 59 int64 GetMemoryUsage() const; | 65 int64 GetMemoryUsage() const; |
| 60 | 66 |
| 61 private: | 67 private: |
| 62 friend class base::RefCounted<BlobData>; | 68 friend class base::RefCounted<BlobData>; |
| 63 virtual ~BlobData(); | 69 virtual ~BlobData(); |
| 64 | 70 |
| 71 std::string uuid_; |
| 65 std::string content_type_; | 72 std::string content_type_; |
| 66 std::string content_disposition_; | 73 std::string content_disposition_; |
| 67 std::vector<Item> items_; | 74 std::vector<Item> items_; |
| 68 std::vector<scoped_refptr<ShareableFileReference> > shareable_files_; | 75 std::vector<scoped_refptr<ShareableFileReference> > shareable_files_; |
| 69 | 76 |
| 70 DISALLOW_COPY_AND_ASSIGN(BlobData); | 77 DISALLOW_COPY_AND_ASSIGN(BlobData); |
| 71 }; | 78 }; |
| 72 | 79 |
| 73 #if defined(UNIT_TEST) | 80 #if defined(UNIT_TEST) |
| 74 inline bool operator==(const BlobData& a, const BlobData& b) { | 81 inline bool operator==(const BlobData& a, const BlobData& b) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 86 } | 93 } |
| 87 | 94 |
| 88 inline bool operator!=(const BlobData& a, const BlobData& b) { | 95 inline bool operator!=(const BlobData& a, const BlobData& b) { |
| 89 return !(a == b); | 96 return !(a == b); |
| 90 } | 97 } |
| 91 #endif // defined(UNIT_TEST) | 98 #endif // defined(UNIT_TEST) |
| 92 | 99 |
| 93 } // namespace webkit_blob | 100 } // namespace webkit_blob |
| 94 | 101 |
| 95 #endif // WEBKIT_BLOB_BLOB_DATA_H_ | 102 #endif // WEBKIT_BLOB_BLOB_DATA_H_ |
| OLD | NEW |