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

Side by Side Diff: webkit/database/database_quota_client.cc

Issue 10066044: RefCounted types should not have public destructors, webkit/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Implementation ordering Created 8 years, 7 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 | « webkit/blob/blob_url_request_job.cc ('k') | webkit/database/database_quota_client_unittest.cc » ('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 "webkit/database/database_quota_client.h" 5 #include "webkit/database/database_quota_client.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 14 matching lines...) Expand all
25 25
26 class DatabaseQuotaClient::HelperTask : public quota::QuotaThreadTask { 26 class DatabaseQuotaClient::HelperTask : public quota::QuotaThreadTask {
27 protected: 27 protected:
28 HelperTask( 28 HelperTask(
29 DatabaseQuotaClient* client, 29 DatabaseQuotaClient* client,
30 base::MessageLoopProxy* db_tracker_thread) 30 base::MessageLoopProxy* db_tracker_thread)
31 : QuotaThreadTask(client, db_tracker_thread), 31 : QuotaThreadTask(client, db_tracker_thread),
32 client_(client), db_tracker_(client->db_tracker_) { 32 client_(client), db_tracker_(client->db_tracker_) {
33 } 33 }
34 34
35 virtual ~HelperTask() {}
36
35 DatabaseQuotaClient* client_; 37 DatabaseQuotaClient* client_;
36 scoped_refptr<DatabaseTracker> db_tracker_; 38 scoped_refptr<DatabaseTracker> db_tracker_;
37 }; 39 };
38 40
39 class DatabaseQuotaClient::GetOriginUsageTask : public HelperTask { 41 class DatabaseQuotaClient::GetOriginUsageTask : public HelperTask {
40 public: 42 public:
41 GetOriginUsageTask( 43 GetOriginUsageTask(
42 DatabaseQuotaClient* client, 44 DatabaseQuotaClient* client,
43 base::MessageLoopProxy* db_tracker_thread, 45 base::MessageLoopProxy* db_tracker_thread,
44 const GURL& origin_url) 46 const GURL& origin_url)
45 : HelperTask(client, db_tracker_thread), 47 : HelperTask(client, db_tracker_thread),
46 origin_url_(origin_url), usage_(0) { 48 origin_url_(origin_url), usage_(0) {
47 } 49 }
48 50
49 private: 51 protected:
52 virtual ~GetOriginUsageTask() {}
53
50 virtual void RunOnTargetThread() OVERRIDE { 54 virtual void RunOnTargetThread() OVERRIDE {
51 OriginInfo info; 55 OriginInfo info;
52 if (db_tracker_->GetOriginInfo( 56 if (db_tracker_->GetOriginInfo(
53 DatabaseUtil::GetOriginIdentifier(origin_url_), 57 DatabaseUtil::GetOriginIdentifier(origin_url_),
54 &info)) { 58 &info)) {
55 usage_ = info.TotalSize(); 59 usage_ = info.TotalSize();
56 } 60 }
57 } 61 }
62
58 virtual void Completed() OVERRIDE { 63 virtual void Completed() OVERRIDE {
59 client_->DidGetOriginUsage(origin_url_, usage_); 64 client_->DidGetOriginUsage(origin_url_, usage_);
60 } 65 }
66
67 private:
61 GURL origin_url_; 68 GURL origin_url_;
62 int64 usage_; 69 int64 usage_;
63 }; 70 };
64 71
65 class DatabaseQuotaClient::GetOriginsTaskBase : public HelperTask { 72 class DatabaseQuotaClient::GetOriginsTaskBase : public HelperTask {
66 protected: 73 protected:
67 GetOriginsTaskBase( 74 GetOriginsTaskBase(
68 DatabaseQuotaClient* client, 75 DatabaseQuotaClient* client,
69 base::MessageLoopProxy* db_tracker_thread) 76 base::MessageLoopProxy* db_tracker_thread)
70 : HelperTask(client, db_tracker_thread) { 77 : HelperTask(client, db_tracker_thread) {
71 } 78 }
72 79
80 virtual ~GetOriginsTaskBase() {}
81
73 virtual bool ShouldAddOrigin(const GURL& origin) = 0; 82 virtual bool ShouldAddOrigin(const GURL& origin) = 0;
74 83
75 virtual void RunOnTargetThread() OVERRIDE { 84 virtual void RunOnTargetThread() OVERRIDE {
76 std::vector<string16> origin_identifiers; 85 std::vector<string16> origin_identifiers;
77 if (db_tracker_->GetAllOriginIdentifiers(&origin_identifiers)) { 86 if (db_tracker_->GetAllOriginIdentifiers(&origin_identifiers)) {
78 for (std::vector<string16>::const_iterator iter = 87 for (std::vector<string16>::const_iterator iter =
79 origin_identifiers.begin(); 88 origin_identifiers.begin();
80 iter != origin_identifiers.end(); ++iter) { 89 iter != origin_identifiers.end(); ++iter) {
81 GURL origin = DatabaseUtil::GetOriginFromIdentifier(*iter); 90 GURL origin = DatabaseUtil::GetOriginFromIdentifier(*iter);
82 if (ShouldAddOrigin(origin)) 91 if (ShouldAddOrigin(origin))
83 origins_.insert(origin); 92 origins_.insert(origin);
84 } 93 }
85 } 94 }
86 } 95 }
87 96
88 std::set<GURL> origins_; 97 std::set<GURL> origins_;
89 }; 98 };
90 99
91 class DatabaseQuotaClient::GetAllOriginsTask : public GetOriginsTaskBase { 100 class DatabaseQuotaClient::GetAllOriginsTask : public GetOriginsTaskBase {
92 public: 101 public:
93 GetAllOriginsTask( 102 GetAllOriginsTask(
94 DatabaseQuotaClient* client, 103 DatabaseQuotaClient* client,
95 base::MessageLoopProxy* db_tracker_thread, 104 base::MessageLoopProxy* db_tracker_thread,
96 quota::StorageType type) 105 quota::StorageType type)
97 : GetOriginsTaskBase(client, db_tracker_thread), 106 : GetOriginsTaskBase(client, db_tracker_thread),
98 type_(type) { 107 type_(type) {
99 } 108 }
100 109
101 protected: 110 protected:
111 virtual ~GetAllOriginsTask() {}
112
102 virtual bool ShouldAddOrigin(const GURL& origin) OVERRIDE { 113 virtual bool ShouldAddOrigin(const GURL& origin) OVERRIDE {
103 return true; 114 return true;
104 } 115 }
105 virtual void Completed() OVERRIDE { 116 virtual void Completed() OVERRIDE {
106 client_->DidGetAllOrigins(origins_, type_); 117 client_->DidGetAllOrigins(origins_, type_);
107 } 118 }
108 119
109 private: 120 private:
110 quota::StorageType type_; 121 quota::StorageType type_;
111 }; 122 };
112 123
113 class DatabaseQuotaClient::GetOriginsForHostTask : public GetOriginsTaskBase { 124 class DatabaseQuotaClient::GetOriginsForHostTask : public GetOriginsTaskBase {
114 public: 125 public:
115 GetOriginsForHostTask( 126 GetOriginsForHostTask(
116 DatabaseQuotaClient* client, 127 DatabaseQuotaClient* client,
117 base::MessageLoopProxy* db_tracker_thread, 128 base::MessageLoopProxy* db_tracker_thread,
118 const std::string& host, 129 const std::string& host,
119 quota::StorageType type) 130 quota::StorageType type)
120 : GetOriginsTaskBase(client, db_tracker_thread), 131 : GetOriginsTaskBase(client, db_tracker_thread),
121 host_(host), 132 host_(host),
122 type_(type) { 133 type_(type) {
123 } 134 }
124 135
125 private: 136 protected:
137 virtual ~GetOriginsForHostTask() {}
138
126 virtual bool ShouldAddOrigin(const GURL& origin) OVERRIDE { 139 virtual bool ShouldAddOrigin(const GURL& origin) OVERRIDE {
127 return host_ == net::GetHostOrSpecFromURL(origin); 140 return host_ == net::GetHostOrSpecFromURL(origin);
128 } 141 }
142
129 virtual void Completed() OVERRIDE { 143 virtual void Completed() OVERRIDE {
130 client_->DidGetOriginsForHost(host_, origins_, type_); 144 client_->DidGetOriginsForHost(host_, origins_, type_);
131 } 145 }
146
147 private:
132 std::string host_; 148 std::string host_;
133 quota::StorageType type_; 149 quota::StorageType type_;
134 }; 150 };
135 151
136 class DatabaseQuotaClient::DeleteOriginTask : public HelperTask { 152 class DatabaseQuotaClient::DeleteOriginTask : public HelperTask {
137 public: 153 public:
138 DeleteOriginTask( 154 DeleteOriginTask(
139 DatabaseQuotaClient* client, 155 DatabaseQuotaClient* client,
140 base::MessageLoopProxy* db_tracker_thread, 156 base::MessageLoopProxy* db_tracker_thread,
141 const GURL& origin_url, 157 const GURL& origin_url,
142 const DeletionCallback& caller_callback) 158 const DeletionCallback& caller_callback)
143 : HelperTask(client, db_tracker_thread), 159 : HelperTask(client, db_tracker_thread),
144 origin_url_(origin_url), 160 origin_url_(origin_url),
145 result_(quota::kQuotaStatusUnknown), 161 result_(quota::kQuotaStatusUnknown),
146 caller_callback_(caller_callback) { 162 caller_callback_(caller_callback) {
147 } 163 }
148 164
149 private: 165 protected:
166 virtual ~DeleteOriginTask() {}
167
150 virtual void Completed() OVERRIDE { 168 virtual void Completed() OVERRIDE {
151 if (caller_callback_.is_null()) 169 if (caller_callback_.is_null())
152 return; 170 return;
153 caller_callback_.Run(result_); 171 caller_callback_.Run(result_);
154 caller_callback_.Reset(); 172 caller_callback_.Reset();
155 } 173 }
156 174
157 virtual void Aborted() OVERRIDE { 175 virtual void Aborted() OVERRIDE {
158 caller_callback_.Reset(); 176 caller_callback_.Reset();
159 } 177 }
160 178
161 virtual bool RunOnTargetThreadAsync() OVERRIDE { 179 virtual bool RunOnTargetThreadAsync() OVERRIDE {
162 AddRef(); // balanced in OnCompletionCallback 180 AddRef(); // balanced in OnCompletionCallback
163 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url_); 181 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url_);
164 int rv = db_tracker_->DeleteDataForOrigin( 182 int rv = db_tracker_->DeleteDataForOrigin(
165 origin_id, base::Bind(&DeleteOriginTask::OnCompletionCallback, 183 origin_id, base::Bind(&DeleteOriginTask::OnCompletionCallback,
166 base::Unretained(this))); 184 base::Unretained(this)));
167 if (rv == net::ERR_IO_PENDING) 185 if (rv == net::ERR_IO_PENDING)
168 return false; // we wait for the callback 186 return false; // we wait for the callback
169 OnCompletionCallback(rv); 187 OnCompletionCallback(rv);
170 return false; 188 return false;
171 } 189 }
172 190
191 private:
173 void OnCompletionCallback(int rv) { 192 void OnCompletionCallback(int rv) {
174 if (rv == net::OK) 193 if (rv == net::OK)
175 result_ = quota::kQuotaStatusOk; 194 result_ = quota::kQuotaStatusOk;
176 original_message_loop()->PostTask( 195 original_message_loop()->PostTask(
177 FROM_HERE, base::Bind(&DeleteOriginTask::CallCompleted, this)); 196 FROM_HERE, base::Bind(&DeleteOriginTask::CallCompleted, this));
178 Release(); // balanced in RunOnTargetThreadAsync 197 Release(); // balanced in RunOnTargetThreadAsync
179 } 198 }
180 199
181 const GURL origin_url_; 200 const GURL origin_url_;
182 quota::QuotaStatusCode result_; 201 quota::QuotaStatusCode result_;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 } 312 }
294 313
295 void DatabaseQuotaClient::DidGetOriginsForHost( 314 void DatabaseQuotaClient::DidGetOriginsForHost(
296 const std::string& host, const std::set<GURL>& origins, 315 const std::string& host, const std::set<GURL>& origins,
297 quota::StorageType type) { 316 quota::StorageType type) {
298 DCHECK(origins_for_host_callbacks_.HasCallbacks(host)); 317 DCHECK(origins_for_host_callbacks_.HasCallbacks(host));
299 origins_for_host_callbacks_.Run(host, origins, type); 318 origins_for_host_callbacks_.Run(host, origins, type);
300 } 319 }
301 320
302 } // namespace webkit_database 321 } // namespace webkit_database
OLDNEW
« no previous file with comments | « webkit/blob/blob_url_request_job.cc ('k') | webkit/database/database_quota_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698