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

Side by Side Diff: content/browser/indexed_db/indexed_db_context_impl.cc

Issue 13949013: Implement download link in chrome://indexeddb-internals/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use FILE_PATH_LITERAL Created 7 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
OLDNEW
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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 origins.push_back(*iter); 121 origins.push_back(*iter);
122 } 122 }
123 return origins; 123 return origins;
124 } 124 }
125 125
126 std::vector<IndexedDBInfo> IndexedDBContextImpl::GetAllOriginsInfo() { 126 std::vector<IndexedDBInfo> IndexedDBContextImpl::GetAllOriginsInfo() {
127 std::vector<GURL> origins = GetAllOrigins(); 127 std::vector<GURL> origins = GetAllOrigins();
128 std::vector<IndexedDBInfo> result; 128 std::vector<IndexedDBInfo> result;
129 for (std::vector<GURL>::const_iterator iter = origins.begin(); 129 for (std::vector<GURL>::const_iterator iter = origins.begin();
130 iter != origins.end(); ++iter) { 130 iter != origins.end(); ++iter) {
131 const GURL& origin = *iter; 131 const GURL& origin_url = *iter;
132 132
133 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin); 133 base::FilePath idb_directory = GetFilePath(origin_url);
134 base::FilePath idb_directory = GetIndexedDBFilePath(origin_id); 134 result.push_back(IndexedDBInfo(origin_url,
135 result.push_back(IndexedDBInfo(origin, 135 GetOriginDiskUsage(origin_url),
136 GetOriginDiskUsage(origin), 136 GetOriginLastModified(origin_url),
137 GetOriginLastModified(origin),
138 idb_directory)); 137 idb_directory));
139 } 138 }
140 return result; 139 return result;
141 } 140 }
142 141
143 int64 IndexedDBContextImpl::GetOriginDiskUsage(const GURL& origin_url) { 142 int64 IndexedDBContextImpl::GetOriginDiskUsage(const GURL& origin_url) {
144 if (data_path_.empty() || !IsInOriginSet(origin_url)) 143 if (data_path_.empty() || !IsInOriginSet(origin_url))
145 return 0; 144 return 0;
146 EnsureDiskUsageCacheInitialized(origin_url); 145 EnsureDiskUsageCacheInitialized(origin_url);
147 return origin_size_map_[origin_url]; 146 return origin_size_map_[origin_url];
148 } 147 }
149 148
150 base::Time IndexedDBContextImpl::GetOriginLastModified(const GURL& origin_url) { 149 base::Time IndexedDBContextImpl::GetOriginLastModified(const GURL& origin_url) {
151 if (data_path_.empty() || !IsInOriginSet(origin_url)) 150 if (data_path_.empty() || !IsInOriginSet(origin_url))
152 return base::Time(); 151 return base::Time();
153 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url); 152 base::FilePath idb_directory = GetFilePath(origin_url);
154 base::FilePath idb_directory = GetIndexedDBFilePath(origin_id);
155 base::PlatformFileInfo file_info; 153 base::PlatformFileInfo file_info;
156 if (!file_util::GetFileInfo(idb_directory, &file_info)) 154 if (!file_util::GetFileInfo(idb_directory, &file_info))
157 return base::Time(); 155 return base::Time();
158 return file_info.last_modified; 156 return file_info.last_modified;
159 } 157 }
160 158
161 void IndexedDBContextImpl::DeleteForOrigin(const GURL& origin_url) { 159 void IndexedDBContextImpl::DeleteForOrigin(const GURL& origin_url) {
162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
161 ForceClose(origin_url);
162 if (data_path_.empty() || !IsInOriginSet(origin_url))
163 return;
164
165 base::FilePath idb_directory = GetFilePath(origin_url);
166 EnsureDiskUsageCacheInitialized(origin_url);
167 const bool recursive = true;
168 bool deleted = file_util::Delete(idb_directory, recursive);
169
170 QueryDiskAndUpdateQuotaUsage(origin_url);
171 if (deleted) {
172 RemoveFromOriginSet(origin_url);
173 origin_size_map_.erase(origin_url);
174 space_available_map_.erase(origin_url);
175 }
176 }
177
178 void IndexedDBContextImpl::ForceClose(const GURL& origin_url) {
179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
163 if (data_path_.empty() || !IsInOriginSet(origin_url)) 180 if (data_path_.empty() || !IsInOriginSet(origin_url))
164 return; 181 return;
165 182
166 if (connections_.find(origin_url) != connections_.end()) { 183 if (connections_.find(origin_url) != connections_.end()) {
167 ConnectionSet& connections = connections_[origin_url]; 184 ConnectionSet& connections = connections_[origin_url];
168 ConnectionSet::iterator it = connections.begin(); 185 ConnectionSet::iterator it = connections.begin();
169 while (it != connections.end()) { 186 while (it != connections.end()) {
170 // Remove before closing so callbacks don't double-erase 187 // Remove before closing so callbacks don't double-erase
171 WebKit::WebIDBDatabase* db = *it; 188 WebKit::WebIDBDatabase* db = *it;
172 connections.erase(it++); 189 connections.erase(it++);
173 db->forceClose(); 190 db->forceClose();
174 } 191 }
175 DCHECK(connections_[origin_url].size() == 0); 192 DCHECK_EQ(connections_[origin_url].size(), 0UL);
176 connections_.erase(origin_url); 193 connections_.erase(origin_url);
177 } 194 }
178
179 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url);
180 base::FilePath idb_directory = GetIndexedDBFilePath(origin_id);
181 EnsureDiskUsageCacheInitialized(origin_url);
182 const bool recursive = true;
183 bool deleted = file_util::Delete(idb_directory, recursive);
184
185 QueryDiskAndUpdateQuotaUsage(origin_url);
186 if (deleted) {
187 RemoveFromOriginSet(origin_url);
188 origin_size_map_.erase(origin_url);
189 space_available_map_.erase(origin_url);
190 }
191 } 195 }
192 196
197 base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) {
198 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url);
199 return GetIndexedDBFilePath(origin_id);
200 }
201
193 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( 202 base::FilePath IndexedDBContextImpl::GetFilePathForTesting(
194 const string16& origin_id) const { 203 const string16& origin_id) const {
195 return GetIndexedDBFilePath(origin_id); 204 return GetIndexedDBFilePath(origin_id);
196 } 205 }
197 206
198 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, 207 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url,
199 WebIDBDatabase* connection) { 208 WebIDBDatabase* connection) {
200 DCHECK(connections_[origin_url].count(connection) == 0); 209 DCHECK_EQ(connections_[origin_url].count(connection), 0UL);
201 if (quota_manager_proxy()) { 210 if (quota_manager_proxy()) {
202 quota_manager_proxy()->NotifyStorageAccessed( 211 quota_manager_proxy()->NotifyStorageAccessed(
203 quota::QuotaClient::kIndexedDatabase, origin_url, 212 quota::QuotaClient::kIndexedDatabase, origin_url,
204 quota::kStorageTypeTemporary); 213 quota::kStorageTypeTemporary);
205 } 214 }
206 connections_[origin_url].insert(connection); 215 connections_[origin_url].insert(connection);
207 if (AddToOriginSet(origin_url)) { 216 if (AddToOriginSet(origin_url)) {
208 // A newly created db, notify the quota system. 217 // A newly created db, notify the quota system.
209 QueryDiskAndUpdateQuotaUsage(origin_url); 218 QueryDiskAndUpdateQuotaUsage(origin_url);
210 } else { 219 } else {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 return origin_set_.get(); 391 return origin_set_.get();
383 } 392 }
384 393
385 void IndexedDBContextImpl::ResetCaches() { 394 void IndexedDBContextImpl::ResetCaches() {
386 origin_set_.reset(); 395 origin_set_.reset();
387 origin_size_map_.clear(); 396 origin_size_map_.clear();
388 space_available_map_.clear(); 397 space_available_map_.clear();
389 } 398 }
390 399
391 } // namespace content 400 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_context_impl.h ('k') | content/browser/indexed_db/indexed_db_internals_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698