Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: content/browser/renderer_host/pepper/quota_reservation.h

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_QUOTA_RESERVATION_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_QUOTA_RESERVATION_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_QUOTA_RESERVATION_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_QUOTA_RESERVATION_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "content/common/content_export.h" 12 #include "content/common/content_export.h"
13 #include "ppapi/c/pp_stdint.h" // For int64_t on Windows. 13 #include "ppapi/c/pp_stdint.h" // For int64_t on Windows.
14 #include "ppapi/shared_impl/file_growth.h" 14 #include "ppapi/shared_impl/file_growth.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 #include "webkit/browser/fileapi/file_system_context.h" 16 #include "storage/browser/fileapi/file_system_context.h"
17 17
18 namespace fileapi { 18 namespace storage {
19 class FileSystemURL; 19 class FileSystemURL;
20 class OpenFileHandle; 20 class OpenFileHandle;
21 class QuotaReservation; 21 class QuotaReservation;
22 } 22 }
23 23
24 namespace content { 24 namespace content {
25 25
26 struct QuotaReservationDeleter; 26 struct QuotaReservationDeleter;
27 27
28 // This class holds a QuotaReservation and manages OpenFileHandles for checking 28 // This class holds a QuotaReservation and manages OpenFileHandles for checking
29 // quota. It should be created, used, and destroyed on a FileSystemContext's 29 // quota. It should be created, used, and destroyed on a FileSystemContext's
30 // default_file_task_runner() instance. This is a RefCountedThreadSafe object 30 // default_file_task_runner() instance. This is a RefCountedThreadSafe object
31 // because it needs to be passed to the file thread and kept alive during 31 // because it needs to be passed to the file thread and kept alive during
32 // potentially long-running quota operations. 32 // potentially long-running quota operations.
33 class CONTENT_EXPORT QuotaReservation 33 class CONTENT_EXPORT QuotaReservation
34 : public base::RefCountedThreadSafe<QuotaReservation, 34 : public base::RefCountedThreadSafe<QuotaReservation,
35 QuotaReservationDeleter> { 35 QuotaReservationDeleter> {
36 public: 36 public:
37 // Static method to facilitate construction on the file task runner. 37 // Static method to facilitate construction on the file task runner.
38 static scoped_refptr<QuotaReservation> Create( 38 static scoped_refptr<QuotaReservation> Create(
39 scoped_refptr<fileapi::FileSystemContext> file_system_context, 39 scoped_refptr<storage::FileSystemContext> file_system_context,
40 const GURL& origin_url, 40 const GURL& origin_url,
41 fileapi::FileSystemType file_system_type); 41 storage::FileSystemType file_system_type);
42 42
43 // Opens a file with the given id and path and returns its current size. 43 // Opens a file with the given id and path and returns its current size.
44 int64_t OpenFile(int32_t id, const fileapi::FileSystemURL& url); 44 int64_t OpenFile(int32_t id, const storage::FileSystemURL& url);
45 // Closes the file opened by OpenFile with the given id. 45 // Closes the file opened by OpenFile with the given id.
46 void CloseFile(int32_t id, const ppapi::FileGrowth& file_growth); 46 void CloseFile(int32_t id, const ppapi::FileGrowth& file_growth);
47 // Refreshes the quota reservation to a new amount. A map that associates file 47 // Refreshes the quota reservation to a new amount. A map that associates file
48 // ids with maximum written offsets is provided as input. The callback will 48 // ids with maximum written offsets is provided as input. The callback will
49 // receive a similar map with the updated file sizes. 49 // receive a similar map with the updated file sizes.
50 typedef base::Callback<void(int64_t, const ppapi::FileSizeMap&)> 50 typedef base::Callback<void(int64_t, const ppapi::FileSizeMap&)>
51 ReserveQuotaCallback; 51 ReserveQuotaCallback;
52 void ReserveQuota(int64_t amount, 52 void ReserveQuota(int64_t amount,
53 const ppapi::FileGrowthMap& file_growth, 53 const ppapi::FileGrowthMap& file_growth,
54 const ReserveQuotaCallback& callback); 54 const ReserveQuotaCallback& callback);
55 55
56 // Notifies underlying QuotaReservation that the associated client crashed, 56 // Notifies underlying QuotaReservation that the associated client crashed,
57 // and that the reserved quota is no longer traceable. 57 // and that the reserved quota is no longer traceable.
58 void OnClientCrash(); 58 void OnClientCrash();
59 59
60 private: 60 private:
61 friend class base::RefCountedThreadSafe<QuotaReservation, 61 friend class base::RefCountedThreadSafe<QuotaReservation,
62 QuotaReservationDeleter>; 62 QuotaReservationDeleter>;
63 friend class base::DeleteHelper<QuotaReservation>; 63 friend class base::DeleteHelper<QuotaReservation>;
64 friend struct QuotaReservationDeleter; 64 friend struct QuotaReservationDeleter;
65 friend class QuotaReservationTest; 65 friend class QuotaReservationTest;
66 66
67 QuotaReservation( 67 QuotaReservation(
68 scoped_refptr<fileapi::FileSystemContext> file_system_context, 68 scoped_refptr<storage::FileSystemContext> file_system_context,
69 const GURL& origin_url, 69 const GURL& origin_url,
70 fileapi::FileSystemType file_system_type); 70 storage::FileSystemType file_system_type);
71 71
72 // For unit testing only. A QuotaReservation intended for unit testing will 72 // For unit testing only. A QuotaReservation intended for unit testing will
73 // have file_system_context_ == NULL. 73 // have file_system_context_ == NULL.
74 QuotaReservation(scoped_refptr<fileapi::QuotaReservation> quota_reservation, 74 QuotaReservation(scoped_refptr<storage::QuotaReservation> quota_reservation,
75 const GURL& origin_url, 75 const GURL& origin_url,
76 fileapi::FileSystemType file_system_type); 76 storage::FileSystemType file_system_type);
77 77
78 ~QuotaReservation(); 78 ~QuotaReservation();
79 79
80 void GotReservedQuota(const ReserveQuotaCallback& callback, 80 void GotReservedQuota(const ReserveQuotaCallback& callback,
81 base::File::Error error); 81 base::File::Error error);
82 82
83 void DeleteOnCorrectThread() const; 83 void DeleteOnCorrectThread() const;
84 84
85 scoped_refptr<fileapi::FileSystemContext> file_system_context_; 85 scoped_refptr<storage::FileSystemContext> file_system_context_;
86 scoped_refptr<fileapi::QuotaReservation> quota_reservation_; 86 scoped_refptr<storage::QuotaReservation> quota_reservation_;
87 typedef std::map<int32_t, fileapi::OpenFileHandle*> FileMap; 87 typedef std::map<int32_t, storage::OpenFileHandle*> FileMap;
88 FileMap files_; 88 FileMap files_;
89 89
90 DISALLOW_COPY_AND_ASSIGN(QuotaReservation); 90 DISALLOW_COPY_AND_ASSIGN(QuotaReservation);
91 }; 91 };
92 92
93 struct QuotaReservationDeleter { 93 struct QuotaReservationDeleter {
94 static void Destruct(const QuotaReservation* quota_reservation) { 94 static void Destruct(const QuotaReservation* quota_reservation) {
95 quota_reservation->DeleteOnCorrectThread(); 95 quota_reservation->DeleteOnCorrectThread();
96 } 96 }
97 }; 97 };
98 98
99 } // namespace content 99 } // namespace content
100 100
101 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_QUOTA_RESERVATION_H_ 101 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_QUOTA_RESERVATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698