1 // Copyright 2014 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 #include "content/browser/indexed_db/indexed_db_blob_info.h"
6
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h"
10
11 namespace content {
12
IndexedDBBlobInfo()13 IndexedDBBlobInfo::IndexedDBBlobInfo()
14 : is_file_(false), size_(-1), key_(DatabaseMetaDataKey::kInvalidBlobKey) {
15 }
16
IndexedDBBlobInfo(const std::string & uuid,const base::string16 & type,int64 size)17 IndexedDBBlobInfo::IndexedDBBlobInfo(const std::string& uuid,
18 const base::string16& type,
19 int64 size)
20 : is_file_(false),
21 uuid_(uuid),
22 type_(type),
23 size_(size),
24 key_(DatabaseMetaDataKey::kInvalidBlobKey) {
25 }
26
IndexedDBBlobInfo(const base::string16 & type,int64 size,int64 key)27 IndexedDBBlobInfo::IndexedDBBlobInfo(const base::string16& type,
28 int64 size,
29 int64 key)
30 : is_file_(false), type_(type), size_(size), key_(key) {
31 }
32
IndexedDBBlobInfo(const std::string & uuid,const base::FilePath & file_path,const base::string16 & file_name,const base::string16 & type)33 IndexedDBBlobInfo::IndexedDBBlobInfo(const std::string& uuid,
34 const base::FilePath& file_path,
35 const base::string16& file_name,
36 const base::string16& type)
37 : is_file_(true),
38 uuid_(uuid),
39 type_(type),
40 size_(-1),
41 file_name_(file_name),
42 file_path_(file_path),
43 key_(DatabaseMetaDataKey::kInvalidBlobKey) {
44 }
45
IndexedDBBlobInfo(int64 key,const base::string16 & type,const base::string16 & file_name)46 IndexedDBBlobInfo::IndexedDBBlobInfo(int64 key,
47 const base::string16& type,
48 const base::string16& file_name)
49 : is_file_(true), type_(type), size_(-1), file_name_(file_name), key_(key) {
50 }
51
~IndexedDBBlobInfo()52 IndexedDBBlobInfo::~IndexedDBBlobInfo() {}
53
set_size(int64 size)54 void IndexedDBBlobInfo::set_size(int64 size) {
55 DCHECK_EQ(-1, size_);
56 size_ = size;
57 }
58
set_uuid(const std::string & uuid)59 void IndexedDBBlobInfo::set_uuid(const std::string& uuid) {
60 DCHECK(uuid_.empty());
61 uuid_ = uuid;
62 DCHECK(!uuid_.empty());
63 }
64
set_file_path(const base::FilePath & file_path)65 void IndexedDBBlobInfo::set_file_path(const base::FilePath& file_path) {
66 DCHECK(file_path_.empty());
67 file_path_ = file_path;
68 }
69
set_last_modified(const base::Time & time)70 void IndexedDBBlobInfo::set_last_modified(const base::Time& time) {
71 DCHECK(base::Time().is_null());
72 DCHECK(is_file_);
73 last_modified_ = time;
74 }
75
set_key(int64 key)76 void IndexedDBBlobInfo::set_key(int64 key) {
77 DCHECK_EQ(DatabaseMetaDataKey::kInvalidBlobKey, key_);
78 key_ = key;
79 }
80
set_mark_used_callback(const base::Closure & mark_used_callback)81 void IndexedDBBlobInfo::set_mark_used_callback(
82 const base::Closure& mark_used_callback) {
83 DCHECK(mark_used_callback_.is_null());
84 mark_used_callback_ = mark_used_callback;
85 }
86
set_release_callback(const ReleaseCallback & release_callback)87 void IndexedDBBlobInfo::set_release_callback(
88 const ReleaseCallback& release_callback) {
89 DCHECK(release_callback_.is_null());
90 release_callback_ = release_callback;
91 }
92
93 } // namespace content
94