blob: 801e63e4a4df83ca25b415f57b1d20319be2d080 [file] [log] [blame]
[email protected]caf66702012-09-07 07:02:201// 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]8eee1b62013-01-08 02:26:448#include <map>
9
[email protected]caf66702012-09-07 07:02:2010#include "base/basictypes.h"
11#include "base/compiler_specific.h"
[email protected]57999812013-02-24 05:40:5212#include "base/files/file_path.h"
[email protected]caf66702012-09-07 07:02:2013#include "base/memory/ref_counted.h"
14#include "base/memory/scoped_ptr.h"
[email protected]8eee1b62013-01-08 02:26:4415#include "base/memory/weak_ptr.h"
[email protected]caf66702012-09-07 07:02:2016#include "webkit/fileapi/file_observers.h"
[email protected]8eee1b62013-01-08 02:26:4417#include "webkit/fileapi/file_system_url.h"
[email protected]caf66702012-09-07 07:02:2018
19namespace base {
20class SequencedTaskRunner;
21}
22
23namespace quota {
24class QuotaManagerProxy;
25}
26
27namespace fileapi {
28
[email protected]06226172013-03-14 15:39:3129class FileSystemUsageCache;
[email protected]caf66702012-09-07 07:02:2030class FileSystemURL;
[email protected]df3c8bb2012-11-06 07:02:5031class ObfuscatedFileUtil;
[email protected]caf66702012-09-07 07:02:2032
33class SandboxQuotaObserver
34 : public FileUpdateObserver,
35 public FileAccessObserver {
36 public:
[email protected]a3ef4832013-02-02 05:12:3337 typedef std::map<base::FilePath, int64> PendingUpdateNotificationMap;
[email protected]8eee1b62013-01-08 02:26:4438
[email protected]caf66702012-09-07 07:02:2039 SandboxQuotaObserver(
40 quota::QuotaManagerProxy* quota_manager_proxy,
41 base::SequencedTaskRunner* update_notify_runner,
[email protected]06226172013-03-14 15:39:3142 ObfuscatedFileUtil* sandbox_file_util,
43 FileSystemUsageCache* file_system_usage_cache_);
[email protected]caf66702012-09-07 07:02:2044 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]bd4219cf2013-04-26 14:33:4654 void SetUsageCacheEnabled(const GURL& origin,
55 FileSystemType type,
56 bool enabled);
57
[email protected]caf66702012-09-07 07:02:2058 private:
[email protected]8eee1b62013-01-08 02:26:4459 void ApplyPendingUsageUpdate();
[email protected]a3ef4832013-02-02 05:12:3360 void UpdateUsageCacheFile(const base::FilePath& usage_file_path, int64 delta);
[email protected]8eee1b62013-01-08 02:26:4461
[email protected]a3ef4832013-02-02 05:12:3362 base::FilePath GetUsageCachePath(const FileSystemURL& url);
[email protected]caf66702012-09-07 07:02:2063
64 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_;
65 scoped_refptr<base::SequencedTaskRunner> update_notify_runner_;
66
[email protected]df3c8bb2012-11-06 07:02:5067 // Not owned; sandbox_file_util_ should have identical lifetime with this.
68 ObfuscatedFileUtil* sandbox_file_util_;
[email protected]caf66702012-09-07 07:02:2069
[email protected]06226172013-03-14 15:39:3170 // Not owned; file_system_usage_cache_ should have longer lifetime than this.
71 FileSystemUsageCache* file_system_usage_cache_;
72
[email protected]8eee1b62013-01-08 02:26:4473 PendingUpdateNotificationMap pending_update_notification_;
74 bool running_delayed_cache_update_;
75
76 base::WeakPtrFactory<SandboxQuotaObserver> weak_factory_;
77
[email protected]caf66702012-09-07 07:02:2078 DISALLOW_COPY_AND_ASSIGN(SandboxQuotaObserver);
79};
80
81} // namespace fileapi
82
83#endif // WEBKIT_FILEAPI_SANDBOX_QUOTA_OBSERVER_H_