summaryrefslogtreecommitdiffstats
path: root/storage/browser/blob/blob_data_item.h
blob: 1953a1a6a2563ed3e3ed3467ea877a99185d05f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef STORAGE_BROWSER_BLOB_BLOB_DATA_ITEM_H_
#define STORAGE_BROWSER_BLOB_BLOB_DATA_ITEM_H_

#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "storage/browser/blob/shareable_file_reference.h"
#include "storage/browser/storage_browser_export.h"
#include "storage/common/data_element.h"

namespace storage {
class BlobDataBuilder;
class BlobStorageContext;

// Ref counted blob item.  This class owns the backing data of the blob item.
// The backing data is immutable, and cannot change after creation.
// The purpose of this class is to allow the resource to stick around in the
// snapshot even after the resource was swapped in the blob (either to disk or
// to memory) by the BlobStorageContext.
class STORAGE_EXPORT BlobDataItem : public base::RefCounted<BlobDataItem> {
 public:
  DataElement::Type type() const { return item_->type(); }
  const char* bytes() const { return item_->bytes(); }
  const base::FilePath& path() const { return item_->path(); }
  const GURL& filesystem_url() const { return item_->filesystem_url(); }
  const std::string& blob_uuid() const { return item_->blob_uuid(); }
  uint64 offset() const { return item_->offset(); }
  uint64 length() const { return item_->length(); }
  const base::Time& expected_modification_time() const {
    return item_->expected_modification_time();
  }
  const DataElement& data_element() const { return *item_; }
  const DataElement* data_element_ptr() const { return item_.get(); }

 private:
  friend class BlobDataBuilder;
  friend class BlobStorageContext;
  friend class base::RefCounted<BlobDataItem>;

  BlobDataItem(scoped_ptr<DataElement> item);
  BlobDataItem(scoped_ptr<DataElement> item,
               scoped_refptr<ShareableFileReference> file_handle);
  virtual ~BlobDataItem();

  scoped_ptr<DataElement> item_;
  scoped_refptr<ShareableFileReference> file_handle_;
};

#if defined(UNIT_TEST)
inline bool operator==(const BlobDataItem& a, const BlobDataItem& b) {
  return a.data_element() == b.data_element();
}

inline bool operator!=(const BlobDataItem& a, const BlobDataItem& b) {
  return !(a == b);
}
#endif  // defined(UNIT_TEST)

}  // namespace storage

#endif  // STORAGE_BROWSER_BLOB_BLOB_DATA_ITEM_H_