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 #ifndef STORAGE_BROWSER_FILE_SYSTEM_QUOTA_OPEN_FILE_HANDLE_CONTEXT_H_
6 #define STORAGE_BROWSER_FILE_SYSTEM_QUOTA_OPEN_FILE_HANDLE_CONTEXT_H_
7 
8 #include <stdint.h>
9 
10 #include <map>
11 
12 #include "base/files/file_path.h"
13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h"
16 #include "storage/common/file_system/file_system_types.h"
17 #include "url/gurl.h"
18 
19 namespace storage {
20 
21 class QuotaReservationBuffer;
22 
23 // This class represents a underlying file of a managed FileSystem file.
24 // The instance keeps alive while at least one consumer keeps an open file
25 // handle.
26 // This class is usually manipulated only via OpenFileHandle.
27 class OpenFileHandleContext : public base::RefCounted<OpenFileHandleContext> {
28  public:
29   OpenFileHandleContext(const base::FilePath& platform_path,
30                         QuotaReservationBuffer* reservation_buffer);
31 
32   // Updates the max written offset and returns the amount of growth.
33   int64_t UpdateMaxWrittenOffset(int64_t offset);
34 
35   void AddAppendModeWriteAmount(int64_t amount);
36 
platform_path()37   const base::FilePath& platform_path() const { return platform_path_; }
38 
39   int64_t GetEstimatedFileSize() const;
40   int64_t GetMaxWrittenOffset() const;
41 
42  private:
43   friend class base::RefCounted<OpenFileHandleContext>;
44   virtual ~OpenFileHandleContext();
45 
46   int64_t initial_file_size_;
47   int64_t maximum_written_offset_;
48   int64_t append_mode_write_amount_;
49   base::FilePath platform_path_;
50 
51   scoped_refptr<QuotaReservationBuffer> reservation_buffer_;
52 
53   base::SequenceChecker sequence_checker_;
54 
55   DISALLOW_COPY_AND_ASSIGN(OpenFileHandleContext);
56 };
57 
58 }  // namespace storage
59 
60 #endif  // STORAGE_BROWSER_FILE_SYSTEM_QUOTA_OPEN_FILE_HANDLE_CONTEXT_H_
61