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

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

Issue 2516713002: [BlobStorage] Implementing disk. (Closed)
Patch Set: comments, and attempt at force flushing all tasks so Windows/Android test works Created 4 years 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_memory_controller.h" 5 #include "storage/browser/blob/blob_memory_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 for (const auto& item : unreserved_file_items) { 152 for (const auto& item : unreserved_file_items) {
153 const DataElement& element = item->item()->data_element(); 153 const DataElement& element = item->item()->data_element();
154 uint64_t file_id = BlobDataBuilder::GetFutureFileID(element); 154 uint64_t file_id = BlobDataBuilder::GetFutureFileID(element);
155 auto it = file_id_to_sizes.find(file_id); 155 auto it = file_id_to_sizes.find(file_id);
156 if (it != file_id_to_sizes.end()) 156 if (it != file_id_to_sizes.end())
157 it->second = std::max(it->second, element.offset() + element.length()); 157 it->second = std::max(it->second, element.offset() + element.length());
158 else 158 else
159 file_id_to_sizes[file_id] = element.offset() + element.length(); 159 file_id_to_sizes[file_id] = element.offset() + element.length();
160 total_size_output += element.length(); 160 total_size_output += element.length();
161 } 161 }
162 uint64_t sizes_from_files = 0;
162 for (const auto& size_pair : file_id_to_sizes) { 163 for (const auto& size_pair : file_id_to_sizes) {
163 file_sizes_output->push_back(size_pair.second); 164 file_sizes_output->push_back(size_pair.second);
165 sizes_from_files += size_pair.second;
164 } 166 }
167 DCHECK_EQ(sizes_from_files, total_size_output)
168 << "Illegal builder configuration, temporary files must be totally used.";
165 return total_size_output; 169 return total_size_output;
166 } 170 }
167 171
168 } // namespace 172 } // namespace
169 173
170 FileCreationInfo::FileCreationInfo() {} 174 FileCreationInfo::FileCreationInfo() {}
171 FileCreationInfo::~FileCreationInfo() { 175 FileCreationInfo::~FileCreationInfo() {
172 if (file.IsValid()) { 176 if (file.IsValid()) {
173 DCHECK(file_deletion_runner); 177 DCHECK(file_deletion_runner);
174 file_deletion_runner->PostTask( 178 file_deletion_runner->PostTask(
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 base::PostTaskAndReplyWithResult( 295 base::PostTaskAndReplyWithResult(
292 controller_->file_runner_.get(), FROM_HERE, 296 controller_->file_runner_.get(), FROM_HERE,
293 base::Bind(&CreateEmptyFiles, controller_->blob_storage_dir_, 297 base::Bind(&CreateEmptyFiles, controller_->blob_storage_dir_,
294 controller_->file_runner_, base::Passed(&file_paths)), 298 controller_->file_runner_, base::Passed(&file_paths)),
295 base::Bind(&FileQuotaAllocationTask::OnCreateEmptyFiles, 299 base::Bind(&FileQuotaAllocationTask::OnCreateEmptyFiles,
296 weak_factory_.GetWeakPtr(), base::Passed(&references))); 300 weak_factory_.GetWeakPtr(), base::Passed(&references)));
297 controller_->RecordTracingCounters(); 301 controller_->RecordTracingCounters();
298 } 302 }
299 ~FileQuotaAllocationTask() override {} 303 ~FileQuotaAllocationTask() override {}
300 304
301 void RunDoneCallback(bool success, std::vector<FileCreationInfo> file_info) { 305 void RunDoneCallback(std::vector<FileCreationInfo> file_info, bool success) {
302 // Make sure we clear the weak pointers we gave to the caller beforehand. 306 // Make sure we clear the weak pointers we gave to the caller beforehand.
303 weak_factory_.InvalidateWeakPtrs(); 307 weak_factory_.InvalidateWeakPtrs();
304 308
305 // We want to destroy this object on the exit of this method if we were 309 // We want to destroy this object on the exit of this method if we were
306 // successful. 310 // successful.
307 std::unique_ptr<FileQuotaAllocationTask> this_object; 311 std::unique_ptr<FileQuotaAllocationTask> this_object;
308 if (success) { 312 if (success) {
309 for (auto& item : pending_items_) { 313 for (auto& item : pending_items_) {
310 item->set_state(ShareableBlobDataItem::QUOTA_GRANTED); 314 item->set_state(ShareableBlobDataItem::QUOTA_GRANTED);
311 } 315 }
312 this_object = std::move(*my_list_position_); 316 this_object = std::move(*my_list_position_);
313 controller_->pending_file_quota_tasks_.erase(my_list_position_); 317 controller_->pending_file_quota_tasks_.erase(my_list_position_);
314 } 318 }
315 319
316 done_callback_.Run(success, std::move(file_info)); 320 done_callback_.Run(std::move(file_info), success);
317 } 321 }
318 322
319 base::WeakPtr<QuotaAllocationTask> GetWeakPtr() { 323 base::WeakPtr<QuotaAllocationTask> GetWeakPtr() {
320 return weak_factory_.GetWeakPtr(); 324 return weak_factory_.GetWeakPtr();
321 } 325 }
322 326
323 void Cancel() override { 327 void Cancel() override {
324 // This call destroys this object. We rely on ShareableFileReference's 328 // This call destroys this object. We rely on ShareableFileReference's
325 // final release callback for disk_usage_ accounting. 329 // final release callback for disk_usage_ accounting.
326 controller_->pending_file_quota_tasks_.erase(my_list_position_); 330 controller_->pending_file_quota_tasks_.erase(my_list_position_);
327 } 331 }
328 332
329 void OnCreateEmptyFiles( 333 void OnCreateEmptyFiles(
330 std::vector<scoped_refptr<ShareableFileReference>> references, 334 std::vector<scoped_refptr<ShareableFileReference>> references,
331 std::pair<std::vector<FileCreationInfo>, File::Error> files_and_error) { 335 std::pair<std::vector<FileCreationInfo>, File::Error> files_and_error) {
332 auto& files = files_and_error.first; 336 auto& files = files_and_error.first;
333 if (files.empty()) { 337 if (files.empty()) {
334 DCHECK_GE(controller_->disk_used_, allocation_size_); 338 DCHECK_GE(controller_->disk_used_, allocation_size_);
335 controller_->disk_used_ -= allocation_size_; 339 controller_->disk_used_ -= allocation_size_;
336 // This will call our callback and delete the object correctly. 340 // This will call our callback and delete the object correctly.
337 controller_->DisableFilePaging(files_and_error.second); 341 controller_->DisableFilePaging(files_and_error.second);
338 return; 342 return;
339 } 343 }
340 DCHECK_EQ(files.size(), references.size()); 344 DCHECK_EQ(files.size(), references.size());
341 for (size_t i = 0; i < files.size(); i++) { 345 for (size_t i = 0; i < files.size(); i++) {
342 files[i].file_reference = std::move(references[i]); 346 files[i].file_reference = std::move(references[i]);
343 } 347 }
344 RunDoneCallback(true, std::move(files)); 348 RunDoneCallback(std::move(files), true);
345 } 349 }
346 350
347 // The my_list_position_ iterator is stored so that we can remove ourself 351 // The my_list_position_ iterator is stored so that we can remove ourself
348 // from the task list when we are cancelled. 352 // from the task list when we are cancelled.
349 void set_my_list_position( 353 void set_my_list_position(
350 PendingFileQuotaTaskList::iterator my_list_position) { 354 PendingFileQuotaTaskList::iterator my_list_position) {
351 my_list_position_ = my_list_position; 355 my_list_position_ = my_list_position;
352 } 356 }
353 357
354 private: 358 private:
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 PendingMemoryQuotaTaskList old_memory_tasks; 395 PendingMemoryQuotaTaskList old_memory_tasks;
392 PendingFileQuotaTaskList old_file_tasks; 396 PendingFileQuotaTaskList old_file_tasks;
393 std::swap(old_memory_tasks, pending_memory_quota_tasks_); 397 std::swap(old_memory_tasks, pending_memory_quota_tasks_);
394 std::swap(old_file_tasks, pending_file_quota_tasks_); 398 std::swap(old_file_tasks, pending_file_quota_tasks_);
395 399
396 // Don't call the callbacks until we have a consistent state. 400 // Don't call the callbacks until we have a consistent state.
397 for (auto& memory_request : old_memory_tasks) { 401 for (auto& memory_request : old_memory_tasks) {
398 memory_request->RunDoneCallback(false); 402 memory_request->RunDoneCallback(false);
399 } 403 }
400 for (auto& file_request : old_file_tasks) { 404 for (auto& file_request : old_file_tasks) {
401 file_request->RunDoneCallback(false, std::vector<FileCreationInfo>()); 405 file_request->RunDoneCallback(std::vector<FileCreationInfo>(), false);
402 } 406 }
403 } 407 }
404 408
405 BlobMemoryController::Strategy BlobMemoryController::DetermineStrategy( 409 BlobMemoryController::Strategy BlobMemoryController::DetermineStrategy(
406 size_t preemptive_transported_bytes, 410 size_t preemptive_transported_bytes,
407 uint64_t total_transportation_bytes) const { 411 uint64_t total_transportation_bytes) const {
408 if (total_transportation_bytes == 0) 412 if (total_transportation_bytes == 0)
409 return Strategy::NONE_NEEDED; 413 return Strategy::NONE_NEEDED;
410 if (!CanReserveQuota(total_transportation_bytes)) 414 if (!CanReserveQuota(total_transportation_bytes))
411 return Strategy::TOO_LARGE; 415 return Strategy::TOO_LARGE;
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 MaybeGrantPendingMemoryRequests(); 742 MaybeGrantPendingMemoryRequests();
739 } 743 }
740 744
741 void BlobMemoryController::OnBlobFileDelete(uint64_t size, 745 void BlobMemoryController::OnBlobFileDelete(uint64_t size,
742 const FilePath& path) { 746 const FilePath& path) {
743 DCHECK_LE(size, disk_used_); 747 DCHECK_LE(size, disk_used_);
744 disk_used_ -= size; 748 disk_used_ -= size;
745 } 749 }
746 750
747 } // namespace storage 751 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698