summaryrefslogtreecommitdiffstats
path: root/storage/browser/fileapi/quota/open_file_handle.cc
blob: 88424381d34400480b32f502e0ef0d6e3b6607e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "storage/browser/fileapi/quota/open_file_handle.h"

#include "storage/browser/fileapi/quota/open_file_handle_context.h"
#include "storage/browser/fileapi/quota/quota_reservation.h"

namespace storage {

OpenFileHandle::~OpenFileHandle() {
  DCHECK(sequence_checker_.CalledOnValidSequencedThread());
}

void OpenFileHandle::UpdateMaxWrittenOffset(int64 offset) {
  DCHECK(sequence_checker_.CalledOnValidSequencedThread());

  int64 growth = context_->UpdateMaxWrittenOffset(offset);
  if (growth > 0)
    reservation_->ConsumeReservation(growth);
}

void OpenFileHandle::AddAppendModeWriteAmount(int64 amount) {
  DCHECK(sequence_checker_.CalledOnValidSequencedThread());
  if (amount <= 0)
    return;

  context_->AddAppendModeWriteAmount(amount);
  reservation_->ConsumeReservation(amount);
}

int64 OpenFileHandle::GetEstimatedFileSize() const {
  DCHECK(sequence_checker_.CalledOnValidSequencedThread());
  return context_->GetEstimatedFileSize();
}

int64 OpenFileHandle::GetMaxWrittenOffset() const {
  DCHECK(sequence_checker_.CalledOnValidSequencedThread());
  return context_->GetMaxWrittenOffset();
}

const base::FilePath& OpenFileHandle::platform_path() const {
  DCHECK(sequence_checker_.CalledOnValidSequencedThread());
  return context_->platform_path();
}

OpenFileHandle::OpenFileHandle(QuotaReservation* reservation,
                               OpenFileHandleContext* context)
    : reservation_(reservation),
      context_(context) {
  DCHECK(sequence_checker_.CalledOnValidSequencedThread());
}

}  // namespace storage