1 // Copyright (c) 2011 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 WEBKIT_FILEAPI_FILE_SYSTEM_QUOTA_UTIL_H_
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_QUOTA_UTIL_H_
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "googleurl/src/gurl.h"
14 #include "webkit/fileapi/file_system_types.h"
17 class MessageLoopProxy
;
21 class QuotaManagerProxy
;
26 // An abstract interface that provides common quota-related utility functions
27 // for internal filesystem modules. The main consumer of this class is
28 // file_system_quota_client and quota_file_util.
29 // All the methods of this class are synchronous and need to be called on
30 // the thread that the method name implies.
31 class FileSystemQuotaUtil
{
33 // Methods of this class can be called on any thread.
34 class Proxy
: public base::RefCountedThreadSafe
<Proxy
> {
36 void UpdateOriginUsage(quota::QuotaManagerProxy
* proxy
,
37 const GURL
& origin_url
,
38 fileapi::FileSystemType type
,
40 void StartUpdateOrigin(const GURL
& origin_url
,
41 fileapi::FileSystemType type
);
42 void EndUpdateOrigin(const GURL
& origin_url
,
43 fileapi::FileSystemType type
);
46 friend class FileSystemQuotaUtil
;
47 friend class base::RefCountedThreadSafe
<Proxy
>;
48 Proxy(FileSystemQuotaUtil
* quota_handler
,
49 base::MessageLoopProxy
* file_thread
);
52 FileSystemQuotaUtil
* quota_util_
; // Accessed only on the FILE thread.
53 scoped_refptr
<base::MessageLoopProxy
> file_thread_
;
54 DISALLOW_COPY_AND_ASSIGN(Proxy
);
57 // Called by quota client.
58 virtual void GetOriginsForTypeOnFileThread(fileapi::FileSystemType type
,
59 std::set
<GURL
>* origins
) = 0;
61 // Called by quota client.
62 virtual void GetOriginsForHostOnFileThread(fileapi::FileSystemType type
,
63 const std::string
& host
,
64 std::set
<GURL
>* origins
) = 0;
66 // Called by quota client.
67 // Returns the amount of data used for the origin for usage tracking.
68 virtual int64
GetOriginUsageOnFileThread(const GURL
& origin_url
,
69 fileapi::FileSystemType type
) = 0;
71 // Called by quota file util.
72 virtual void UpdateOriginUsageOnFileThread(quota::QuotaManagerProxy
* proxy
,
73 const GURL
& origin_url
,
74 fileapi::FileSystemType type
,
77 // Called by file_system_operation.
78 // Called when a read operation accesses the origin's storage data.
79 virtual void NotifyOriginWasAccessedOnIOThread(
80 quota::QuotaManagerProxy
* proxy
,
81 const GURL
& origin_url
,
82 fileapi::FileSystemType type
) = 0;
84 // Called by quota_file_util or file_writer_delegate.
85 // Called before a write operation modifies the origin's storage data.
86 virtual void StartUpdateOriginOnFileThread(const GURL
& origin_url
,
87 fileapi::FileSystemType type
) = 0;
89 // Called by quota_file_util or file_writer_delegate.
90 // Called after a write operation modifies the origin's storage data.
91 virtual void EndUpdateOriginOnFileThread(const GURL
& origin_url
,
92 fileapi::FileSystemType type
) = 0;
94 virtual void InvalidateUsageCache(const GURL
& origin_url
,
95 fileapi::FileSystemType type
) = 0;
97 Proxy
* proxy() { return proxy_
.get(); }
100 explicit FileSystemQuotaUtil(base::MessageLoopProxy
* file_thread
);
101 virtual ~FileSystemQuotaUtil();
104 scoped_refptr
<Proxy
> proxy_
;
107 } // namespace fileapi
109 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_QUOTA_UTIL_H_