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

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

Issue 7438001: Cleanup: Make quota dispatcher code independent from WebKit types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clang fix Created 9 years, 4 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
« no previous file with comments | « content/common/quota_dispatcher.h ('k') | content/common/quota_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/quota_dispatcher.h" 5 #include "content/common/quota_dispatcher.h"
6 6
7 #include "base/basictypes.h"
7 #include "content/common/child_thread.h" 8 #include "content/common/child_thread.h"
8 #include "content/common/quota_messages.h" 9 #include "content/common/quota_messages.h"
9 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallba cks.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallba cks.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaType.h "
13
14 using quota::QuotaStatusCode;
15 using quota::StorageType;
11 16
12 using WebKit::WebStorageQuotaCallbacks; 17 using WebKit::WebStorageQuotaCallbacks;
13 using WebKit::WebStorageQuotaError; 18 using WebKit::WebStorageQuotaError;
14 using WebKit::WebStorageQuotaType; 19 using WebKit::WebStorageQuotaType;
15 20
21 namespace {
22
23 // QuotaDispatcher::Callback implementation for WebStorageQuotaCallbacks.
24 class WebStorageQuotaDispatcherCallback : public QuotaDispatcher::Callback {
25 public:
26 WebStorageQuotaDispatcherCallback(WebKit::WebStorageQuotaCallbacks* callback)
27 : callbacks_(callback) {
28 DCHECK(callbacks_);
29 }
30 virtual ~WebStorageQuotaDispatcherCallback() {}
31 virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) OVERRIDE {
32 callbacks_->didQueryStorageUsageAndQuota(usage, quota);
33 }
34 virtual void DidGrantStorageQuota(int64 granted_quota) OVERRIDE {
35 callbacks_->didGrantStorageQuota(granted_quota);
36 }
37 virtual void DidFail(quota::QuotaStatusCode error) OVERRIDE {
38 callbacks_->didFail(static_cast<WebStorageQuotaError>(error));
39 }
40
41 private:
42 // Not owned (self-destructed).
43 WebKit::WebStorageQuotaCallbacks* callbacks_;
44 };
45
46 } // namespace
47
16 QuotaDispatcher::QuotaDispatcher() { 48 QuotaDispatcher::QuotaDispatcher() {
17 } 49 }
18 50
19 QuotaDispatcher::~QuotaDispatcher() { 51 QuotaDispatcher::~QuotaDispatcher() {
20 IDMap<WebStorageQuotaCallbacks>::iterator iter(&pending_quota_callbacks_); 52 IDMap<Callback, IDMapOwnPointer>::iterator iter(&pending_quota_callbacks_);
21 while (!iter.IsAtEnd()) { 53 while (!iter.IsAtEnd()) {
22 iter.GetCurrentValue()->didFail(WebKit::WebStorageQuotaErrorAbort); 54 iter.GetCurrentValue()->DidFail(quota::kQuotaErrorAbort);
23 iter.Advance(); 55 iter.Advance();
24 } 56 }
25 } 57 }
26 58
27 bool QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) { 59 bool QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) {
28 bool handled = true; 60 bool handled = true;
29 IPC_BEGIN_MESSAGE_MAP(QuotaDispatcher, msg) 61 IPC_BEGIN_MESSAGE_MAP(QuotaDispatcher, msg)
30 IPC_MESSAGE_HANDLER(QuotaMsg_DidGrantStorageQuota, 62 IPC_MESSAGE_HANDLER(QuotaMsg_DidGrantStorageQuota,
31 DidGrantStorageQuota) 63 DidGrantStorageQuota)
32 IPC_MESSAGE_HANDLER(QuotaMsg_DidQueryStorageUsageAndQuota, 64 IPC_MESSAGE_HANDLER(QuotaMsg_DidQueryStorageUsageAndQuota,
33 DidQueryStorageUsageAndQuota); 65 DidQueryStorageUsageAndQuota);
34 IPC_MESSAGE_HANDLER(QuotaMsg_DidFail, DidFail); 66 IPC_MESSAGE_HANDLER(QuotaMsg_DidFail, DidFail);
35 IPC_MESSAGE_UNHANDLED(handled = false) 67 IPC_MESSAGE_UNHANDLED(handled = false)
36 IPC_END_MESSAGE_MAP() 68 IPC_END_MESSAGE_MAP()
37 return handled; 69 return handled;
38 } 70 }
39 71
40 void QuotaDispatcher::QueryStorageUsageAndQuota( 72 void QuotaDispatcher::QueryStorageUsageAndQuota(
41 const GURL& origin_url, 73 const GURL& origin_url,
42 WebStorageQuotaType type, 74 StorageType type,
43 WebStorageQuotaCallbacks* callbacks) { 75 Callback* callback) {
44 DCHECK(callbacks); 76 DCHECK(callback);
45 int request_id = pending_quota_callbacks_.Add(callbacks); 77 int request_id = pending_quota_callbacks_.Add(callback);
46 ChildThread::current()->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( 78 ChildThread::current()->Send(new QuotaHostMsg_QueryStorageUsageAndQuota(
47 request_id, origin_url, type)); 79 request_id, origin_url, type));
48 } 80 }
49 81
50 void QuotaDispatcher::RequestStorageQuota( 82 void QuotaDispatcher::RequestStorageQuota(
51 int render_view_id, 83 int render_view_id,
52 const GURL& origin_url, 84 const GURL& origin_url,
53 WebStorageQuotaType type, 85 StorageType type,
54 unsigned long long requested_size, 86 int64 requested_size,
55 WebStorageQuotaCallbacks* callbacks) { 87 Callback* callback) {
56 DCHECK(callbacks); 88 DCHECK(callback);
57 int request_id = pending_quota_callbacks_.Add(callbacks); 89 int request_id = pending_quota_callbacks_.Add(callback);
58 ChildThread::current()->Send(new QuotaHostMsg_RequestStorageQuota( 90 ChildThread::current()->Send(new QuotaHostMsg_RequestStorageQuota(
59 render_view_id, request_id, origin_url, type, requested_size)); 91 render_view_id, request_id, origin_url, type, requested_size));
60 } 92 }
61 93
94 // static
95 QuotaDispatcher::Callback*
96 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(
97 WebKit::WebStorageQuotaCallbacks* callbacks) {
98 return new WebStorageQuotaDispatcherCallback(callbacks);
99 }
100
62 void QuotaDispatcher::DidGrantStorageQuota( 101 void QuotaDispatcher::DidGrantStorageQuota(
63 int request_id, 102 int request_id,
64 int64 granted_quota) { 103 int64 granted_quota) {
65 WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup( 104 Callback* callback = pending_quota_callbacks_.Lookup(request_id);
66 request_id); 105 DCHECK(callback);
67 DCHECK(callbacks); 106 callback->DidGrantStorageQuota(granted_quota);
68 callbacks->didGrantStorageQuota(granted_quota);
69 pending_quota_callbacks_.Remove(request_id); 107 pending_quota_callbacks_.Remove(request_id);
70 } 108 }
71 109
72 void QuotaDispatcher::DidQueryStorageUsageAndQuota( 110 void QuotaDispatcher::DidQueryStorageUsageAndQuota(
73 int request_id, 111 int request_id,
74 int64 current_usage, 112 int64 current_usage,
75 int64 current_quota) { 113 int64 current_quota) {
76 WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup( 114 Callback* callback = pending_quota_callbacks_.Lookup(request_id);
77 request_id); 115 DCHECK(callback);
78 DCHECK(callbacks); 116 callback->DidQueryStorageUsageAndQuota(current_usage, current_quota);
79 callbacks->didQueryStorageUsageAndQuota(current_usage, current_quota);
80 pending_quota_callbacks_.Remove(request_id); 117 pending_quota_callbacks_.Remove(request_id);
81 } 118 }
82 119
83 void QuotaDispatcher::DidFail( 120 void QuotaDispatcher::DidFail(
84 int request_id, 121 int request_id,
85 WebStorageQuotaError error) { 122 QuotaStatusCode error) {
86 WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup( 123 Callback* callback = pending_quota_callbacks_.Lookup(request_id);
87 request_id); 124 DCHECK(callback);
88 DCHECK(callbacks); 125 callback->DidFail(error);
89 callbacks->didFail(error);
90 pending_quota_callbacks_.Remove(request_id); 126 pending_quota_callbacks_.Remove(request_id);
91 } 127 }
128
129 COMPILE_ASSERT(int(WebKit::WebStorageQuotaTypeTemporary) == \
130 int(quota::kStorageTypeTemporary), mismatching_enums);
131 COMPILE_ASSERT(int(WebKit::WebStorageQuotaTypePersistent) == \
132 int(quota::kStorageTypePersistent), mismatching_enums);
133
134 COMPILE_ASSERT(int(WebKit::WebStorageQuotaErrorNotSupported) == \
135 int(quota::kQuotaErrorNotSupported), mismatching_enums);
136 COMPILE_ASSERT(int(WebKit::WebStorageQuotaErrorAbort) == \
137 int(quota::kQuotaErrorAbort), mismatching_enums);
OLDNEW
« no previous file with comments | « content/common/quota_dispatcher.h ('k') | content/common/quota_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698