Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/quota/Client.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_dom_quota_client_h__
8
#define mozilla_dom_quota_client_h__
9
10
#include "mozilla/dom/quota/QuotaCommon.h"
11
12
#include "mozilla/dom/ipc/IdType.h"
13
14
#include "PersistenceType.h"
15
16
class nsIFile;
17
class nsIRunnable;
18
19
0
#define IDB_DIRECTORY_NAME "idb"
20
0
#define ASMJSCACHE_DIRECTORY_NAME "asmjs"
21
0
#define DOMCACHE_DIRECTORY_NAME "cache"
22
0
#define SDB_DIRECTORY_NAME "sdb"
23
#define LS_DIRECTORY_NAME "ls"
24
25
BEGIN_QUOTA_NAMESPACE
26
27
class QuotaManager;
28
class UsageInfo;
29
30
// An abstract interface for quota manager clients.
31
// Each storage API must provide an implementation of this interface in order
32
// to participate in centralized quota and storage handling.
33
class Client
34
{
35
public:
36
  typedef mozilla::Atomic<bool> AtomicBool;
37
38
  NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
39
40
  enum Type {
41
    IDB = 0,
42
    //LS,
43
    //APPCACHE,
44
    ASMJS,
45
    DOMCACHE,
46
    SDB,
47
    TYPE_MAX
48
  };
49
50
  virtual Type
51
  GetType() = 0;
52
53
  static nsresult
54
  TypeToText(Type aType, nsAString& aText)
55
0
  {
56
0
    switch (aType) {
57
0
      case IDB:
58
0
        aText.AssignLiteral(IDB_DIRECTORY_NAME);
59
0
        break;
60
0
61
0
      case ASMJS:
62
0
        aText.AssignLiteral(ASMJSCACHE_DIRECTORY_NAME);
63
0
        break;
64
0
65
0
      case DOMCACHE:
66
0
        aText.AssignLiteral(DOMCACHE_DIRECTORY_NAME);
67
0
        break;
68
0
69
0
      case SDB:
70
0
        aText.AssignLiteral(SDB_DIRECTORY_NAME);
71
0
        break;
72
0
73
0
      case TYPE_MAX:
74
0
      default:
75
0
        MOZ_ASSERT_UNREACHABLE("Bad id value!");
76
0
        return NS_ERROR_UNEXPECTED;
77
0
    }
78
0
79
0
    return NS_OK;
80
0
  }
81
82
  static nsresult
83
  TypeFromText(const nsAString& aText, Type& aType)
84
0
  {
85
0
    if (aText.EqualsLiteral(IDB_DIRECTORY_NAME)) {
86
0
      aType = IDB;
87
0
    }
88
0
    else if (aText.EqualsLiteral(ASMJSCACHE_DIRECTORY_NAME)) {
89
0
      aType = ASMJS;
90
0
    }
91
0
    else if (aText.EqualsLiteral(DOMCACHE_DIRECTORY_NAME)) {
92
0
      aType = DOMCACHE;
93
0
    }
94
0
    else if (aText.EqualsLiteral(SDB_DIRECTORY_NAME)) {
95
0
      aType = SDB;
96
0
    }
97
0
    else {
98
0
      return NS_ERROR_FAILURE;
99
0
    }
100
0
101
0
    return NS_OK;
102
0
  }
103
104
  // Methods which are called on the IO thread.
105
  virtual nsresult
106
  UpgradeStorageFrom1_0To2_0(nsIFile* aDirectory)
107
  {
108
    return NS_OK;
109
  }
110
111
  virtual nsresult
112
  UpgradeStorageFrom2_0To2_1(nsIFile* aDirectory)
113
  {
114
    return NS_OK;
115
  }
116
117
  virtual nsresult
118
  InitOrigin(PersistenceType aPersistenceType,
119
             const nsACString& aGroup,
120
             const nsACString& aOrigin,
121
             const AtomicBool& aCanceled,
122
             UsageInfo* aUsageInfo) = 0;
123
124
  virtual nsresult
125
  GetUsageForOrigin(PersistenceType aPersistenceType,
126
                    const nsACString& aGroup,
127
                    const nsACString& aOrigin,
128
                    const AtomicBool& aCanceled,
129
                    UsageInfo* aUsageInfo) = 0;
130
131
  virtual void
132
  OnOriginClearCompleted(PersistenceType aPersistenceType,
133
                         const nsACString& aOrigin) = 0;
134
135
  virtual void
136
  ReleaseIOThreadObjects() = 0;
137
138
  // Methods which are called on the background thread.
139
  virtual void
140
  AbortOperations(const nsACString& aOrigin) = 0;
141
142
  virtual void
143
  AbortOperationsForProcess(ContentParentId aContentParentId) = 0;
144
145
  virtual void
146
  StartIdleMaintenance() = 0;
147
148
  virtual void
149
  StopIdleMaintenance() = 0;
150
151
  virtual void
152
  ShutdownWorkThreads() = 0;
153
154
  // Methods which are called on the main thread.
155
  virtual void
156
  DidInitialize(QuotaManager* aQuotaManager)
157
  { }
158
159
  virtual void
160
  WillShutdown()
161
  { }
162
163
protected:
164
  virtual ~Client()
165
  { }
166
};
167
168
END_QUOTA_NAMESPACE
169
170
#endif // mozilla_dom_quota_client_h__