Include all dupe types (event when value is zero) in scan stats.
[chromium-blink-merge.git] / storage / browser / fileapi / quota / open_file_handle.h
blob8954b1db71f9470e94ab6013c04d58e1570f22d6
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.
5 #ifndef STORAGE_BROWSER_FILEAPI_QUOTA_OPEN_FILE_HANDLE_H_
6 #define STORAGE_BROWSER_FILEAPI_QUOTA_OPEN_FILE_HANDLE_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "storage/browser/storage_browser_export.h"
13 namespace base {
14 class FilePath;
17 namespace storage {
19 class QuotaReservation;
20 class OpenFileHandleContext;
21 class QuotaReservationBuffer;
23 // Represents an open file like a file descriptor.
24 // This should be alive while a consumer keeps a file opened and should be
25 // deleted when the plugin closes the file.
26 class STORAGE_EXPORT OpenFileHandle {
27 public:
28 ~OpenFileHandle();
30 // Updates cached file size and consumes quota for that.
31 // Both this and AddAppendModeWriteAmount should be called for each modified
32 // file before calling QuotaReservation::RefreshQuota and before closing the
33 // file.
34 void UpdateMaxWrittenOffset(int64 offset);
36 // Notifies that |amount| of data is written to the file in append mode, and
37 // consumes quota for that.
38 // Both this and UpdateMaxWrittenOffset should be called for each modified
39 // file before calling QuotaReservation::RefreshQuota and before closing the
40 // file.
41 void AddAppendModeWriteAmount(int64 amount);
43 // Returns the estimated file size for the quota consumption calculation.
44 // The client must consume its reserved quota when it writes data to the file
45 // beyond the estimated file size.
46 // The estimated file size is greater than or equal to actual file size after
47 // all clients report their file usage, and is monotonically increasing over
48 // OpenFileHandle object life cycle, so that client may cache the value.
49 int64 GetEstimatedFileSize() const;
51 int64 GetMaxWrittenOffset() const;
52 const base::FilePath& platform_path() const;
54 private:
55 friend class QuotaReservationBuffer;
57 OpenFileHandle(QuotaReservation* reservation,
58 OpenFileHandleContext* context);
60 scoped_refptr<QuotaReservation> reservation_;
61 scoped_refptr<OpenFileHandleContext> context_;
63 base::SequenceChecker sequence_checker_;
65 DISALLOW_COPY_AND_ASSIGN(OpenFileHandle);
68 } // namespace storage
70 #endif // STORAGE_BROWSER_FILEAPI_QUOTA_OPEN_FILE_HANDLE_H_