summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi/file_system_quota_manager.h
blob: f1c94e14f6b079997bd5d4523c8b4bfb0af10c07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef WEBKIT_FILEAPI_FILE_SYSTEM_QUOTA_MANAGER_H_
#define WEBKIT_FILEAPI_FILE_SYSTEM_QUOTA_MANAGER_H_

#include <set>

#include "base/basictypes.h"
#include "googleurl/src/gurl.h"

namespace fileapi {

// A quota manager for FileSystem. For now it has little implementation
// and just allows unlimited quota for apps.
class FileSystemQuotaManager {
 public:
  static const int64 kUnknownSize;

  // If |allow_file_access_from_files| is true, unlimited access is granted
  // for file:/// URLs.
  // If |unlimited_quota| is true, unlimited access is granted for every
  // origin.  This flag must be used only for testing.
  FileSystemQuotaManager(bool allow_file_access_from_files,
                         bool unlimited_quota);
  ~FileSystemQuotaManager();

  // Checks if the origin can grow its usage by |growth| bytes.
  // This only performs in-memory check and returns immediately.
  // For now it just returns false for any origins (regardless of the size)
  // that are not in the in-memory unlimited_quota_origins map.
  bool CheckOriginQuota(const GURL& origin, int64 growth);

  // Maintains origins in memory that are allowed to have unlimited quota.
  void SetOriginQuotaUnlimited(const GURL& origin);
  void ResetOriginQuotaUnlimited(const GURL& origin);
  bool CheckIfOriginGrantedUnlimitedQuota(const GURL& origin);

 private:
  // For some extensions/apps we allow unlimited quota.
  std::set<GURL> unlimited_quota_origins_;

  const bool allow_file_access_from_files_;
  const bool unlimited_quota_;

  DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaManager);
};

}  // namespace fileapi

#endif  // WEBKIT_FILEAPI_FILE_SYSTEM_QUOTA_MANAGER_H_