[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 1 | // Copyright (c) 2012 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 WEBKIT_FILEAPI_SANDBOX_QUOTA_OBSERVER_H_ | ||||
6 | #define WEBKIT_FILEAPI_SANDBOX_QUOTA_OBSERVER_H_ | ||||
7 | |||||
[email protected] | 8eee1b6 | 2013-01-08 02:26:44 | [diff] [blame] | 8 | #include <map> |
9 | |||||
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 10 | #include "base/basictypes.h" |
11 | #include "base/compiler_specific.h" | ||||
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 12 | #include "base/files/file_path.h" |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 13 | #include "base/memory/ref_counted.h" |
14 | #include "base/memory/scoped_ptr.h" | ||||
[email protected] | 8eee1b6 | 2013-01-08 02:26:44 | [diff] [blame] | 15 | #include "base/memory/weak_ptr.h" |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 16 | #include "webkit/fileapi/file_observers.h" |
[email protected] | 8eee1b6 | 2013-01-08 02:26:44 | [diff] [blame] | 17 | #include "webkit/fileapi/file_system_url.h" |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 18 | |
19 | namespace base { | ||||
20 | class SequencedTaskRunner; | ||||
21 | } | ||||
22 | |||||
23 | namespace quota { | ||||
24 | class QuotaManagerProxy; | ||||
25 | } | ||||
26 | |||||
27 | namespace fileapi { | ||||
28 | |||||
[email protected] | 0622617 | 2013-03-14 15:39:31 | [diff] [blame] | 29 | class FileSystemUsageCache; |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 30 | class FileSystemURL; |
[email protected] | df3c8bb | 2012-11-06 07:02:50 | [diff] [blame] | 31 | class ObfuscatedFileUtil; |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 32 | |
33 | class SandboxQuotaObserver | ||||
34 | : public FileUpdateObserver, | ||||
35 | public FileAccessObserver { | ||||
36 | public: | ||||
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 37 | typedef std::map<base::FilePath, int64> PendingUpdateNotificationMap; |
[email protected] | 8eee1b6 | 2013-01-08 02:26:44 | [diff] [blame] | 38 | |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 39 | SandboxQuotaObserver( |
40 | quota::QuotaManagerProxy* quota_manager_proxy, | ||||
41 | base::SequencedTaskRunner* update_notify_runner, | ||||
[email protected] | 0622617 | 2013-03-14 15:39:31 | [diff] [blame] | 42 | ObfuscatedFileUtil* sandbox_file_util, |
43 | FileSystemUsageCache* file_system_usage_cache_); | ||||
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 44 | virtual ~SandboxQuotaObserver(); |
45 | |||||
46 | // FileUpdateObserver overrides. | ||||
47 | virtual void OnStartUpdate(const FileSystemURL& url) OVERRIDE; | ||||
48 | virtual void OnUpdate(const FileSystemURL& url, int64 delta) OVERRIDE; | ||||
49 | virtual void OnEndUpdate(const FileSystemURL& url) OVERRIDE; | ||||
50 | |||||
51 | // FileAccessObserver overrides. | ||||
52 | virtual void OnAccess(const FileSystemURL& url) OVERRIDE; | ||||
53 | |||||
[email protected] | bd4219cf | 2013-04-26 14:33:46 | [diff] [blame] | 54 | void SetUsageCacheEnabled(const GURL& origin, |
55 | FileSystemType type, | ||||
56 | bool enabled); | ||||
57 | |||||
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 58 | private: |
[email protected] | 8eee1b6 | 2013-01-08 02:26:44 | [diff] [blame] | 59 | void ApplyPendingUsageUpdate(); |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 60 | void UpdateUsageCacheFile(const base::FilePath& usage_file_path, int64 delta); |
[email protected] | 8eee1b6 | 2013-01-08 02:26:44 | [diff] [blame] | 61 | |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 62 | base::FilePath GetUsageCachePath(const FileSystemURL& url); |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 63 | |
64 | scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; | ||||
65 | scoped_refptr<base::SequencedTaskRunner> update_notify_runner_; | ||||
66 | |||||
[email protected] | df3c8bb | 2012-11-06 07:02:50 | [diff] [blame] | 67 | // Not owned; sandbox_file_util_ should have identical lifetime with this. |
68 | ObfuscatedFileUtil* sandbox_file_util_; | ||||
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 69 | |
[email protected] | 0622617 | 2013-03-14 15:39:31 | [diff] [blame] | 70 | // Not owned; file_system_usage_cache_ should have longer lifetime than this. |
71 | FileSystemUsageCache* file_system_usage_cache_; | ||||
72 | |||||
[email protected] | 8eee1b6 | 2013-01-08 02:26:44 | [diff] [blame] | 73 | PendingUpdateNotificationMap pending_update_notification_; |
74 | bool running_delayed_cache_update_; | ||||
75 | |||||
76 | base::WeakPtrFactory<SandboxQuotaObserver> weak_factory_; | ||||
77 | |||||
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 78 | DISALLOW_COPY_AND_ASSIGN(SandboxQuotaObserver); |
79 | }; | ||||
80 | |||||
81 | } // namespace fileapi | ||||
82 | |||||
83 | #endif // WEBKIT_FILEAPI_SANDBOX_QUOTA_OBSERVER_H_ |