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

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

Issue 61593002: Quota: Implement QuotaBackendImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix Created 7 years, 1 month 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 | Annotate | Revision Log
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 "webkit/browser/fileapi/quota/quota_reservation_buffer.h" 5 #include "webkit/browser/fileapi/quota/quota_reservation_buffer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "webkit/browser/fileapi/quota/open_file_handle.h" 8 #include "webkit/browser/fileapi/quota/open_file_handle.h"
9 #include "webkit/browser/fileapi/quota/open_file_handle_context.h" 9 #include "webkit/browser/fileapi/quota/open_file_handle_context.h"
10 #include "webkit/browser/fileapi/quota/quota_reservation.h" 10 #include "webkit/browser/fileapi/quota/quota_reservation.h"
11 11
12 namespace fileapi { 12 namespace fileapi {
13 13
14 namespace { 14 namespace {
15 15
16 void IgnoreResult(base::PlatformFileError error) {} 16 void IgnoreResult(base::PlatformFileError error) {}
17 17
18 } // namespace 18 } // namespace
19 19
20 QuotaReservationBuffer::QuotaReservationBuffer( 20 QuotaReservationBuffer::QuotaReservationBuffer(
21 base::WeakPtr<QuotaReservationManager> reservation_manager, 21 base::WeakPtr<QuotaReservationManager> reservation_manager,
22 const GURL& origin, 22 const GURL& origin,
23 FileSystemType type) 23 FileSystemType type)
24 : reservation_manager_(reservation_manager), 24 : reservation_manager_(reservation_manager),
25 origin_(origin), 25 origin_(origin),
26 type_(type), 26 type_(type),
27 reserved_quota_(0) { 27 reserved_quota_(0) {
28 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 28 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
29 reservation_manager_->IncreaseDirtyCount(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_.CalledOnValidSequencedThread());
34 return make_scoped_refptr(new QuotaReservation(this)); 34 return make_scoped_refptr(new QuotaReservation(this));
35 } 35 }
36 36
37 scoped_ptr<OpenFileHandle> QuotaReservationBuffer::GetOpenFileHandle( 37 scoped_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_.CalledOnValidSequencedThread());
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 make_scoped_ptr(new OpenFileHandle(reservation, *open_file)); 44 return make_scoped_ptr(new OpenFileHandle(reservation, *open_file));
45 } 45 }
46 46
47 void QuotaReservationBuffer::CommitFileGrowth(int64 quota_consumption, 47 void QuotaReservationBuffer::CommitFileGrowth(int64 quota_consumption,
48 int64 usage_delta) { 48 int64 usage_delta) {
49 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 49 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
50 if (!reservation_manager_) 50 if (!reservation_manager_)
51 return; 51 return;
52 52 reservation_manager_->CommitQuotaUsage(origin_, type_, usage_delta);
53 reservation_manager_->CommitQuotaUsage(
54 origin_, type_, usage_delta,
55 base::Bind(&IgnoreResult));
56 53
57 DCHECK_LE(quota_consumption, reserved_quota_); 54 DCHECK_LE(quota_consumption, reserved_quota_);
58 if (quota_consumption > 0) { 55 if (quota_consumption > 0) {
59 reserved_quota_ -= quota_consumption; 56 reserved_quota_ -= quota_consumption;
60 reservation_manager_->ReleaseReservedQuota( 57 reservation_manager_->ReleaseReservedQuota(
61 origin_, type_, quota_consumption); 58 origin_, type_, quota_consumption);
62 } 59 }
63 } 60 }
64 61
65 void QuotaReservationBuffer::DetachOpenFileHandleContext( 62 void QuotaReservationBuffer::DetachOpenFileHandleContext(
(...skipping 11 matching lines...) Expand all
77 74
78 QuotaReservationBuffer::~QuotaReservationBuffer() { 75 QuotaReservationBuffer::~QuotaReservationBuffer() {
79 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 76 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
80 if (!reservation_manager_) 77 if (!reservation_manager_)
81 return; 78 return;
82 79
83 DCHECK_LE(0, reserved_quota_); 80 DCHECK_LE(0, reserved_quota_);
84 if (reserved_quota_ && reservation_manager_) { 81 if (reserved_quota_ && reservation_manager_) {
85 reservation_manager_->ReserveQuota( 82 reservation_manager_->ReserveQuota(
86 origin_, type_, -reserved_quota_, 83 origin_, type_, -reserved_quota_,
87 base::Bind(&QuotaReservationBuffer::DecreaseDirtyCount, 84 base::Bind(&QuotaReservationBuffer::DecrementDirtyCount,
88 reservation_manager_, origin_, type_)); 85 reservation_manager_, origin_, type_));
89 } 86 }
90 reservation_manager_->ReleaseReservationBuffer(this); 87 reservation_manager_->ReleaseReservationBuffer(this);
91 } 88 }
92 89
93 // static 90 // static
94 bool QuotaReservationBuffer::DecreaseDirtyCount( 91 bool QuotaReservationBuffer::DecrementDirtyCount(
95 base::WeakPtr<QuotaReservationManager> reservation_manager, 92 base::WeakPtr<QuotaReservationManager> reservation_manager,
96 const GURL& origin, 93 const GURL& origin,
97 FileSystemType type, 94 FileSystemType type,
98 base::PlatformFileError error) { 95 base::PlatformFileError error) {
99 if (error == base::PLATFORM_FILE_OK && reservation_manager) { 96 if (error == base::PLATFORM_FILE_OK && reservation_manager) {
100 reservation_manager->DecreaseDirtyCount(origin, type); 97 reservation_manager->DecrementDirtyCount(origin, type);
101 return true; 98 return true;
102 } 99 }
103 return false; 100 return false;
104 } 101 }
105 102
106 103
107 } // namespace fileapi 104 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/quota/quota_reservation_buffer.h ('k') | webkit/browser/fileapi/quota/quota_reservation_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698