When enabling new profile management programmatically, make sure to set the
[chromium-blink-merge.git] / webkit / browser / fileapi / sandbox_quota_observer.h
blob2c16860149c943aaf3ac46b2f414fefb2fe7adff
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.
5 #ifndef WEBKIT_BROWSER_FILEAPI_SANDBOX_QUOTA_OBSERVER_H_
6 #define WEBKIT_BROWSER_FILEAPI_SANDBOX_QUOTA_OBSERVER_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/files/file_path.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "webkit/browser/fileapi/file_observers.h"
17 #include "webkit/browser/fileapi/file_system_url.h"
19 namespace base {
20 class SequencedTaskRunner;
23 namespace quota {
24 class QuotaManagerProxy;
27 namespace fileapi {
29 class FileSystemUsageCache;
30 class FileSystemURL;
31 class TimedTaskHelper;
32 class ObfuscatedFileUtil;
34 class SandboxQuotaObserver
35 : public FileUpdateObserver,
36 public FileAccessObserver {
37 public:
38 typedef std::map<base::FilePath, int64> PendingUpdateNotificationMap;
40 SandboxQuotaObserver(
41 quota::QuotaManagerProxy* quota_manager_proxy,
42 base::SequencedTaskRunner* update_notify_runner,
43 ObfuscatedFileUtil* sandbox_file_util,
44 FileSystemUsageCache* file_system_usage_cache_);
45 virtual ~SandboxQuotaObserver();
47 // FileUpdateObserver overrides.
48 virtual void OnStartUpdate(const FileSystemURL& url) OVERRIDE;
49 virtual void OnUpdate(const FileSystemURL& url, int64 delta) OVERRIDE;
50 virtual void OnEndUpdate(const FileSystemURL& url) OVERRIDE;
52 // FileAccessObserver overrides.
53 virtual void OnAccess(const FileSystemURL& url) OVERRIDE;
55 void SetUsageCacheEnabled(const GURL& origin,
56 FileSystemType type,
57 bool enabled);
59 private:
60 void ApplyPendingUsageUpdate();
61 void UpdateUsageCacheFile(const base::FilePath& usage_file_path, int64 delta);
63 base::FilePath GetUsageCachePath(const FileSystemURL& url);
65 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_;
66 scoped_refptr<base::SequencedTaskRunner> update_notify_runner_;
68 // Not owned; sandbox_file_util_ should have identical lifetime with this.
69 ObfuscatedFileUtil* sandbox_file_util_;
71 // Not owned; file_system_usage_cache_ should have longer lifetime than this.
72 FileSystemUsageCache* file_system_usage_cache_;
74 PendingUpdateNotificationMap pending_update_notification_;
75 scoped_ptr<TimedTaskHelper> delayed_cache_update_helper_;
77 DISALLOW_COPY_AND_ASSIGN(SandboxQuotaObserver);
80 } // namespace fileapi
82 #endif // WEBKIT_BROWSER_FILEAPI_SANDBOX_QUOTA_OBSERVER_H_