summaryrefslogtreecommitdiffstats
path: root/content/common/quota_dispatcher.h
blob: d283b28c8c2c33d821cfb8a340a0ffc303eacc32 (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
53
54
55
56
57
58
59
60
61
// Copyright (c) 2011 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 CONTENT_COMMON_QUOTA_DISPATCHER_H_
#define CONTENT_COMMON_QUOTA_DISPATCHER_H_

#include <map>
#include <set>

#include "base/basictypes.h"
#include "base/id_map.h"
#include "ipc/ipc_channel.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaError.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaType.h"

class GURL;

namespace IPC {
class Message;
}

namespace WebKit {
class WebStorageQuotaCallbacks;
}

// Dispatches and sends quota related messages sent to/from a child
// process from/to the main browser process.  There is one instance
// per child process.  Messages are dispatched on the main child thread.
class QuotaDispatcher : public IPC::Channel::Listener {
 public:
  QuotaDispatcher();
  ~QuotaDispatcher();

  // IPC::Channel::Listener implementation.
  virtual bool OnMessageReceived(const IPC::Message& msg);

  void QueryStorageUsageAndQuota(const GURL& gurl,
                                 WebKit::WebStorageQuotaType type,
                                 WebKit::WebStorageQuotaCallbacks* callbacks);
  void RequestStorageQuota(const GURL& gurl,
                           WebKit::WebStorageQuotaType type,
                           unsigned long long requested_size,
                           WebKit::WebStorageQuotaCallbacks* callbacks);

 private:
  // Message handlers.
  void DidQueryStorageUsageAndQuota(int request_id,
                                    int64 current_usage,
                                    int64 current_quota);
  void DidGrantStorageQuota(int request_id,
                            int64 granted_quota);
  void DidFail(int request_id,
               WebKit::WebStorageQuotaError error);

  IDMap<WebKit::WebStorageQuotaCallbacks> pending_quota_callbacks_;

  DISALLOW_COPY_AND_ASSIGN(QuotaDispatcher);
};

#endif  // CONTENT_COMMON_QUOTA_DISPATCHER_H_