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 "content/browser/in_process_webkit/indexed_db_quota_client.h" | 5 #include "content/browser/in_process_webkit/indexed_db_quota_client.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 } | 35 } |
36 | 36 |
37 void GetAllOriginsOnWebKitThread( | 37 void GetAllOriginsOnWebKitThread( |
38 IndexedDBContextImpl* context, | 38 IndexedDBContextImpl* context, |
39 std::set<GURL>* origins_to_return) { | 39 std::set<GURL>* origins_to_return) { |
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
41 std::vector<GURL> all_origins = context->GetAllOrigins(); | 41 std::vector<GURL> all_origins = context->GetAllOrigins(); |
42 origins_to_return->insert(all_origins.begin(), all_origins.end()); | 42 origins_to_return->insert(all_origins.begin(), all_origins.end()); |
43 } | 43 } |
44 | 44 |
45 void DidGetAllOrigins( | 45 void DidGetOrigins( |
46 const IndexedDBQuotaClient::GetOriginsCallback& callback, | 46 const IndexedDBQuotaClient::GetOriginsCallback& callback, |
47 const std::set<GURL>* origins, | 47 const std::set<GURL>* origins, |
48 quota::StorageType storage_type) { | 48 quota::StorageType storage_type) { |
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
50 callback.Run(*origins, storage_type); | 50 callback.Run(*origins, storage_type); |
51 } | 51 } |
52 | 52 |
| 53 void GetOriginsForHostOnWebKitThread( |
| 54 IndexedDBContextImpl* context, |
| 55 const std::string& host, |
| 56 std::set<GURL>* origins_to_return) { |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
| 58 std::vector<GURL> all_origins = context->GetAllOrigins(); |
| 59 for (std::vector<GURL>::const_iterator iter = all_origins.begin(); |
| 60 iter != all_origins.end(); ++iter) { |
| 61 if (host == net::GetHostOrSpecFromURL(*iter)) |
| 62 origins_to_return->insert(*iter); |
| 63 } |
| 64 } |
| 65 |
53 } // namespace | 66 } // namespace |
54 | 67 |
55 // Helper tasks --------------------------------------------------------------- | |
56 | |
57 class IndexedDBQuotaClient::HelperTask : public quota::QuotaThreadTask { | |
58 protected: | |
59 HelperTask( | |
60 IndexedDBQuotaClient* client, | |
61 base::MessageLoopProxy* webkit_thread_message_loop) | |
62 : QuotaThreadTask(client, webkit_thread_message_loop), | |
63 client_(client), indexed_db_context_(client->indexed_db_context_) { | |
64 } | |
65 | |
66 IndexedDBQuotaClient* client_; | |
67 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; | |
68 | |
69 protected: | |
70 virtual ~HelperTask() {} | |
71 }; | |
72 | |
73 class IndexedDBQuotaClient::GetOriginsTaskBase : public HelperTask { | |
74 protected: | |
75 GetOriginsTaskBase( | |
76 IndexedDBQuotaClient* client, | |
77 base::MessageLoopProxy* webkit_thread_message_loop) | |
78 : HelperTask(client, webkit_thread_message_loop) { | |
79 } | |
80 | |
81 virtual bool ShouldAddOrigin(const GURL& origin) = 0; | |
82 | |
83 virtual void RunOnTargetThread() OVERRIDE { | |
84 std::vector<GURL> origins = indexed_db_context_->GetAllOrigins(); | |
85 for (std::vector<GURL>::const_iterator iter = origins.begin(); | |
86 iter != origins.end(); ++iter) { | |
87 if (ShouldAddOrigin(*iter)) | |
88 origins_.insert(*iter); | |
89 } | |
90 } | |
91 | |
92 std::set<GURL> origins_; | |
93 | |
94 protected: | |
95 virtual ~GetOriginsTaskBase() {} | |
96 }; | |
97 | |
98 class IndexedDBQuotaClient::GetOriginsForHostTask : public GetOriginsTaskBase { | |
99 public: | |
100 GetOriginsForHostTask( | |
101 IndexedDBQuotaClient* client, | |
102 base::MessageLoopProxy* webkit_thread_message_loop, | |
103 const std::string& host, | |
104 quota::StorageType type) | |
105 : GetOriginsTaskBase(client, webkit_thread_message_loop), | |
106 host_(host), | |
107 type_(type) { | |
108 } | |
109 | |
110 private: | |
111 virtual ~GetOriginsForHostTask() {} | |
112 | |
113 virtual bool ShouldAddOrigin(const GURL& origin) OVERRIDE { | |
114 return host_ == net::GetHostOrSpecFromURL(origin); | |
115 } | |
116 | |
117 virtual void Completed() OVERRIDE { | |
118 client_->DidGetOriginsForHost(host_, origins_, type_); | |
119 } | |
120 | |
121 std::string host_; | |
122 quota::StorageType type_; | |
123 }; | |
124 | |
125 // IndexedDBQuotaClient -------------------------------------------------------- | 68 // IndexedDBQuotaClient -------------------------------------------------------- |
126 | 69 |
127 IndexedDBQuotaClient::IndexedDBQuotaClient( | 70 IndexedDBQuotaClient::IndexedDBQuotaClient( |
128 base::MessageLoopProxy* webkit_thread_message_loop, | 71 base::MessageLoopProxy* webkit_thread_message_loop, |
129 IndexedDBContextImpl* indexed_db_context) | 72 IndexedDBContextImpl* indexed_db_context) |
130 : webkit_thread_message_loop_(webkit_thread_message_loop), | 73 : webkit_thread_message_loop_(webkit_thread_message_loop), |
131 indexed_db_context_(indexed_db_context) { | 74 indexed_db_context_(indexed_db_context) { |
132 } | 75 } |
133 | 76 |
134 IndexedDBQuotaClient::~IndexedDBQuotaClient() { | 77 IndexedDBQuotaClient::~IndexedDBQuotaClient() { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 callback.Run(std::set<GURL>(), type); | 118 callback.Run(std::set<GURL>(), type); |
176 return; | 119 return; |
177 } | 120 } |
178 | 121 |
179 std::set<GURL>* origins_to_return = new std::set<GURL>(); | 122 std::set<GURL>* origins_to_return = new std::set<GURL>(); |
180 webkit_thread_message_loop_->PostTaskAndReply( | 123 webkit_thread_message_loop_->PostTaskAndReply( |
181 FROM_HERE, | 124 FROM_HERE, |
182 base::Bind(&GetAllOriginsOnWebKitThread, | 125 base::Bind(&GetAllOriginsOnWebKitThread, |
183 indexed_db_context_, | 126 indexed_db_context_, |
184 base::Unretained(origins_to_return)), | 127 base::Unretained(origins_to_return)), |
185 base::Bind(&DidGetAllOrigins, | 128 base::Bind(&DidGetOrigins, |
186 callback, | 129 callback, |
187 base::Owned(origins_to_return), | 130 base::Owned(origins_to_return), |
188 type)); | 131 type)); |
189 } | 132 } |
190 | 133 |
191 void IndexedDBQuotaClient::GetOriginsForHost( | 134 void IndexedDBQuotaClient::GetOriginsForHost( |
192 quota::StorageType type, | 135 quota::StorageType type, |
193 const std::string& host, | 136 const std::string& host, |
194 const GetOriginsCallback& callback) { | 137 const GetOriginsCallback& callback) { |
195 DCHECK(!callback.is_null()); | 138 DCHECK(!callback.is_null()); |
196 DCHECK(indexed_db_context_.get()); | 139 DCHECK(indexed_db_context_.get()); |
197 | 140 |
198 // All databases are in the temp namespace for now. | 141 // All databases are in the temp namespace for now. |
199 if (type != quota::kStorageTypeTemporary) { | 142 if (type != quota::kStorageTypeTemporary) { |
200 callback.Run(std::set<GURL>(), type); | 143 callback.Run(std::set<GURL>(), type); |
201 return; | 144 return; |
202 } | 145 } |
203 | 146 |
204 if (origins_for_host_callbacks_.Add(host, callback)) { | 147 std::set<GURL>* origins_to_return = new std::set<GURL>(); |
205 scoped_refptr<GetOriginsForHostTask> task( | 148 webkit_thread_message_loop_->PostTaskAndReply( |
206 new GetOriginsForHostTask( | 149 FROM_HERE, |
207 this, webkit_thread_message_loop_, host, type)); | 150 base::Bind(&GetOriginsForHostOnWebKitThread, |
208 task->Start(); | 151 indexed_db_context_, |
209 } | 152 host, |
| 153 base::Unretained(origins_to_return)), |
| 154 base::Bind(&DidGetOrigins, |
| 155 callback, |
| 156 base::Owned(origins_to_return), |
| 157 type)); |
210 } | 158 } |
211 | 159 |
212 void IndexedDBQuotaClient::DeleteOriginData( | 160 void IndexedDBQuotaClient::DeleteOriginData( |
213 const GURL& origin, | 161 const GURL& origin, |
214 quota::StorageType type, | 162 quota::StorageType type, |
215 const DeletionCallback& callback) { | 163 const DeletionCallback& callback) { |
216 if (type != quota::kStorageTypeTemporary) { | 164 if (type != quota::kStorageTypeTemporary) { |
217 callback.Run(quota::kQuotaErrorNotSupported); | 165 callback.Run(quota::kQuotaErrorNotSupported); |
218 return; | 166 return; |
219 } | 167 } |
220 | 168 |
221 base::PostTaskAndReplyWithResult( | 169 base::PostTaskAndReplyWithResult( |
222 webkit_thread_message_loop_, | 170 webkit_thread_message_loop_, |
223 FROM_HERE, | 171 FROM_HERE, |
224 base::Bind(&DeleteOriginDataOnWebKitThread, | 172 base::Bind(&DeleteOriginDataOnWebKitThread, |
225 indexed_db_context_, | 173 indexed_db_context_, |
226 origin), | 174 origin), |
227 callback); | 175 callback); |
228 } | 176 } |
229 | |
230 void IndexedDBQuotaClient::DidGetOriginsForHost( | |
231 const std::string& host, const std::set<GURL>& origins, | |
232 quota::StorageType type) { | |
233 DCHECK(origins_for_host_callbacks_.HasCallbacks(host)); | |
234 origins_for_host_callbacks_.Run(host, origins, type); | |
235 } | |
OLD | NEW |