Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: storage/browser/blob/blob_storage_context.cc

Issue 810403004: [Storage] Blob Storage Refactoring pt 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: memory leak fixed Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "storage/browser/blob/blob_storage_context.h" 5 #include "storage/browser/blob/blob_storage_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/stl_util.h"
12 #include "storage/browser/blob/blob_data_handle.h" 13 #include "storage/browser/blob/blob_data_handle.h"
13 #include "storage/common/blob/blob_data.h" 14 #include "storage/common/blob/blob_data.h"
14 #include "url/gurl.h" 15 #include "url/gurl.h"
15 16
16 namespace storage { 17 namespace storage {
17 18
18 namespace { 19 namespace {
19 20
20 // We can't use GURL directly for these hash fragment manipulations 21 // We can't use GURL directly for these hash fragment manipulations
21 // since it doesn't have specific knowlege of the BlobURL format. GURL 22 // since it doesn't have specific knowlege of the BlobURL format. GURL
(...skipping 14 matching lines...) Expand all
36 // TODO(michaeln): use base::SysInfo::AmountOfPhysicalMemoryMB() in some 37 // TODO(michaeln): use base::SysInfo::AmountOfPhysicalMemoryMB() in some
37 // way to come up with a better limit. 38 // way to come up with a better limit.
38 static const int64 kMaxMemoryUsage = 500 * 1024 * 1024; // Half a gig. 39 static const int64 kMaxMemoryUsage = 500 * 1024 * 1024; // Half a gig.
39 40
40 } // namespace 41 } // namespace
41 42
42 BlobStorageContext::BlobMapEntry::BlobMapEntry() 43 BlobStorageContext::BlobMapEntry::BlobMapEntry()
43 : refcount(0), flags(0) { 44 : refcount(0), flags(0) {
44 } 45 }
45 46
46 BlobStorageContext::BlobMapEntry::BlobMapEntry( 47 BlobStorageContext::BlobMapEntry::BlobMapEntry(int refcount,
47 int refcount, int flags, BlobData* data) 48 int flags,
48 : refcount(refcount), flags(flags), data(data) { 49 BlobDataBuilder* data)
50 : refcount(refcount), flags(flags), data_builder(data) {
49 } 51 }
50 52
51 BlobStorageContext::BlobMapEntry::~BlobMapEntry() { 53 BlobStorageContext::BlobMapEntry::~BlobMapEntry() {
52 } 54 }
53 55
54 BlobStorageContext::BlobStorageContext() 56 BlobStorageContext::BlobStorageContext()
55 : memory_usage_(0) { 57 : memory_usage_(0) {
56 } 58 }
57 59
58 BlobStorageContext::~BlobStorageContext() { 60 BlobStorageContext::~BlobStorageContext() {
61 STLDeleteContainerPairSecondPointers(blob_map_.begin(), blob_map_.end());
59 } 62 }
60 63
61 scoped_ptr<BlobDataHandle> BlobStorageContext::GetBlobDataFromUUID( 64 scoped_ptr<BlobDataSnapshotHandle> BlobStorageContext::GetBlobDataFromUUID(
62 const std::string& uuid) { 65 const std::string& uuid) {
63 scoped_ptr<BlobDataHandle> result; 66 scoped_ptr<BlobDataSnapshotHandle> result;
64 BlobMap::iterator found = blob_map_.find(uuid); 67 BlobMap::iterator found = blob_map_.find(uuid);
65 if (found == blob_map_.end()) 68 if (found == blob_map_.end())
66 return result.Pass(); 69 return result.Pass();
67 if (found->second.flags & EXCEEDED_MEMORY) 70 auto* entry = found->second;
71 if (entry->flags & EXCEEDED_MEMORY)
68 return result.Pass(); 72 return result.Pass();
69 DCHECK(!(found->second.flags & BEING_BUILT)); 73 DCHECK(!(entry->flags & BEING_BUILT));
70 result.reset(new BlobDataHandle( 74 result.reset(
71 found->second.data.get(), this, base::MessageLoopProxy::current().get())); 75 new BlobDataSnapshotHandle(new BlobDataSnapshot(*entry->data.get()), this,
76 base::MessageLoopProxy::current().get()));
72 return result.Pass(); 77 return result.Pass();
73 } 78 }
74 79
75 scoped_ptr<BlobDataHandle> BlobStorageContext::GetBlobDataFromPublicURL( 80 scoped_ptr<BlobDataSnapshotHandle> BlobStorageContext::GetBlobDataFromPublicURL(
76 const GURL& url) { 81 const GURL& url) {
77 BlobURLMap::iterator found = public_blob_urls_.find( 82 BlobURLMap::iterator found = public_blob_urls_.find(
78 BlobUrlHasRef(url) ? ClearBlobUrlRef(url) : url); 83 BlobUrlHasRef(url) ? ClearBlobUrlRef(url) : url);
79 if (found == public_blob_urls_.end()) 84 if (found == public_blob_urls_.end())
80 return scoped_ptr<BlobDataHandle>(); 85 return scoped_ptr<BlobDataSnapshotHandle>();
81 return GetBlobDataFromUUID(found->second); 86 return GetBlobDataFromUUID(found->second);
82 } 87 }
83 88
84 scoped_ptr<BlobDataHandle> BlobStorageContext::AddFinishedBlob( 89 scoped_ptr<BlobDataSnapshotHandle> BlobStorageContext::AddFinishedBlob(
85 const BlobData* data) { 90 const BlobDataBuilder& data) {
86 StartBuildingBlob(data->uuid()); 91 StartBuildingBlob(data.uuid_);
87 for (std::vector<BlobData::Item>::const_iterator iter = 92 for (const auto& blob_item : data.items_) {
88 data->items().begin(); 93 AppendBlobDataItem(data.uuid_, *(blob_item->item_));
89 iter != data->items().end(); ++iter) {
90 AppendBlobDataItem(data->uuid(), *iter);
91 } 94 }
92 FinishBuildingBlob(data->uuid(), data->content_type()); 95 FinishBuildingBlob(data.uuid_, data.content_type_);
93 scoped_ptr<BlobDataHandle> handle = GetBlobDataFromUUID(data->uuid()); 96 scoped_ptr<BlobDataSnapshotHandle> handle = GetBlobDataFromUUID(data.uuid_);
94 DecrementBlobRefCount(data->uuid()); 97 DecrementBlobRefCount(data.uuid_);
95 return handle.Pass(); 98 return handle.Pass();
96 } 99 }
97 100
98 bool BlobStorageContext::RegisterPublicBlobURL( 101 bool BlobStorageContext::RegisterPublicBlobURL(
99 const GURL& blob_url, const std::string& uuid) { 102 const GURL& blob_url, const std::string& uuid) {
100 DCHECK(!BlobUrlHasRef(blob_url)); 103 DCHECK(!BlobUrlHasRef(blob_url));
101 DCHECK(IsInUse(uuid)); 104 DCHECK(IsInUse(uuid));
102 DCHECK(!IsUrlRegistered(blob_url)); 105 DCHECK(!IsUrlRegistered(blob_url));
103 if (!IsInUse(uuid) || IsUrlRegistered(blob_url)) 106 if (!IsInUse(uuid) || IsUrlRegistered(blob_url))
104 return false; 107 return false;
105 IncrementBlobRefCount(uuid); 108 IncrementBlobRefCount(uuid);
106 public_blob_urls_[blob_url] = uuid; 109 public_blob_urls_[blob_url] = uuid;
107 return true; 110 return true;
108 } 111 }
109 112
110 void BlobStorageContext::RevokePublicBlobURL(const GURL& blob_url) { 113 void BlobStorageContext::RevokePublicBlobURL(const GURL& blob_url) {
111 DCHECK(!BlobUrlHasRef(blob_url)); 114 DCHECK(!BlobUrlHasRef(blob_url));
112 if (!IsUrlRegistered(blob_url)) 115 if (!IsUrlRegistered(blob_url))
113 return; 116 return;
114 DecrementBlobRefCount(public_blob_urls_[blob_url]); 117 DecrementBlobRefCount(public_blob_urls_[blob_url]);
115 public_blob_urls_.erase(blob_url); 118 public_blob_urls_.erase(blob_url);
116 } 119 }
117 120
118 void BlobStorageContext::StartBuildingBlob(const std::string& uuid) { 121 void BlobStorageContext::StartBuildingBlob(const std::string& uuid) {
119 DCHECK(!IsInUse(uuid) && !uuid.empty()); 122 DCHECK(!IsInUse(uuid) && !uuid.empty());
120 blob_map_[uuid] = BlobMapEntry(1, BEING_BUILT, new BlobData(uuid)); 123 blob_map_[uuid] = new BlobMapEntry(1, BEING_BUILT, new BlobDataBuilder(uuid));
121 } 124 }
122 125
123 void BlobStorageContext::AppendBlobDataItem( 126 void BlobStorageContext::AppendBlobDataItem(const std::string& uuid,
124 const std::string& uuid, const BlobData::Item& item) { 127 const DataElement& item) {
125 DCHECK(IsBeingBuilt(uuid)); 128 DCHECK(IsBeingBuilt(uuid));
126 BlobMap::iterator found = blob_map_.find(uuid); 129 BlobMap::iterator found = blob_map_.find(uuid);
127 if (found == blob_map_.end()) 130 if (found == blob_map_.end())
128 return; 131 return;
129 if (found->second.flags & EXCEEDED_MEMORY) 132 auto* entry = found->second;
133 if (entry->flags & EXCEEDED_MEMORY)
130 return; 134 return;
131 BlobData* target_blob_data = found->second.data.get(); 135 BlobDataBuilder* target_blob_data = entry->data_builder.get();
132 DCHECK(target_blob_data); 136 DCHECK(target_blob_data);
133 137
134 bool exceeded_memory = false; 138 bool exceeded_memory = false;
135 139
136 // The blob data is stored in the canonical way which only contains a 140 // The blob data is stored in the canonical way which only contains a
137 // list of Data, File, and FileSystem items. Aggregated TYPE_BLOB items 141 // list of Data, File, and FileSystem items. Aggregated TYPE_BLOB items
138 // are expanded into the primitive constituent types. 142 // are expanded into the primitive constituent types.
139 // 1) The Data item is denoted by the raw data and length. 143 // 1) The Data item is denoted by the raw data and length.
140 // 2) The File item is denoted by the file path, the range and the expected 144 // 2) The File item is denoted by the file path, the range and the expected
141 // modification time. 145 // modification time.
142 // 3) The FileSystem File item is denoted by the FileSystem URL, the range 146 // 3) The FileSystem File item is denoted by the FileSystem URL, the range
143 // and the expected modification time. 147 // and the expected modification time.
144 // 4) The Blob items are expanded. 148 // 4) The Blob items are expanded.
145 // TODO(michaeln): Would be nice to avoid copying Data items when expanding. 149 // TODO(michaeln): Would be nice to avoid copying Data items when expanding.
146 150
147 uint64 length = item.length(); 151 uint64 length = item.length();
148 DCHECK_GT(length, 0u); 152 DCHECK_GT(length, 0u);
149 UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeBeforeAppend", 153 UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeBeforeAppend",
150 memory_usage_ / 1024); 154 memory_usage_ / 1024);
151 switch (item.type()) { 155 switch (item.type()) {
152 case BlobData::Item::TYPE_BYTES: 156 case DataElement::TYPE_BYTES:
153 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.Bytes", length / 1024); 157 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.Bytes", length / 1024);
154 DCHECK(!item.offset()); 158 DCHECK(!item.offset());
155 exceeded_memory = !AppendBytesItem(target_blob_data, item.bytes(), 159 exceeded_memory = !AppendBytesItem(target_blob_data, item.bytes(),
156 static_cast<int64>(length)); 160 static_cast<int64>(length));
157 break; 161 break;
158 case BlobData::Item::TYPE_FILE: 162 case DataElement::TYPE_FILE:
159 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.File", length / 1024); 163 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.File", length / 1024);
160 AppendFileItem(target_blob_data, item.path(), item.offset(), length, 164 AppendFileItem(target_blob_data, item.path(), item.offset(),
161 item.expected_modification_time()); 165 item.length(), item.expected_modification_time());
162 break; 166 break;
163 case BlobData::Item::TYPE_FILE_FILESYSTEM: 167 case DataElement::TYPE_FILE_FILESYSTEM:
164 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.FileSystem", length / 1024); 168 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.FileSystem", length / 1024);
165 AppendFileSystemFileItem(target_blob_data, item.filesystem_url(), 169 AppendFileSystemFileItem(target_blob_data, item.filesystem_url(),
166 item.offset(), length, 170 item.offset(), item.length(),
167 item.expected_modification_time()); 171 item.expected_modification_time());
168 break; 172 break;
169 case BlobData::Item::TYPE_BLOB: { 173 case DataElement::TYPE_BLOB: {
170 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.Blob", length / 1024); 174 UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.Blob", length / 1024);
171 scoped_ptr<BlobDataHandle> src = GetBlobDataFromUUID(item.blob_uuid()); 175 scoped_ptr<BlobDataSnapshotHandle> src =
176 GetBlobDataFromUUID(item.blob_uuid());
172 if (src) 177 if (src)
173 exceeded_memory = !ExpandStorageItems(target_blob_data, 178 exceeded_memory = !ExpandStorageItems(target_blob_data, *src->data(),
174 src->data(), 179 item.offset(), item.length());
175 item.offset(),
176 item.length());
177 break; 180 break;
178 } 181 }
179 default: 182 default:
180 NOTREACHED(); 183 NOTREACHED();
181 break; 184 break;
182 } 185 }
183 UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeAfterAppend", 186 UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeAfterAppend",
184 memory_usage_ / 1024); 187 memory_usage_ / 1024);
185 188
186 // If we're using too much memory, drop this blob's data. 189 // If we're using too much memory, drop this blob's data.
187 // TODO(michaeln): Blob memory storage does not yet spill over to disk, 190 // TODO(michaeln): Blob memory storage does not yet spill over to disk,
188 // as a stop gap, we'll prevent memory usage over a max amount. 191 // as a stop gap, we'll prevent memory usage over a max amount.
189 if (exceeded_memory) { 192 if (exceeded_memory) {
190 memory_usage_ -= target_blob_data->GetMemoryUsage(); 193 memory_usage_ -= target_blob_data->GetMemoryUsage();
191 found->second.flags |= EXCEEDED_MEMORY; 194 entry->flags |= EXCEEDED_MEMORY;
192 found->second.data = new BlobData(uuid); 195 entry->data_builder.reset(new BlobDataBuilder(uuid));
193 return; 196 return;
194 } 197 }
195 } 198 }
196 199
197 void BlobStorageContext::FinishBuildingBlob( 200 void BlobStorageContext::FinishBuildingBlob(
198 const std::string& uuid, const std::string& content_type) { 201 const std::string& uuid, const std::string& content_type) {
199 DCHECK(IsBeingBuilt(uuid)); 202 DCHECK(IsBeingBuilt(uuid));
200 BlobMap::iterator found = blob_map_.find(uuid); 203 BlobMap::iterator found = blob_map_.find(uuid);
201 if (found == blob_map_.end()) 204 if (found == blob_map_.end())
202 return; 205 return;
203 found->second.data->set_content_type(content_type); 206 auto* entry = found->second;
204 found->second.flags &= ~BEING_BUILT; 207 entry->data_builder->set_content_type(content_type);
208 entry->data = entry->data_builder->Build().Pass();
209 entry->data_builder.reset();
210 entry->flags &= ~BEING_BUILT;
205 UMA_HISTOGRAM_COUNTS("Storage.Blob.ItemCount", 211 UMA_HISTOGRAM_COUNTS("Storage.Blob.ItemCount",
206 found->second.data->items().size()); 212 entry->data->items().size());
207 UMA_HISTOGRAM_BOOLEAN( 213 UMA_HISTOGRAM_BOOLEAN("Storage.Blob.ExceededMemory",
208 "Storage.Blob.ExceededMemory", 214 (entry->flags & EXCEEDED_MEMORY) == EXCEEDED_MEMORY);
209 (found->second.flags & EXCEEDED_MEMORY) == EXCEEDED_MEMORY);
210 } 215 }
211 216
212 void BlobStorageContext::CancelBuildingBlob(const std::string& uuid) { 217 void BlobStorageContext::CancelBuildingBlob(const std::string& uuid) {
213 DCHECK(IsBeingBuilt(uuid)); 218 DCHECK(IsBeingBuilt(uuid));
214 DecrementBlobRefCount(uuid); 219 DecrementBlobRefCount(uuid);
215 } 220 }
216 221
217 void BlobStorageContext::IncrementBlobRefCount(const std::string& uuid) { 222 void BlobStorageContext::IncrementBlobRefCount(const std::string& uuid) {
218 BlobMap::iterator found = blob_map_.find(uuid); 223 BlobMap::iterator found = blob_map_.find(uuid);
219 if (found == blob_map_.end()) { 224 if (found == blob_map_.end()) {
220 DCHECK(false); 225 DCHECK(false);
221 return; 226 return;
222 } 227 }
223 ++(found->second.refcount); 228 ++(found->second->refcount);
224 } 229 }
225 230
226 void BlobStorageContext::DecrementBlobRefCount(const std::string& uuid) { 231 void BlobStorageContext::DecrementBlobRefCount(const std::string& uuid) {
227 BlobMap::iterator found = blob_map_.find(uuid); 232 BlobMap::iterator found = blob_map_.find(uuid);
228 if (found == blob_map_.end()) 233 if (found == blob_map_.end())
229 return; 234 return;
230 DCHECK_EQ(found->second.data->uuid(), uuid); 235 auto* entry = found->second;
231 if (--(found->second.refcount) == 0) { 236 DCHECK_EQ(entry->data->uuid(), uuid);
232 memory_usage_ -= found->second.data->GetMemoryUsage(); 237 if (--(entry->refcount) == 0) {
238 memory_usage_ -= entry->data->GetMemoryUsage();
239 delete entry;
233 blob_map_.erase(found); 240 blob_map_.erase(found);
234 } 241 }
235 } 242 }
236 243
237 bool BlobStorageContext::ExpandStorageItems( 244 bool BlobStorageContext::ExpandStorageItems(
238 BlobData* target_blob_data, BlobData* src_blob_data, 245 BlobDataBuilder* target_blob_data,
239 uint64 offset, uint64 length) { 246 const BlobDataSnapshot& src_blob_data,
240 DCHECK(target_blob_data && src_blob_data && 247 uint64 offset,
241 length != static_cast<uint64>(-1)); 248 uint64 length) {
249 DCHECK(target_blob_data && length != static_cast<uint64>(-1));
242 250
243 std::vector<BlobData::Item>::const_iterator iter = 251 auto& items = src_blob_data.items();
244 src_blob_data->items().begin(); 252 auto iter = items.begin();
245 if (offset) { 253 if (offset) {
246 for (; iter != src_blob_data->items().end(); ++iter) { 254 for (; iter != items.end(); ++iter) {
247 if (offset >= iter->length()) 255 const BlobDataItem& item = *(iter->get());
248 offset -= iter->length(); 256 if (offset >= item.length())
257 offset -= item.length();
249 else 258 else
250 break; 259 break;
251 } 260 }
252 } 261 }
253 262
254 for (; iter != src_blob_data->items().end() && length > 0; ++iter) { 263 for (; iter != items.end() && length > 0; ++iter) {
255 uint64 current_length = iter->length() - offset; 264 const BlobDataItem& item = *(iter->get());
265 uint64 current_length = item.length() - offset;
256 uint64 new_length = current_length > length ? length : current_length; 266 uint64 new_length = current_length > length ? length : current_length;
257 if (iter->type() == BlobData::Item::TYPE_BYTES) { 267 if (iter->get()->type() == DataElement::TYPE_BYTES) {
258 if (!AppendBytesItem( 268 if (!AppendBytesItem(
259 target_blob_data, 269 target_blob_data,
260 iter->bytes() + static_cast<size_t>(iter->offset() + offset), 270 item.bytes() + static_cast<size_t>(item.offset() + offset),
261 static_cast<int64>(new_length))) { 271 static_cast<int64>(new_length))) {
262 return false; // exceeded memory 272 return false; // exceeded memory
263 } 273 }
264 } else if (iter->type() == BlobData::Item::TYPE_FILE) { 274 } else if (item.type() == DataElement::TYPE_FILE) {
265 AppendFileItem(target_blob_data, 275 AppendFileItem(target_blob_data, item.path(), item.offset() + offset,
266 iter->path(), 276 new_length, item.expected_modification_time());
267 iter->offset() + offset,
268 new_length,
269 iter->expected_modification_time());
270 } else { 277 } else {
271 DCHECK(iter->type() == BlobData::Item::TYPE_FILE_FILESYSTEM); 278 DCHECK(item.type() == DataElement::TYPE_FILE_FILESYSTEM);
272 AppendFileSystemFileItem(target_blob_data, 279 AppendFileSystemFileItem(target_blob_data, item.filesystem_url(),
273 iter->filesystem_url(), 280 item.offset() + offset, new_length,
274 iter->offset() + offset, 281 item.expected_modification_time());
275 new_length,
276 iter->expected_modification_time());
277 } 282 }
278 length -= new_length; 283 length -= new_length;
279 offset = 0; 284 offset = 0;
280 } 285 }
281 return true; 286 return true;
282 } 287 }
283 288
284 bool BlobStorageContext::AppendBytesItem( 289 bool BlobStorageContext::AppendBytesItem(BlobDataBuilder* target_blob_data,
285 BlobData* target_blob_data, const char* bytes, int64 length) { 290 const char* bytes,
291 int64 length) {
286 if (length < 0) { 292 if (length < 0) {
287 DCHECK(false); 293 DCHECK(false);
288 return false; 294 return false;
289 } 295 }
290 if (memory_usage_ + length > kMaxMemoryUsage) 296 if (memory_usage_ + length > kMaxMemoryUsage) {
291 return false; 297 return false;
298 }
292 target_blob_data->AppendData(bytes, static_cast<size_t>(length)); 299 target_blob_data->AppendData(bytes, static_cast<size_t>(length));
293 memory_usage_ += length; 300 memory_usage_ += length;
294 return true; 301 return true;
295 } 302 }
296 303
297 void BlobStorageContext::AppendFileItem( 304 void BlobStorageContext::AppendFileItem(
298 BlobData* target_blob_data, 305 BlobDataBuilder* target_blob_data,
299 const base::FilePath& file_path, uint64 offset, uint64 length, 306 const base::FilePath& file_path,
307 uint64 offset,
308 uint64 length,
300 const base::Time& expected_modification_time) { 309 const base::Time& expected_modification_time) {
301 target_blob_data->AppendFile(file_path, offset, length,
302 expected_modification_time);
303
304 // It may be a temporary file that should be deleted when no longer needed. 310 // It may be a temporary file that should be deleted when no longer needed.
305 scoped_refptr<ShareableFileReference> shareable_file = 311 scoped_refptr<ShareableFileReference> shareable_file =
306 ShareableFileReference::Get(file_path); 312 ShareableFileReference::Get(file_path);
307 if (shareable_file.get()) 313
308 target_blob_data->AttachShareableFileReference(shareable_file.get()); 314 target_blob_data->AppendFile(file_path, offset, length,
315 expected_modification_time, shareable_file);
309 } 316 }
310 317
311 void BlobStorageContext::AppendFileSystemFileItem( 318 void BlobStorageContext::AppendFileSystemFileItem(
312 BlobData* target_blob_data, 319 BlobDataBuilder* target_blob_data,
313 const GURL& filesystem_url, uint64 offset, uint64 length, 320 const GURL& filesystem_url,
321 uint64 offset,
322 uint64 length,
314 const base::Time& expected_modification_time) { 323 const base::Time& expected_modification_time) {
315 target_blob_data->AppendFileSystemFile(filesystem_url, offset, length, 324 target_blob_data->AppendFileSystemFile(filesystem_url, offset, length,
316 expected_modification_time); 325 expected_modification_time);
317 } 326 }
318 327
319 bool BlobStorageContext::IsInUse(const std::string& uuid) { 328 bool BlobStorageContext::IsInUse(const std::string& uuid) {
320 return blob_map_.find(uuid) != blob_map_.end(); 329 return blob_map_.find(uuid) != blob_map_.end();
321 } 330 }
322 331
323 bool BlobStorageContext::IsBeingBuilt(const std::string& uuid) { 332 bool BlobStorageContext::IsBeingBuilt(const std::string& uuid) {
324 BlobMap::iterator found = blob_map_.find(uuid); 333 BlobMap::iterator found = blob_map_.find(uuid);
325 if (found == blob_map_.end()) 334 if (found == blob_map_.end())
326 return false; 335 return false;
327 return found->second.flags & BEING_BUILT; 336 return (found->second->flags & BEING_BUILT) && found->second->data_builder;
328 } 337 }
329 338
330 bool BlobStorageContext::IsUrlRegistered(const GURL& blob_url) { 339 bool BlobStorageContext::IsUrlRegistered(const GURL& blob_url) {
331 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); 340 return public_blob_urls_.find(blob_url) != public_blob_urls_.end();
332 } 341 }
333 342
334 } // namespace storage 343 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698