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

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

Issue 539143002: Migrate webkit/browser/ to storage/browser/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/browser/fileapi/quota/quota_reservation.h"
6
7 #include "base/bind.h"
8 #include "webkit/browser/fileapi/quota/open_file_handle.h"
9 #include "webkit/browser/fileapi/quota/quota_reservation_buffer.h"
10
11 namespace storage {
12
13 void QuotaReservation::RefreshReservation(
14 int64 size,
15 const StatusCallback& callback) {
16 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
17 DCHECK(!running_refresh_request_);
18 DCHECK(!client_crashed_);
19 if (!reservation_manager())
20 return;
21
22 running_refresh_request_ = true;
23
24 reservation_manager()->ReserveQuota(
25 origin(), type(), size - remaining_quota_,
26 base::Bind(&QuotaReservation::AdaptDidUpdateReservedQuota,
27 weak_ptr_factory_.GetWeakPtr(),
28 remaining_quota_, callback));
29
30 if (running_refresh_request_)
31 remaining_quota_ = 0;
32 }
33
34 scoped_ptr<OpenFileHandle> QuotaReservation::GetOpenFileHandle(
35 const base::FilePath& platform_path) {
36 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
37 DCHECK(!client_crashed_);
38 return reservation_buffer_->GetOpenFileHandle(this, platform_path);
39 }
40
41 void QuotaReservation::OnClientCrash() {
42 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
43 client_crashed_ = true;
44
45 if (remaining_quota_) {
46 reservation_buffer_->PutReservationToBuffer(remaining_quota_);
47 remaining_quota_ = 0;
48 }
49 }
50
51 void QuotaReservation::ConsumeReservation(int64 size) {
52 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
53 DCHECK_LT(0, size);
54 DCHECK_LE(size, remaining_quota_);
55 if (client_crashed_)
56 return;
57
58 remaining_quota_ -= size;
59 reservation_buffer_->PutReservationToBuffer(size);
60 }
61
62 QuotaReservationManager* QuotaReservation::reservation_manager() {
63 return reservation_buffer_->reservation_manager();
64 }
65
66 const GURL& QuotaReservation::origin() const {
67 return reservation_buffer_->origin();
68 }
69
70 FileSystemType QuotaReservation::type() const {
71 return reservation_buffer_->type();
72 }
73
74 QuotaReservation::QuotaReservation(
75 QuotaReservationBuffer* reservation_buffer)
76 : client_crashed_(false),
77 running_refresh_request_(false),
78 remaining_quota_(0),
79 reservation_buffer_(reservation_buffer),
80 weak_ptr_factory_(this) {
81 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
82 }
83
84 QuotaReservation::~QuotaReservation() {
85 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
86
87 if (remaining_quota_ && reservation_manager()) {
88 reservation_manager()->ReleaseReservedQuota(
89 origin(), type(), remaining_quota_);
90 }
91 }
92
93 // static
94 bool QuotaReservation::AdaptDidUpdateReservedQuota(
95 const base::WeakPtr<QuotaReservation>& reservation,
96 int64 previous_size,
97 const StatusCallback& callback,
98 base::File::Error error,
99 int64 delta) {
100 if (!reservation)
101 return false;
102
103 return reservation->DidUpdateReservedQuota(
104 previous_size, callback, error, delta);
105 }
106
107 bool QuotaReservation::DidUpdateReservedQuota(
108 int64 previous_size,
109 const StatusCallback& callback,
110 base::File::Error error,
111 int64 delta) {
112 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
113 DCHECK(running_refresh_request_);
114 running_refresh_request_ = false;
115
116 if (client_crashed_) {
117 callback.Run(base::File::FILE_ERROR_ABORT);
118 return false;
119 }
120
121 if (error == base::File::FILE_OK)
122 remaining_quota_ = previous_size + delta;
123 callback.Run(error);
124 return true;
125 }
126
127 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698