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