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

Side by Side Diff: storage/browser/fileapi/quota/quota_reservation_buffer.cc

Issue 2189113002: Rename CalledOnValidSequencedThread() to CalledOnValidSequence(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/fileapi/quota/quota_reservation_buffer.h" 5 #include "storage/browser/fileapi/quota/quota_reservation_buffer.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "storage/browser/fileapi/quota/open_file_handle.h" 13 #include "storage/browser/fileapi/quota/open_file_handle.h"
14 #include "storage/browser/fileapi/quota/open_file_handle_context.h" 14 #include "storage/browser/fileapi/quota/open_file_handle_context.h"
15 #include "storage/browser/fileapi/quota/quota_reservation.h" 15 #include "storage/browser/fileapi/quota/quota_reservation.h"
16 16
17 namespace storage { 17 namespace storage {
18 18
19 QuotaReservationBuffer::QuotaReservationBuffer( 19 QuotaReservationBuffer::QuotaReservationBuffer(
20 base::WeakPtr<QuotaReservationManager> reservation_manager, 20 base::WeakPtr<QuotaReservationManager> reservation_manager,
21 const GURL& origin, 21 const GURL& origin,
22 FileSystemType type) 22 FileSystemType type)
23 : reservation_manager_(reservation_manager), 23 : reservation_manager_(reservation_manager),
24 origin_(origin), 24 origin_(origin),
25 type_(type), 25 type_(type),
26 reserved_quota_(0) { 26 reserved_quota_(0) {
27 DCHECK(origin.is_valid()); 27 DCHECK(origin.is_valid());
28 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 28 DCHECK(sequence_checker_.CalledOnValidSequence());
29 reservation_manager_->IncrementDirtyCount(origin, type); 29 reservation_manager_->IncrementDirtyCount(origin, type);
30 } 30 }
31 31
32 scoped_refptr<QuotaReservation> QuotaReservationBuffer::CreateReservation() { 32 scoped_refptr<QuotaReservation> QuotaReservationBuffer::CreateReservation() {
33 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 33 DCHECK(sequence_checker_.CalledOnValidSequence());
34 return make_scoped_refptr(new QuotaReservation(this)); 34 return make_scoped_refptr(new QuotaReservation(this));
35 } 35 }
36 36
37 std::unique_ptr<OpenFileHandle> QuotaReservationBuffer::GetOpenFileHandle( 37 std::unique_ptr<OpenFileHandle> QuotaReservationBuffer::GetOpenFileHandle(
38 QuotaReservation* reservation, 38 QuotaReservation* reservation,
39 const base::FilePath& platform_path) { 39 const base::FilePath& platform_path) {
40 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 40 DCHECK(sequence_checker_.CalledOnValidSequence());
41 OpenFileHandleContext** open_file = &open_files_[platform_path]; 41 OpenFileHandleContext** open_file = &open_files_[platform_path];
42 if (!*open_file) 42 if (!*open_file)
43 *open_file = new OpenFileHandleContext(platform_path, this); 43 *open_file = new OpenFileHandleContext(platform_path, this);
44 return base::WrapUnique(new OpenFileHandle(reservation, *open_file)); 44 return base::WrapUnique(new OpenFileHandle(reservation, *open_file));
45 } 45 }
46 46
47 void QuotaReservationBuffer::CommitFileGrowth( 47 void QuotaReservationBuffer::CommitFileGrowth(
48 int64_t reserved_quota_consumption, 48 int64_t reserved_quota_consumption,
49 int64_t usage_delta) { 49 int64_t usage_delta) {
50 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 50 DCHECK(sequence_checker_.CalledOnValidSequence());
51 if (!reservation_manager_) 51 if (!reservation_manager_)
52 return; 52 return;
53 reservation_manager_->CommitQuotaUsage(origin_, type_, usage_delta); 53 reservation_manager_->CommitQuotaUsage(origin_, type_, usage_delta);
54 54
55 if (reserved_quota_consumption > 0) { 55 if (reserved_quota_consumption > 0) {
56 if (reserved_quota_consumption > reserved_quota_) { 56 if (reserved_quota_consumption > reserved_quota_) {
57 LOG(ERROR) << "Detected over consumption of the storage quota beyond its" 57 LOG(ERROR) << "Detected over consumption of the storage quota beyond its"
58 << " reservation"; 58 << " reservation";
59 reserved_quota_consumption = reserved_quota_; 59 reserved_quota_consumption = reserved_quota_;
60 } 60 }
61 61
62 reserved_quota_ -= reserved_quota_consumption; 62 reserved_quota_ -= reserved_quota_consumption;
63 reservation_manager_->ReleaseReservedQuota( 63 reservation_manager_->ReleaseReservedQuota(
64 origin_, type_, reserved_quota_consumption); 64 origin_, type_, reserved_quota_consumption);
65 } 65 }
66 } 66 }
67 67
68 void QuotaReservationBuffer::DetachOpenFileHandleContext( 68 void QuotaReservationBuffer::DetachOpenFileHandleContext(
69 OpenFileHandleContext* open_file) { 69 OpenFileHandleContext* open_file) {
70 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 70 DCHECK(sequence_checker_.CalledOnValidSequence());
71 DCHECK_EQ(open_file, open_files_[open_file->platform_path()]); 71 DCHECK_EQ(open_file, open_files_[open_file->platform_path()]);
72 open_files_.erase(open_file->platform_path()); 72 open_files_.erase(open_file->platform_path());
73 } 73 }
74 74
75 void QuotaReservationBuffer::PutReservationToBuffer(int64_t reservation) { 75 void QuotaReservationBuffer::PutReservationToBuffer(int64_t reservation) {
76 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 76 DCHECK(sequence_checker_.CalledOnValidSequence());
77 DCHECK_LE(0, reservation); 77 DCHECK_LE(0, reservation);
78 reserved_quota_ += reservation; 78 reserved_quota_ += reservation;
79 } 79 }
80 80
81 QuotaReservationBuffer::~QuotaReservationBuffer() { 81 QuotaReservationBuffer::~QuotaReservationBuffer() {
82 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 82 DCHECK(sequence_checker_.CalledOnValidSequence());
83 if (!reservation_manager_) 83 if (!reservation_manager_)
84 return; 84 return;
85 85
86 DCHECK_LE(0, reserved_quota_); 86 DCHECK_LE(0, reserved_quota_);
87 if (reserved_quota_ && reservation_manager_) { 87 if (reserved_quota_ && reservation_manager_) {
88 reservation_manager_->ReserveQuota( 88 reservation_manager_->ReserveQuota(
89 origin_, type_, -reserved_quota_, 89 origin_, type_, -reserved_quota_,
90 base::Bind(&QuotaReservationBuffer::DecrementDirtyCount, 90 base::Bind(&QuotaReservationBuffer::DecrementDirtyCount,
91 reservation_manager_, origin_, type_)); 91 reservation_manager_, origin_, type_));
92 } 92 }
93 reservation_manager_->ReleaseReservationBuffer(this); 93 reservation_manager_->ReleaseReservationBuffer(this);
94 } 94 }
95 95
96 // static 96 // static
97 bool QuotaReservationBuffer::DecrementDirtyCount( 97 bool QuotaReservationBuffer::DecrementDirtyCount(
98 base::WeakPtr<QuotaReservationManager> reservation_manager, 98 base::WeakPtr<QuotaReservationManager> reservation_manager,
99 const GURL& origin, 99 const GURL& origin,
100 FileSystemType type, 100 FileSystemType type,
101 base::File::Error error, 101 base::File::Error error,
102 int64_t delta_unused) { 102 int64_t delta_unused) {
103 DCHECK(origin.is_valid()); 103 DCHECK(origin.is_valid());
104 if (error == base::File::FILE_OK && reservation_manager) { 104 if (error == base::File::FILE_OK && reservation_manager) {
105 reservation_manager->DecrementDirtyCount(origin, type); 105 reservation_manager->DecrementDirtyCount(origin, type);
106 return true; 106 return true;
107 } 107 }
108 return false; 108 return false;
109 } 109 }
110 110
111 } // namespace storage 111 } // namespace storage
OLDNEW
« no previous file with comments | « storage/browser/fileapi/quota/quota_reservation.cc ('k') | storage/browser/fileapi/quota/quota_reservation_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698