OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/database/database_quota_client.h" | 5 #include "storage/browser/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" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop/message_loop_proxy.h" | 13 #include "base/message_loop/message_loop_proxy.h" |
14 #include "base/task_runner_util.h" | 14 #include "base/task_runner_util.h" |
15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
17 #include "webkit/browser/database/database_tracker.h" | 17 #include "storage/browser/database/database_tracker.h" |
18 #include "webkit/browser/database/database_util.h" | 18 #include "storage/browser/database/database_util.h" |
19 #include "webkit/common/database/database_identifier.h" | 19 #include "storage/common/database/database_identifier.h" |
20 | 20 |
21 using quota::QuotaClient; | 21 using quota::QuotaClient; |
22 | 22 |
23 namespace webkit_database { | 23 namespace webkit_database { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 int64 GetOriginUsageOnDBThread( | 27 int64 GetOriginUsageOnDBThread(DatabaseTracker* db_tracker, |
28 DatabaseTracker* db_tracker, | 28 const GURL& origin_url) { |
29 const GURL& origin_url) { | |
30 OriginInfo info; | 29 OriginInfo info; |
31 if (db_tracker->GetOriginInfo( | 30 if (db_tracker->GetOriginInfo( |
32 webkit_database::GetIdentifierFromOrigin(origin_url), &info)) | 31 webkit_database::GetIdentifierFromOrigin(origin_url), &info)) |
33 return info.TotalSize(); | 32 return info.TotalSize(); |
34 return 0; | 33 return 0; |
35 } | 34 } |
36 | 35 |
37 void GetOriginsOnDBThread( | 36 void GetOriginsOnDBThread(DatabaseTracker* db_tracker, |
38 DatabaseTracker* db_tracker, | 37 std::set<GURL>* origins_ptr) { |
39 std::set<GURL>* origins_ptr) { | |
40 std::vector<std::string> origin_identifiers; | 38 std::vector<std::string> origin_identifiers; |
41 if (db_tracker->GetAllOriginIdentifiers(&origin_identifiers)) { | 39 if (db_tracker->GetAllOriginIdentifiers(&origin_identifiers)) { |
42 for (std::vector<std::string>::const_iterator iter = | 40 for (std::vector<std::string>::const_iterator iter = |
43 origin_identifiers.begin(); | 41 origin_identifiers.begin(); |
44 iter != origin_identifiers.end(); ++iter) { | 42 iter != origin_identifiers.end(); |
| 43 ++iter) { |
45 GURL origin = webkit_database::GetOriginFromIdentifier(*iter); | 44 GURL origin = webkit_database::GetOriginFromIdentifier(*iter); |
46 origins_ptr->insert(origin); | 45 origins_ptr->insert(origin); |
47 } | 46 } |
48 } | 47 } |
49 } | 48 } |
50 | 49 |
51 void GetOriginsForHostOnDBThread( | 50 void GetOriginsForHostOnDBThread(DatabaseTracker* db_tracker, |
52 DatabaseTracker* db_tracker, | 51 std::set<GURL>* origins_ptr, |
53 std::set<GURL>* origins_ptr, | 52 const std::string& host) { |
54 const std::string& host) { | |
55 std::vector<std::string> origin_identifiers; | 53 std::vector<std::string> origin_identifiers; |
56 if (db_tracker->GetAllOriginIdentifiers(&origin_identifiers)) { | 54 if (db_tracker->GetAllOriginIdentifiers(&origin_identifiers)) { |
57 for (std::vector<std::string>::const_iterator iter = | 55 for (std::vector<std::string>::const_iterator iter = |
58 origin_identifiers.begin(); | 56 origin_identifiers.begin(); |
59 iter != origin_identifiers.end(); ++iter) { | 57 iter != origin_identifiers.end(); |
| 58 ++iter) { |
60 GURL origin = webkit_database::GetOriginFromIdentifier(*iter); | 59 GURL origin = webkit_database::GetOriginFromIdentifier(*iter); |
61 if (host == net::GetHostOrSpecFromURL(origin)) | 60 if (host == net::GetHostOrSpecFromURL(origin)) |
62 origins_ptr->insert(origin); | 61 origins_ptr->insert(origin); |
63 } | 62 } |
64 } | 63 } |
65 } | 64 } |
66 | 65 |
67 void DidGetOrigins( | 66 void DidGetOrigins(const QuotaClient::GetOriginsCallback& callback, |
68 const QuotaClient::GetOriginsCallback& callback, | 67 std::set<GURL>* origins_ptr) { |
69 std::set<GURL>* origins_ptr) { | |
70 callback.Run(*origins_ptr); | 68 callback.Run(*origins_ptr); |
71 } | 69 } |
72 | 70 |
73 void DidDeleteOriginData( | 71 void DidDeleteOriginData(base::SingleThreadTaskRunner* original_task_runner, |
74 base::SingleThreadTaskRunner* original_task_runner, | 72 const QuotaClient::DeletionCallback& callback, |
75 const QuotaClient::DeletionCallback& callback, | 73 int result) { |
76 int result) { | |
77 if (result == net::ERR_IO_PENDING) { | 74 if (result == net::ERR_IO_PENDING) { |
78 // The callback will be invoked via | 75 // The callback will be invoked via |
79 // DatabaseTracker::ScheduleDatabasesForDeletion. | 76 // DatabaseTracker::ScheduleDatabasesForDeletion. |
80 return; | 77 return; |
81 } | 78 } |
82 | 79 |
83 quota::QuotaStatusCode status; | 80 quota::QuotaStatusCode status; |
84 if (result == net::OK) | 81 if (result == net::OK) |
85 status = quota::kQuotaStatusOk; | 82 status = quota::kQuotaStatusOk; |
86 else | 83 else |
(...skipping 25 matching lines...) Expand all Loading... |
112 } | 109 } |
113 | 110 |
114 QuotaClient::ID DatabaseQuotaClient::id() const { | 111 QuotaClient::ID DatabaseQuotaClient::id() const { |
115 return kDatabase; | 112 return kDatabase; |
116 } | 113 } |
117 | 114 |
118 void DatabaseQuotaClient::OnQuotaManagerDestroyed() { | 115 void DatabaseQuotaClient::OnQuotaManagerDestroyed() { |
119 delete this; | 116 delete this; |
120 } | 117 } |
121 | 118 |
122 void DatabaseQuotaClient::GetOriginUsage( | 119 void DatabaseQuotaClient::GetOriginUsage(const GURL& origin_url, |
123 const GURL& origin_url, | 120 quota::StorageType type, |
124 quota::StorageType type, | 121 const GetUsageCallback& callback) { |
125 const GetUsageCallback& callback) { | |
126 DCHECK(!callback.is_null()); | 122 DCHECK(!callback.is_null()); |
127 DCHECK(db_tracker_.get()); | 123 DCHECK(db_tracker_.get()); |
128 | 124 |
129 // All databases are in the temp namespace for now. | 125 // All databases are in the temp namespace for now. |
130 if (type != quota::kStorageTypeTemporary) { | 126 if (type != quota::kStorageTypeTemporary) { |
131 callback.Run(0); | 127 callback.Run(0); |
132 return; | 128 return; |
133 } | 129 } |
134 | 130 |
135 base::PostTaskAndReplyWithResult( | 131 base::PostTaskAndReplyWithResult( |
(...skipping 11 matching lines...) Expand all Loading... |
147 | 143 |
148 // All databases are in the temp namespace for now. | 144 // All databases are in the temp namespace for now. |
149 if (type != quota::kStorageTypeTemporary) { | 145 if (type != quota::kStorageTypeTemporary) { |
150 callback.Run(std::set<GURL>()); | 146 callback.Run(std::set<GURL>()); |
151 return; | 147 return; |
152 } | 148 } |
153 | 149 |
154 std::set<GURL>* origins_ptr = new std::set<GURL>(); | 150 std::set<GURL>* origins_ptr = new std::set<GURL>(); |
155 db_tracker_thread_->PostTaskAndReply( | 151 db_tracker_thread_->PostTaskAndReply( |
156 FROM_HERE, | 152 FROM_HERE, |
157 base::Bind(&GetOriginsOnDBThread, | 153 base::Bind( |
158 db_tracker_, | 154 &GetOriginsOnDBThread, db_tracker_, base::Unretained(origins_ptr)), |
159 base::Unretained(origins_ptr)), | 155 base::Bind(&DidGetOrigins, callback, base::Owned(origins_ptr))); |
160 base::Bind(&DidGetOrigins, | |
161 callback, | |
162 base::Owned(origins_ptr))); | |
163 } | 156 } |
164 | 157 |
165 void DatabaseQuotaClient::GetOriginsForHost( | 158 void DatabaseQuotaClient::GetOriginsForHost( |
166 quota::StorageType type, | 159 quota::StorageType type, |
167 const std::string& host, | 160 const std::string& host, |
168 const GetOriginsCallback& callback) { | 161 const GetOriginsCallback& callback) { |
169 DCHECK(!callback.is_null()); | 162 DCHECK(!callback.is_null()); |
170 DCHECK(db_tracker_.get()); | 163 DCHECK(db_tracker_.get()); |
171 | 164 |
172 // All databases are in the temp namespace for now. | 165 // All databases are in the temp namespace for now. |
173 if (type != quota::kStorageTypeTemporary) { | 166 if (type != quota::kStorageTypeTemporary) { |
174 callback.Run(std::set<GURL>()); | 167 callback.Run(std::set<GURL>()); |
175 return; | 168 return; |
176 } | 169 } |
177 | 170 |
178 std::set<GURL>* origins_ptr = new std::set<GURL>(); | 171 std::set<GURL>* origins_ptr = new std::set<GURL>(); |
179 db_tracker_thread_->PostTaskAndReply( | 172 db_tracker_thread_->PostTaskAndReply( |
180 FROM_HERE, | 173 FROM_HERE, |
181 base::Bind(&GetOriginsForHostOnDBThread, | 174 base::Bind(&GetOriginsForHostOnDBThread, |
182 db_tracker_, | 175 db_tracker_, |
183 base::Unretained(origins_ptr), | 176 base::Unretained(origins_ptr), |
184 host), | 177 host), |
185 base::Bind(&DidGetOrigins, | 178 base::Bind(&DidGetOrigins, callback, base::Owned(origins_ptr))); |
186 callback, | |
187 base::Owned(origins_ptr))); | |
188 } | 179 } |
189 | 180 |
190 void DatabaseQuotaClient::DeleteOriginData( | 181 void DatabaseQuotaClient::DeleteOriginData(const GURL& origin, |
191 const GURL& origin, | 182 quota::StorageType type, |
192 quota::StorageType type, | 183 const DeletionCallback& callback) { |
193 const DeletionCallback& callback) { | |
194 DCHECK(!callback.is_null()); | 184 DCHECK(!callback.is_null()); |
195 DCHECK(db_tracker_.get()); | 185 DCHECK(db_tracker_.get()); |
196 | 186 |
197 // All databases are in the temp namespace for now, so nothing to delete. | 187 // All databases are in the temp namespace for now, so nothing to delete. |
198 if (type != quota::kStorageTypeTemporary) { | 188 if (type != quota::kStorageTypeTemporary) { |
199 callback.Run(quota::kQuotaStatusOk); | 189 callback.Run(quota::kQuotaStatusOk); |
200 return; | 190 return; |
201 } | 191 } |
202 | 192 |
203 base::Callback<void(int)> delete_callback = | 193 base::Callback<void(int)> delete_callback = base::Bind( |
204 base::Bind(&DidDeleteOriginData, | 194 &DidDeleteOriginData, base::MessageLoopProxy::current(), callback); |
205 base::MessageLoopProxy::current(), | |
206 callback); | |
207 | 195 |
208 PostTaskAndReplyWithResult( | 196 PostTaskAndReplyWithResult( |
209 db_tracker_thread_.get(), | 197 db_tracker_thread_.get(), |
210 FROM_HERE, | 198 FROM_HERE, |
211 base::Bind(&DatabaseTracker::DeleteDataForOrigin, | 199 base::Bind(&DatabaseTracker::DeleteDataForOrigin, |
212 db_tracker_, | 200 db_tracker_, |
213 webkit_database::GetIdentifierFromOrigin(origin), | 201 webkit_database::GetIdentifierFromOrigin(origin), |
214 delete_callback), | 202 delete_callback), |
215 delete_callback); | 203 delete_callback); |
216 } | 204 } |
217 | 205 |
218 bool DatabaseQuotaClient::DoesSupport(quota::StorageType type) const { | 206 bool DatabaseQuotaClient::DoesSupport(quota::StorageType type) const { |
219 return type == quota::kStorageTypeTemporary; | 207 return type == quota::kStorageTypeTemporary; |
220 } | 208 } |
221 | 209 |
222 } // namespace webkit_database | 210 } // namespace webkit_database |
OLD | NEW |