| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ | 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ |
| 6 #define STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ | 6 #define STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 8 #include <string> | 9 #include <string> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/memory/ref_counted.h" |
| 13 #include "storage/browser/blob/blob_data_item.h" | 15 #include "storage/browser/blob/blob_data_item.h" |
| 14 #include "storage/browser/blob/blob_data_snapshot.h" | 16 #include "storage/browser/blob/blob_data_snapshot.h" |
| 15 #include "storage/browser/storage_browser_export.h" | 17 #include "storage/browser/storage_browser_export.h" |
| 16 | 18 |
| 17 namespace storage { | 19 namespace storage { |
| 18 class BlobStorageContext; | 20 class BlobStorageContext; |
| 19 | 21 |
| 20 class STORAGE_EXPORT BlobDataBuilder { | 22 class STORAGE_EXPORT BlobDataBuilder { |
| 21 public: | 23 public: |
| 22 explicit BlobDataBuilder(const std::string& uuid); | 24 explicit BlobDataBuilder(const std::string& uuid); |
| 23 virtual ~BlobDataBuilder(); | 25 ~BlobDataBuilder(); |
| 24 | 26 |
| 25 const std::string& uuid() const { return uuid_; } | 27 const std::string& uuid() const { return 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 |
| 35 // You must know the length of the file, you cannot use kuint64max to specify |
| 36 // the whole file. |
| 33 void AppendFile(const base::FilePath& file_path, | 37 void AppendFile(const base::FilePath& file_path, |
| 34 uint64 offset, | 38 uint64_t offset, |
| 35 uint64 length, | 39 uint64_t length, |
| 36 const base::Time& expected_modification_time); | 40 const base::Time& expected_modification_time); |
| 37 | 41 |
| 42 // You must know the length of the file, you cannot use kuint64max to specify |
| 43 // the whole file. |
| 38 void AppendFile(const base::FilePath& file_path, | 44 void AppendFile(const base::FilePath& file_path, |
| 39 uint64 offset, | 45 uint64_t offset, |
| 40 uint64 length, | 46 uint64_t length, |
| 41 const base::Time& expected_modification_time, | 47 const base::Time& expected_modification_time, |
| 42 scoped_refptr<ShareableFileReference> shareable_file); | 48 scoped_refptr<ShareableFileReference> shareable_file); |
| 43 | 49 |
| 44 void AppendBlob(const std::string& uuid, uint64 offset, uint64 length); | 50 void AppendBlob(const std::string& uuid, uint64_t offset, uint64_t length); |
| 51 |
| 52 void AppendBlob(const std::string& uuid); |
| 53 |
| 45 void AppendFileSystemFile(const GURL& url, | 54 void AppendFileSystemFile(const GURL& url, |
| 46 uint64 offset, | 55 uint64_t offset, |
| 47 uint64 length, | 56 uint64_t length, |
| 48 const base::Time& expected_modification_time); | 57 const base::Time& expected_modification_time); |
| 49 | 58 |
| 50 void set_content_type(const std::string& content_type) { | 59 void set_content_type(const std::string& content_type) { |
| 51 content_type_ = content_type; | 60 content_type_ = content_type; |
| 52 } | 61 } |
| 53 | 62 |
| 54 void set_content_disposition(const std::string& content_disposition) { | 63 void set_content_disposition(const std::string& content_disposition) { |
| 55 content_disposition_ = content_disposition; | 64 content_disposition_ = content_disposition; |
| 56 } | 65 } |
| 57 | 66 |
| 58 size_t GetMemoryUsage() const; | |
| 59 | |
| 60 scoped_ptr<BlobDataSnapshot> BuildSnapshot(); | |
| 61 | |
| 62 private: | 67 private: |
| 63 friend class BlobStorageContext; | 68 friend class BlobStorageContext; |
| 64 friend bool operator==(const BlobDataBuilder& a, const BlobDataBuilder& b); | 69 friend bool operator==(const BlobDataBuilder& a, const BlobDataBuilder& b); |
| 65 friend bool operator==(const BlobDataSnapshot& a, const BlobDataBuilder& b); | 70 friend bool operator==(const BlobDataSnapshot& a, const BlobDataBuilder& b); |
| 66 | 71 |
| 67 std::string uuid_; | 72 std::string uuid_; |
| 68 std::string content_type_; | 73 std::string content_type_; |
| 69 std::string content_disposition_; | 74 std::string content_disposition_; |
| 70 std::vector<scoped_refptr<BlobDataItem>> items_; | 75 std::vector<scoped_refptr<BlobDataItem>> items_; |
| 71 | 76 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 91 if (a.content_type() != b.content_type_) { | 96 if (a.content_type() != b.content_type_) { |
| 92 return false; | 97 return false; |
| 93 } | 98 } |
| 94 if (a.content_disposition() != b.content_disposition_) { | 99 if (a.content_disposition() != b.content_disposition_) { |
| 95 return false; | 100 return false; |
| 96 } | 101 } |
| 97 if (a.items().size() != b.items_.size()) { | 102 if (a.items().size() != b.items_.size()) { |
| 98 return false; | 103 return false; |
| 99 } | 104 } |
| 100 for (size_t i = 0; i < a.items().size(); ++i) { | 105 for (size_t i = 0; i < a.items().size(); ++i) { |
| 101 if (*(a.items()[i]) != *(b.items_[i])) { | 106 if (*(a.items()[i]) != *(b.items_[i])) |
| 102 return false; | 107 return false; |
| 103 } | |
| 104 } | 108 } |
| 105 return true; | 109 return true; |
| 106 } | 110 } |
| 107 | 111 |
| 108 inline bool operator!=(const BlobDataSnapshot& a, const BlobDataBuilder& b) { | 112 inline bool operator!=(const BlobDataSnapshot& a, const BlobDataBuilder& b) { |
| 109 return !(a == b); | 113 return !(a == b); |
| 110 } | 114 } |
| 111 | 115 |
| 112 inline bool operator!=(const BlobDataBuilder& a, const BlobDataBuilder& b) { | 116 inline bool operator!=(const BlobDataBuilder& a, const BlobDataBuilder& b) { |
| 113 return !(a == b); | 117 return !(a == b); |
| 114 } | 118 } |
| 115 #endif // defined(UNIT_TEST) | 119 #endif // defined(UNIT_TEST) |
| 116 | 120 |
| 117 } // namespace storage | 121 } // namespace storage |
| 118 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ | 122 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ |
| OLD | NEW |