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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
// 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.
#include "content/common/quota_dispatcher.h"
#include "base/basictypes.h"
#include "content/common/child_thread.h"
#include "content/common/quota_messages.h"
#include "googleurl/src/gurl.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaType.h"
using quota::QuotaStatusCode;
using quota::StorageType;
using WebKit::WebStorageQuotaCallbacks;
using WebKit::WebStorageQuotaError;
using WebKit::WebStorageQuotaType;
namespace {
// QuotaDispatcher::Callback implementation for WebStorageQuotaCallbacks.
class WebStorageQuotaDispatcherCallback : public QuotaDispatcher::Callback {
public:
WebStorageQuotaDispatcherCallback(WebKit::WebStorageQuotaCallbacks* callback)
: callbacks_(callback) {
DCHECK(callbacks_);
}
virtual ~WebStorageQuotaDispatcherCallback() {}
virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) OVERRIDE {
callbacks_->didQueryStorageUsageAndQuota(usage, quota);
}
virtual void DidGrantStorageQuota(int64 granted_quota) OVERRIDE {
callbacks_->didGrantStorageQuota(granted_quota);
}
virtual void DidFail(quota::QuotaStatusCode error) OVERRIDE {
callbacks_->didFail(static_cast<WebStorageQuotaError>(error));
}
private:
// Not owned (self-destructed).
WebKit::WebStorageQuotaCallbacks* callbacks_;
};
} // namespace
QuotaDispatcher::QuotaDispatcher() {
}
QuotaDispatcher::~QuotaDispatcher() {
IDMap<Callback, IDMapOwnPointer>::iterator iter(&pending_quota_callbacks_);
while (!iter.IsAtEnd()) {
iter.GetCurrentValue()->DidFail(quota::kQuotaErrorAbort);
iter.Advance();
}
}
bool QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(QuotaDispatcher, msg)
IPC_MESSAGE_HANDLER(QuotaMsg_DidGrantStorageQuota,
DidGrantStorageQuota)
IPC_MESSAGE_HANDLER(QuotaMsg_DidQueryStorageUsageAndQuota,
DidQueryStorageUsageAndQuota);
IPC_MESSAGE_HANDLER(QuotaMsg_DidFail, DidFail);
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void QuotaDispatcher::QueryStorageUsageAndQuota(
const GURL& origin_url,
StorageType type,
Callback* callback) {
DCHECK(callback);
int request_id = pending_quota_callbacks_.Add(callback);
ChildThread::current()->Send(new QuotaHostMsg_QueryStorageUsageAndQuota(
request_id, origin_url, type));
}
void QuotaDispatcher::RequestStorageQuota(
int render_view_id,
const GURL& origin_url,
StorageType type,
int64 requested_size,
Callback* callback) {
DCHECK(callback);
int request_id = pending_quota_callbacks_.Add(callback);
ChildThread::current()->Send(new QuotaHostMsg_RequestStorageQuota(
render_view_id, request_id, origin_url, type, requested_size));
}
// static
QuotaDispatcher::Callback*
QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(
WebKit::WebStorageQuotaCallbacks* callbacks) {
return new WebStorageQuotaDispatcherCallback(callbacks);
}
void QuotaDispatcher::DidGrantStorageQuota(
int request_id,
int64 granted_quota) {
Callback* callback = pending_quota_callbacks_.Lookup(request_id);
DCHECK(callback);
callback->DidGrantStorageQuota(granted_quota);
pending_quota_callbacks_.Remove(request_id);
}
void QuotaDispatcher::DidQueryStorageUsageAndQuota(
int request_id,
int64 current_usage,
int64 current_quota) {
Callback* callback = pending_quota_callbacks_.Lookup(request_id);
DCHECK(callback);
callback->DidQueryStorageUsageAndQuota(current_usage, current_quota);
pending_quota_callbacks_.Remove(request_id);
}
void QuotaDispatcher::DidFail(
int request_id,
QuotaStatusCode error) {
Callback* callback = pending_quota_callbacks_.Lookup(request_id);
DCHECK(callback);
callback->DidFail(error);
pending_quota_callbacks_.Remove(request_id);
}
COMPILE_ASSERT(int(WebKit::WebStorageQuotaTypeTemporary) == \
int(quota::kStorageTypeTemporary), mismatching_enums);
COMPILE_ASSERT(int(WebKit::WebStorageQuotaTypePersistent) == \
int(quota::kStorageTypePersistent), mismatching_enums);
COMPILE_ASSERT(int(WebKit::WebStorageQuotaErrorNotSupported) == \
int(quota::kQuotaErrorNotSupported), mismatching_enums);
COMPILE_ASSERT(int(WebKit::WebStorageQuotaErrorAbort) == \
int(quota::kQuotaErrorAbort), mismatching_enums);
|