1 // Copyright (c) 2011 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 CONTENT_CHILD_QUOTA_DISPATCHER_H_
6 #define CONTENT_CHILD_QUOTA_DISPATCHER_H_
11 #include "base/basictypes.h"
12 #include "base/id_map.h"
13 #include "base/memory/ref_counted.h"
14 #include "content/child/worker_task_runner.h"
15 #include "storage/common/quota/quota_types.h"
24 class WebStorageQuotaCallbacks
;
29 class ThreadSafeSender
;
30 class QuotaMessageFilter
;
32 // Dispatches and sends quota related messages sent to/from a child
33 // process from/to the main browser process. There is one instance
34 // per each thread. Thread-specific instance can be obtained by
35 // ThreadSpecificInstance().
36 class QuotaDispatcher
: public WorkerTaskRunner::Observer
{
40 virtual ~Callback() {}
41 virtual void DidQueryStorageUsageAndQuota(int64 usage
, int64 quota
) = 0;
42 virtual void DidGrantStorageQuota(int64 usage
, int64 granted_quota
) = 0;
43 virtual void DidFail(storage::QuotaStatusCode status
) = 0;
46 QuotaDispatcher(ThreadSafeSender
* thread_safe_sender
,
47 QuotaMessageFilter
* quota_message_filter
);
48 ~QuotaDispatcher() override
;
50 // |thread_safe_sender| and |quota_message_filter| are used if
51 // calling this leads to construction.
52 static QuotaDispatcher
* ThreadSpecificInstance(
53 ThreadSafeSender
* thread_safe_sender
,
54 QuotaMessageFilter
* quota_message_filter
);
56 // WorkerTaskRunner::Observer implementation.
57 void OnWorkerRunLoopStopped() override
;
59 void OnMessageReceived(const IPC::Message
& msg
);
61 void QueryStorageUsageAndQuota(const GURL
& gurl
,
62 storage::StorageType type
,
64 void RequestStorageQuota(int render_view_id
,
66 storage::StorageType type
,
67 uint64 requested_size
,
70 // Creates a new Callback instance for WebStorageQuotaCallbacks.
71 static Callback
* CreateWebStorageQuotaCallbacksWrapper(
72 blink::WebStorageQuotaCallbacks callbacks
);
76 void DidQueryStorageUsageAndQuota(int request_id
,
79 void DidGrantStorageQuota(int request_id
,
82 void DidFail(int request_id
, storage::QuotaStatusCode error
);
84 IDMap
<Callback
, IDMapOwnPointer
> pending_quota_callbacks_
;
86 scoped_refptr
<ThreadSafeSender
> thread_safe_sender_
;
87 scoped_refptr
<QuotaMessageFilter
> quota_message_filter_
;
89 DISALLOW_COPY_AND_ASSIGN(QuotaDispatcher
);
92 } // namespace content
94 #endif // CONTENT_CHILD_QUOTA_DISPATCHER_H_