Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: content/common/quota_dispatcher.cc

Issue 6811022: Add IPC plumbing code for Quota API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "content/common/quota_dispatcher.h"
6
7 #include "content/common/child_thread.h"
8 #include "content/common/quota_messages.h"
9 #include "googleurl/src/gurl.h"
10 #include "ipc/ipc_message.h"
jam 2011/04/12 17:53:52 nit: this isn't needed
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallba cks.h"
12
13 using WebKit::WebStorageQuotaCallbacks;
14 using WebKit::WebStorageQuotaError;
15 using WebKit::WebStorageQuotaType;
16
17 QuotaDispatcher::QuotaDispatcher() {
18 }
19
20 QuotaDispatcher::~QuotaDispatcher() {
21 IDMap<WebStorageQuotaCallbacks>::iterator iter(&pending_quota_callbacks_);
22 while (!iter.IsAtEnd()) {
23 iter.GetCurrentValue()->didFail(WebKit::WebStorageQuotaErrorAbort);
24 iter.Advance();
25 }
26 }
27
28 bool QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) {
29 bool handled = true;
30 IPC_BEGIN_MESSAGE_MAP(QuotaDispatcher, msg)
31 IPC_MESSAGE_HANDLER(QuotaMsg_DidGrantStorageQuota,
32 DidGrantStorageQuota)
33 IPC_MESSAGE_HANDLER(QuotaMsg_DidQueryStorageUsageAndQuota,
34 DidQueryStorageUsageAndQuota);
35 IPC_MESSAGE_HANDLER(QuotaMsg_DidFail, DidFail);
36 IPC_MESSAGE_UNHANDLED(handled = false)
37 IPC_END_MESSAGE_MAP()
38 return handled;
39 }
40
41 void QuotaDispatcher::QueryStorageUsageAndQuota(
42 const GURL& origin_url,
43 WebStorageQuotaType type,
44 WebStorageQuotaCallbacks* callbacks) {
45 DCHECK(callbacks);
46 int request_id = pending_quota_callbacks_.Add(callbacks);
47 ChildThread::current()->Send(new QuotaHostMsg_QueryStorageUsageAndQuota(
48 request_id, origin_url, type));
49 }
50
51 void QuotaDispatcher::RequestStorageQuota(
52 const GURL& origin_url,
53 WebStorageQuotaType type,
54 unsigned long long requested_size,
55 WebStorageQuotaCallbacks* callbacks) {
56 DCHECK(callbacks);
57 int request_id = pending_quota_callbacks_.Add(callbacks);
58 ChildThread::current()->Send(new QuotaHostMsg_RequestStorageQuota(
59 request_id, origin_url, type, requested_size));
60 }
61
62 void QuotaDispatcher::DidGrantStorageQuota(
63 int request_id,
64 int64 granted_quota) {
65 WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup(
66 request_id);
67 DCHECK(callbacks);
68 callbacks->didGrantStorageQuota(granted_quota);
69 pending_quota_callbacks_.Remove(request_id);
70 }
71
72 void QuotaDispatcher::DidQueryStorageUsageAndQuota(
73 int request_id,
74 int64 current_usage,
75 int64 current_quota) {
76 WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup(
77 request_id);
78 DCHECK(callbacks);
79 callbacks->didQueryStorageUsageAndQuota(current_usage, current_quota);
80 pending_quota_callbacks_.Remove(request_id);
81 }
82
83 void QuotaDispatcher::DidFail(
84 int request_id,
85 WebStorageQuotaError error) {
86 WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup(
87 request_id);
88 DCHECK(callbacks);
89 callbacks->didFail(error);
90 pending_quota_callbacks_.Remove(request_id);
91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698