OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 WEBKIT_FILEAPI_SANDBOX_QUOTA_OBSERVER_H_ | 5 #ifndef WEBKIT_FILEAPI_SANDBOX_QUOTA_OBSERVER_H_ |
6 #define WEBKIT_FILEAPI_SANDBOX_QUOTA_OBSERVER_H_ | 6 #define WEBKIT_FILEAPI_SANDBOX_QUOTA_OBSERVER_H_ |
7 | 7 |
| 8 #include <map> |
| 9 |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
10 #include "base/file_path.h" | 12 #include "base/file_path.h" |
11 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" |
13 #include "webkit/fileapi/file_observers.h" | 16 #include "webkit/fileapi/file_observers.h" |
| 17 #include "webkit/fileapi/file_system_url.h" |
14 | 18 |
15 namespace base { | 19 namespace base { |
16 class SequencedTaskRunner; | 20 class SequencedTaskRunner; |
17 } | 21 } |
18 | 22 |
19 namespace quota { | 23 namespace quota { |
20 class QuotaManagerProxy; | 24 class QuotaManagerProxy; |
21 } | 25 } |
22 | 26 |
23 namespace fileapi { | 27 namespace fileapi { |
24 | 28 |
25 class FileSystemURL; | 29 class FileSystemURL; |
26 class ObfuscatedFileUtil; | 30 class ObfuscatedFileUtil; |
27 | 31 |
28 class SandboxQuotaObserver | 32 class SandboxQuotaObserver |
29 : public FileUpdateObserver, | 33 : public FileUpdateObserver, |
30 public FileAccessObserver { | 34 public FileAccessObserver { |
31 public: | 35 public: |
| 36 typedef std::map<FilePath, int64> PendingUpdateNotificationMap; |
| 37 |
32 SandboxQuotaObserver( | 38 SandboxQuotaObserver( |
33 quota::QuotaManagerProxy* quota_manager_proxy, | 39 quota::QuotaManagerProxy* quota_manager_proxy, |
34 base::SequencedTaskRunner* update_notify_runner, | 40 base::SequencedTaskRunner* update_notify_runner, |
35 ObfuscatedFileUtil* sandbox_file_util); | 41 ObfuscatedFileUtil* sandbox_file_util); |
36 virtual ~SandboxQuotaObserver(); | 42 virtual ~SandboxQuotaObserver(); |
37 | 43 |
38 // FileUpdateObserver overrides. | 44 // FileUpdateObserver overrides. |
39 virtual void OnStartUpdate(const FileSystemURL& url) OVERRIDE; | 45 virtual void OnStartUpdate(const FileSystemURL& url) OVERRIDE; |
40 virtual void OnUpdate(const FileSystemURL& url, int64 delta) OVERRIDE; | 46 virtual void OnUpdate(const FileSystemURL& url, int64 delta) OVERRIDE; |
41 virtual void OnEndUpdate(const FileSystemURL& url) OVERRIDE; | 47 virtual void OnEndUpdate(const FileSystemURL& url) OVERRIDE; |
42 | 48 |
43 // FileAccessObserver overrides. | 49 // FileAccessObserver overrides. |
44 virtual void OnAccess(const FileSystemURL& url) OVERRIDE; | 50 virtual void OnAccess(const FileSystemURL& url) OVERRIDE; |
45 | 51 |
46 private: | 52 private: |
| 53 void ApplyPendingUsageUpdate(); |
| 54 void UpdateUsageCacheFile(const FilePath& usage_file_path, int64 delta); |
| 55 |
47 FilePath GetUsageCachePath(const FileSystemURL& url); | 56 FilePath GetUsageCachePath(const FileSystemURL& url); |
48 | 57 |
49 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; | 58 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; |
50 scoped_refptr<base::SequencedTaskRunner> update_notify_runner_; | 59 scoped_refptr<base::SequencedTaskRunner> update_notify_runner_; |
51 | 60 |
52 // Not owned; sandbox_file_util_ should have identical lifetime with this. | 61 // Not owned; sandbox_file_util_ should have identical lifetime with this. |
53 ObfuscatedFileUtil* sandbox_file_util_; | 62 ObfuscatedFileUtil* sandbox_file_util_; |
54 | 63 |
| 64 PendingUpdateNotificationMap pending_update_notification_; |
| 65 bool running_delayed_cache_update_; |
| 66 |
| 67 base::WeakPtrFactory<SandboxQuotaObserver> weak_factory_; |
| 68 |
55 DISALLOW_COPY_AND_ASSIGN(SandboxQuotaObserver); | 69 DISALLOW_COPY_AND_ASSIGN(SandboxQuotaObserver); |
56 }; | 70 }; |
57 | 71 |
58 } // namespace fileapi | 72 } // namespace fileapi |
59 | 73 |
60 #endif // WEBKIT_FILEAPI_SANDBOX_QUOTA_OBSERVER_H_ | 74 #endif // WEBKIT_FILEAPI_SANDBOX_QUOTA_OBSERVER_H_ |
OLD | NEW |