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