net cleanup: Remove unnecessary namespace prefixes.
[chromium-blink-merge.git] / storage / browser / fileapi / quota / quota_reservation_buffer.h
blob0e893b65fb59796260e86343be195f6d6a36cee0
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_QUOTA_RESERVATION_BUFFER_H_
6 #define STORAGE_BROWSER_FILEAPI_QUOTA_QUOTA_RESERVATION_BUFFER_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/files/file.h"
12 #include "base/files/file_path.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15 #include "storage/browser/storage_browser_export.h"
16 #include "storage/common/fileapi/file_system_types.h"
17 #include "url/gurl.h"
19 namespace storage {
21 class QuotaReservation;
22 class OpenFileHandle;
23 class OpenFileHandleContext;
24 class QuotaReservationManager;
26 // QuotaReservationBuffer manages QuotaReservation instances. All consumed
27 // quota and leaked quota by associated QuotaReservation will be staged in
28 // QuotaReservationBuffer, and will be committed on a modified file is closed.
29 // The instance keeps alive while any associated QuotaReservation or
30 // OpenFileHandle alive.
31 // This class is usually manipulated only via OpenFileHandle and
32 // QuotaReservation.
33 class QuotaReservationBuffer : public base::RefCounted<QuotaReservationBuffer> {
34 public:
35 QuotaReservationBuffer(
36 base::WeakPtr<QuotaReservationManager> reservation_manager,
37 const GURL& origin,
38 FileSystemType type);
40 scoped_refptr<QuotaReservation> CreateReservation();
41 scoped_ptr<OpenFileHandle> GetOpenFileHandle(
42 QuotaReservation* reservation,
43 const base::FilePath& platform_path);
44 void CommitFileGrowth(int64 quota_consumption, int64 usage_delta);
45 void DetachOpenFileHandleContext(OpenFileHandleContext* context);
46 void PutReservationToBuffer(int64 size);
48 QuotaReservationManager* reservation_manager() {
49 return reservation_manager_.get();
52 const GURL& origin() const { return origin_; }
53 FileSystemType type() const { return type_; }
55 private:
56 friend class base::RefCounted<QuotaReservationBuffer>;
57 virtual ~QuotaReservationBuffer();
59 static bool DecrementDirtyCount(
60 base::WeakPtr<QuotaReservationManager> reservation_manager,
61 const GURL& origin,
62 FileSystemType type,
63 base::File::Error error,
64 int64 delta);
66 typedef std::map<base::FilePath, OpenFileHandleContext*>
67 OpenFileHandleContextByPath;
69 // Not owned. The destructor of OpenFileHandler should erase itself from
70 // |open_files_|.
71 OpenFileHandleContextByPath open_files_;
73 base::WeakPtr<QuotaReservationManager> reservation_manager_;
75 GURL origin_;
76 storage::FileSystemType type_;
78 int64 reserved_quota_;
80 base::SequenceChecker sequence_checker_;
82 DISALLOW_COPY_AND_ASSIGN(QuotaReservationBuffer);
85 } // namespace storage
87 #endif // STORAGE_BROWSER_FILEAPI_QUOTA_QUOTA_RESERVATION_BUFFER_H_