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/indexed_db/indexed_db_context_impl.h" | 5 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 origins.push_back(*iter); | 123 origins.push_back(*iter); |
124 } | 124 } |
125 return origins; | 125 return origins; |
126 } | 126 } |
127 | 127 |
128 std::vector<IndexedDBInfo> IndexedDBContextImpl::GetAllOriginsInfo() { | 128 std::vector<IndexedDBInfo> IndexedDBContextImpl::GetAllOriginsInfo() { |
129 std::vector<GURL> origins = GetAllOrigins(); | 129 std::vector<GURL> origins = GetAllOrigins(); |
130 std::vector<IndexedDBInfo> result; | 130 std::vector<IndexedDBInfo> result; |
131 for (std::vector<GURL>::const_iterator iter = origins.begin(); | 131 for (std::vector<GURL>::const_iterator iter = origins.begin(); |
132 iter != origins.end(); ++iter) { | 132 iter != origins.end(); ++iter) { |
133 const GURL& origin = *iter; | 133 const GURL& origin_url = *iter; |
134 | 134 |
135 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin); | 135 base::FilePath idb_directory = GetFilePath(origin_url); |
136 base::FilePath idb_directory = GetIndexedDBFilePath(origin_id); | 136 result.push_back(IndexedDBInfo(origin_url, |
137 result.push_back(IndexedDBInfo(origin, | 137 GetOriginDiskUsage(origin_url), |
138 GetOriginDiskUsage(origin), | 138 GetOriginLastModified(origin_url), |
139 GetOriginLastModified(origin), | |
140 idb_directory)); | 139 idb_directory)); |
141 } | 140 } |
142 return result; | 141 return result; |
143 } | 142 } |
144 | 143 |
145 int64 IndexedDBContextImpl::GetOriginDiskUsage(const GURL& origin_url) { | 144 int64 IndexedDBContextImpl::GetOriginDiskUsage(const GURL& origin_url) { |
146 if (data_path_.empty() || !IsInOriginSet(origin_url)) | 145 if (data_path_.empty() || !HasOrigin(origin_url)) |
147 return 0; | 146 return 0; |
148 EnsureDiskUsageCacheInitialized(origin_url); | 147 EnsureDiskUsageCacheInitialized(origin_url); |
149 return origin_size_map_[origin_url]; | 148 return origin_size_map_[origin_url]; |
150 } | 149 } |
151 | 150 |
152 base::Time IndexedDBContextImpl::GetOriginLastModified(const GURL& origin_url) { | 151 base::Time IndexedDBContextImpl::GetOriginLastModified(const GURL& origin_url) { |
153 if (data_path_.empty() || !IsInOriginSet(origin_url)) | 152 if (data_path_.empty() || !HasOrigin(origin_url)) |
154 return base::Time(); | 153 return base::Time(); |
155 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url); | 154 base::FilePath idb_directory = GetFilePath(origin_url); |
156 base::FilePath idb_directory = GetIndexedDBFilePath(origin_id); | |
157 base::PlatformFileInfo file_info; | 155 base::PlatformFileInfo file_info; |
158 if (!file_util::GetFileInfo(idb_directory, &file_info)) | 156 if (!file_util::GetFileInfo(idb_directory, &file_info)) |
159 return base::Time(); | 157 return base::Time(); |
160 return file_info.last_modified; | 158 return file_info.last_modified; |
161 } | 159 } |
162 | 160 |
163 void IndexedDBContextImpl::DeleteForOrigin(const GURL& origin_url) { | 161 void IndexedDBContextImpl::DeleteForOrigin(const GURL& origin_url) { |
164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
165 if (data_path_.empty() || !IsInOriginSet(origin_url)) | 163 ForceClose(origin_url); |
| 164 if (data_path_.empty() || !HasOrigin(origin_url)) |
| 165 return; |
| 166 |
| 167 base::FilePath idb_directory = GetFilePath(origin_url); |
| 168 EnsureDiskUsageCacheInitialized(origin_url); |
| 169 const bool recursive = true; |
| 170 bool deleted = file_util::Delete(idb_directory, recursive); |
| 171 |
| 172 QueryDiskAndUpdateQuotaUsage(origin_url); |
| 173 if (deleted) { |
| 174 RemoveFromOriginSet(origin_url); |
| 175 origin_size_map_.erase(origin_url); |
| 176 space_available_map_.erase(origin_url); |
| 177 } |
| 178 } |
| 179 |
| 180 void IndexedDBContextImpl::ForceClose(const GURL& origin_url) { |
| 181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
| 182 if (data_path_.empty() || !HasOrigin(origin_url)) |
166 return; | 183 return; |
167 | 184 |
168 if (connections_.find(origin_url) != connections_.end()) { | 185 if (connections_.find(origin_url) != connections_.end()) { |
169 ConnectionSet& connections = connections_[origin_url]; | 186 ConnectionSet& connections = connections_[origin_url]; |
170 ConnectionSet::iterator it = connections.begin(); | 187 ConnectionSet::iterator it = connections.begin(); |
171 while (it != connections.end()) { | 188 while (it != connections.end()) { |
172 // Remove before closing so callbacks don't double-erase | 189 // Remove before closing so callbacks don't double-erase |
173 WebKit::WebIDBDatabase* db = *it; | 190 WebKit::WebIDBDatabase* db = *it; |
174 connections.erase(it++); | 191 connections.erase(it++); |
175 db->forceClose(); | 192 db->forceClose(); |
176 } | 193 } |
177 DCHECK(connections_[origin_url].size() == 0); | 194 DCHECK_EQ(connections_[origin_url].size(), 0UL); |
178 connections_.erase(origin_url); | 195 connections_.erase(origin_url); |
179 } | 196 } |
180 | |
181 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url); | |
182 base::FilePath idb_directory = GetIndexedDBFilePath(origin_id); | |
183 EnsureDiskUsageCacheInitialized(origin_url); | |
184 const bool recursive = true; | |
185 bool deleted = file_util::Delete(idb_directory, recursive); | |
186 | |
187 QueryDiskAndUpdateQuotaUsage(origin_url); | |
188 if (deleted) { | |
189 RemoveFromOriginSet(origin_url); | |
190 origin_size_map_.erase(origin_url); | |
191 space_available_map_.erase(origin_url); | |
192 } | |
193 } | 197 } |
194 | 198 |
| 199 base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) { |
| 200 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url); |
| 201 return GetIndexedDBFilePath(origin_id); |
| 202 } |
| 203 |
195 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( | 204 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( |
196 const string16& origin_id) const { | 205 const string16& origin_id) const { |
197 return GetIndexedDBFilePath(origin_id); | 206 return GetIndexedDBFilePath(origin_id); |
198 } | 207 } |
199 | 208 |
200 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, | 209 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, |
201 WebIDBDatabase* connection) { | 210 WebIDBDatabase* connection) { |
202 DCHECK(connections_[origin_url].count(connection) == 0); | 211 DCHECK_EQ(connections_[origin_url].count(connection), 0UL); |
203 if (quota_manager_proxy()) { | 212 if (quota_manager_proxy()) { |
204 quota_manager_proxy()->NotifyStorageAccessed( | 213 quota_manager_proxy()->NotifyStorageAccessed( |
205 quota::QuotaClient::kIndexedDatabase, origin_url, | 214 quota::QuotaClient::kIndexedDatabase, origin_url, |
206 quota::kStorageTypeTemporary); | 215 quota::kStorageTypeTemporary); |
207 } | 216 } |
208 connections_[origin_url].insert(connection); | 217 connections_[origin_url].insert(connection); |
209 if (AddToOriginSet(origin_url)) { | 218 if (AddToOriginSet(origin_url)) { |
210 // A newly created db, notify the quota system. | 219 // A newly created db, notify the quota system. |
211 QueryDiskAndUpdateQuotaUsage(origin_url); | 220 QueryDiskAndUpdateQuotaUsage(origin_url); |
212 } else { | 221 } else { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 std::vector<GURL> origins; | 386 std::vector<GURL> origins; |
378 GetAllOriginsAndPaths(data_path_, &origins, NULL); | 387 GetAllOriginsAndPaths(data_path_, &origins, NULL); |
379 for (std::vector<GURL>::const_iterator iter = origins.begin(); | 388 for (std::vector<GURL>::const_iterator iter = origins.begin(); |
380 iter != origins.end(); ++iter) { | 389 iter != origins.end(); ++iter) { |
381 origin_set_->insert(*iter); | 390 origin_set_->insert(*iter); |
382 } | 391 } |
383 } | 392 } |
384 return origin_set_.get(); | 393 return origin_set_.get(); |
385 } | 394 } |
386 | 395 |
| 396 bool IndexedDBContextImpl::HasOrigin(const GURL& origin_url) { |
| 397 std::set<GURL>* set = GetOriginSet(); |
| 398 return set->find(origin_url) != set->end(); |
| 399 } |
| 400 |
387 void IndexedDBContextImpl::ResetCaches() { | 401 void IndexedDBContextImpl::ResetCaches() { |
388 origin_set_.reset(); | 402 origin_set_.reset(); |
389 origin_size_map_.clear(); | 403 origin_size_map_.clear(); |
390 space_available_map_.clear(); | 404 space_available_map_.clear(); |
391 } | 405 } |
392 | 406 |
393 } // namespace content | 407 } // namespace content |
OLD | NEW |