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