summaryrefslogtreecommitdiffstats
path: root/webkit/browser/fileapi/quota/open_file_handle.h
blob: 79f1380a4372cd798cb1dbc529249b0dae2b358d (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
// 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.

#ifndef WEBKIT_BROWSER_FILEAPI_QUOTA_OPEN_FILE_HANDLE_H_
#define WEBKIT_BROWSER_FILEAPI_QUOTA_OPEN_FILE_HANDLE_H_

#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "webkit/browser/webkit_storage_browser_export.h"

namespace fileapi {

class QuotaReservation;
class OpenFileHandleContext;
class QuotaReservationBuffer;

// Represents an open file like a file descriptor.
// This should be alive while a consumer keeps a file opened and should be
// deleted when the plugin closes the file.
class WEBKIT_STORAGE_BROWSER_EXPORT OpenFileHandle {
 public:
  ~OpenFileHandle();

  // Updates cached file size and consumes quota for that.
  // This should be called for each modified file before calling RefreshQuota
  // and file close.
  // Returns updated base file size that should be used to measure quota
  // consumption by difference to this.
  int64 UpdateMaxWrittenOffset(int64 offset);

  int64 base_file_size() const;

 private:
  friend class QuotaReservationBuffer;

  OpenFileHandle(QuotaReservation* reservation,
                 OpenFileHandleContext* context);

  scoped_refptr<QuotaReservation> reservation_;
  scoped_refptr<OpenFileHandleContext> context_;

  base::SequenceChecker sequence_checker_;

  DISALLOW_COPY_AND_ASSIGN(OpenFileHandle);
};

}  // namespace fileapi

#endif  // WEBKIT_BROWSER_FILEAPI_QUOTA_OPEN_FILE_HANDLE_H_