Don't preload rarely seen large images
[chromium-blink-merge.git] / storage / browser / fileapi / sandbox_quota_observer.h
blob64c153a8e440dc35b169a8a1fbd484aaaf259102
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 STORAGE_BROWSER_FILEAPI_SANDBOX_QUOTA_OBSERVER_H_
6 #define STORAGE_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 "storage/browser/fileapi/file_observers.h"
17 #include "storage/browser/fileapi/file_system_url.h"
19 namespace base {
20 class SequencedTaskRunner;
23 namespace storage {
24 class QuotaManagerProxy;
27 namespace storage {
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(storage::QuotaManagerProxy* quota_manager_proxy,
41 base::SequencedTaskRunner* update_notify_runner,
42 ObfuscatedFileUtil* sandbox_file_util,
43 FileSystemUsageCache* file_system_usage_cache_);
44 ~SandboxQuotaObserver() override;
46 // FileUpdateObserver overrides.
47 void OnStartUpdate(const FileSystemURL& url) override;
48 void OnUpdate(const FileSystemURL& url, int64 delta) override;
49 void OnEndUpdate(const FileSystemURL& url) override;
51 // FileAccessObserver overrides.
52 void OnAccess(const FileSystemURL& url) override;
54 void SetUsageCacheEnabled(const GURL& origin,
55 FileSystemType type,
56 bool enabled);
58 private:
59 void ApplyPendingUsageUpdate();
60 void UpdateUsageCacheFile(const base::FilePath& usage_file_path, int64 delta);
62 base::FilePath GetUsageCachePath(const FileSystemURL& url);
64 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_;
65 scoped_refptr<base::SequencedTaskRunner> update_notify_runner_;
67 // Not owned; sandbox_file_util_ should have identical lifetime with this.
68 ObfuscatedFileUtil* sandbox_file_util_;
70 // Not owned; file_system_usage_cache_ should have longer lifetime than this.
71 FileSystemUsageCache* file_system_usage_cache_;
73 PendingUpdateNotificationMap pending_update_notification_;
74 scoped_ptr<TimedTaskHelper> delayed_cache_update_helper_;
76 DISALLOW_COPY_AND_ASSIGN(SandboxQuotaObserver);
79 } // namespace storage
81 #endif // STORAGE_BROWSER_FILEAPI_SANDBOX_QUOTA_OBSERVER_H_