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

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

Issue 12213066: Use base namespace for FilePath in content/browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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/in_process_webkit/indexed_db_context_impl.h" 5 #include "content/browser/in_process_webkit/indexed_db_context_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 12 matching lines...) Expand all
23 #include "webkit/database/database_util.h" 23 #include "webkit/database/database_util.h"
24 #include "webkit/quota/quota_manager.h" 24 #include "webkit/quota/quota_manager.h"
25 #include "webkit/quota/special_storage_policy.h" 25 #include "webkit/quota/special_storage_policy.h"
26 26
27 using webkit_database::DatabaseUtil; 27 using webkit_database::DatabaseUtil;
28 using WebKit::WebIDBDatabase; 28 using WebKit::WebIDBDatabase;
29 using WebKit::WebIDBFactory; 29 using WebKit::WebIDBFactory;
30 using WebKit::WebSecurityOrigin; 30 using WebKit::WebSecurityOrigin;
31 31
32 namespace content { 32 namespace content {
33 const FilePath::CharType IndexedDBContextImpl::kIndexedDBDirectory[] = 33 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBDirectory[] =
34 FILE_PATH_LITERAL("IndexedDB"); 34 FILE_PATH_LITERAL("IndexedDB");
35 35
36 const FilePath::CharType IndexedDBContextImpl::kIndexedDBExtension[] = 36 const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBExtension[] =
37 FILE_PATH_LITERAL(".leveldb"); 37 FILE_PATH_LITERAL(".leveldb");
38 38
39 namespace { 39 namespace {
40 40
41 void GetAllOriginsAndPaths( 41 void GetAllOriginsAndPaths(
42 const FilePath& indexeddb_path, 42 const base::FilePath& indexeddb_path,
43 std::vector<GURL>* origins, 43 std::vector<GURL>* origins,
44 std::vector<FilePath>* file_paths) { 44 std::vector<base::FilePath>* file_paths) {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
46 if (indexeddb_path.empty()) 46 if (indexeddb_path.empty())
47 return; 47 return;
48 file_util::FileEnumerator file_enumerator(indexeddb_path, 48 file_util::FileEnumerator file_enumerator(indexeddb_path,
49 false, file_util::FileEnumerator::DIRECTORIES); 49 false, file_util::FileEnumerator::DIRECTORIES);
50 for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); 50 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty();
51 file_path = file_enumerator.Next()) { 51 file_path = file_enumerator.Next()) {
52 if (file_path.Extension() == IndexedDBContextImpl::kIndexedDBExtension) { 52 if (file_path.Extension() == IndexedDBContextImpl::kIndexedDBExtension) {
53 WebKit::WebString origin_id_webstring = 53 WebKit::WebString origin_id_webstring =
54 webkit_base::FilePathToWebString(file_path.BaseName()); 54 webkit_base::FilePathToWebString(file_path.BaseName());
55 origins->push_back( 55 origins->push_back(
56 DatabaseUtil::GetOriginFromIdentifier(origin_id_webstring)); 56 DatabaseUtil::GetOriginFromIdentifier(origin_id_webstring));
57 if (file_paths) 57 if (file_paths)
58 file_paths->push_back(file_path); 58 file_paths->push_back(file_path);
59 } 59 }
60 } 60 }
61 } 61 }
62 62
63 // Deletes session-only databases. 63 // Deletes session-only databases.
64 void ClearSessionOnlyOrigins( 64 void ClearSessionOnlyOrigins(
65 const FilePath& indexeddb_path, 65 const base::FilePath& indexeddb_path,
66 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { 66 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) {
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
68 std::vector<GURL> origins; 68 std::vector<GURL> origins;
69 std::vector<FilePath> file_paths; 69 std::vector<base::FilePath> file_paths;
70 GetAllOriginsAndPaths(indexeddb_path, &origins, &file_paths); 70 GetAllOriginsAndPaths(indexeddb_path, &origins, &file_paths);
71 DCHECK_EQ(origins.size(), file_paths.size()); 71 DCHECK_EQ(origins.size(), file_paths.size());
72 std::vector<FilePath>::const_iterator file_path_iter = file_paths.begin(); 72 std::vector<base::FilePath>::const_iterator file_path_iter =
73 file_paths.begin();
73 for (std::vector<GURL>::const_iterator iter = origins.begin(); 74 for (std::vector<GURL>::const_iterator iter = origins.begin();
74 iter != origins.end(); ++iter, ++file_path_iter) { 75 iter != origins.end(); ++iter, ++file_path_iter) {
75 if (!special_storage_policy->IsStorageSessionOnly(*iter)) 76 if (!special_storage_policy->IsStorageSessionOnly(*iter))
76 continue; 77 continue;
77 if (special_storage_policy->IsStorageProtected(*iter)) 78 if (special_storage_policy->IsStorageProtected(*iter))
78 continue; 79 continue;
79 file_util::Delete(*file_path_iter, true); 80 file_util::Delete(*file_path_iter, true);
80 } 81 }
81 } 82 }
82 83
83 } // namespace 84 } // namespace
84 85
85 IndexedDBContextImpl::IndexedDBContextImpl( 86 IndexedDBContextImpl::IndexedDBContextImpl(
86 const FilePath& data_path, 87 const base::FilePath& data_path,
87 quota::SpecialStoragePolicy* special_storage_policy, 88 quota::SpecialStoragePolicy* special_storage_policy,
88 quota::QuotaManagerProxy* quota_manager_proxy, 89 quota::QuotaManagerProxy* quota_manager_proxy,
89 base::MessageLoopProxy* webkit_thread_loop) 90 base::MessageLoopProxy* webkit_thread_loop)
90 : force_keep_session_state_(false), 91 : force_keep_session_state_(false),
91 special_storage_policy_(special_storage_policy), 92 special_storage_policy_(special_storage_policy),
92 quota_manager_proxy_(quota_manager_proxy) { 93 quota_manager_proxy_(quota_manager_proxy) {
93 if (!data_path.empty()) 94 if (!data_path.empty())
94 data_path_ = data_path.Append(kIndexedDBDirectory); 95 data_path_ = data_path.Append(kIndexedDBDirectory);
95 if (quota_manager_proxy && 96 if (quota_manager_proxy &&
96 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) { 97 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) {
(...skipping 28 matching lines...) Expand all
125 if (data_path_.empty() || !IsInOriginSet(origin_url)) 126 if (data_path_.empty() || !IsInOriginSet(origin_url))
126 return 0; 127 return 0;
127 EnsureDiskUsageCacheInitialized(origin_url); 128 EnsureDiskUsageCacheInitialized(origin_url);
128 return origin_size_map_[origin_url]; 129 return origin_size_map_[origin_url];
129 } 130 }
130 131
131 base::Time IndexedDBContextImpl::GetOriginLastModified(const GURL& origin_url) { 132 base::Time IndexedDBContextImpl::GetOriginLastModified(const GURL& origin_url) {
132 if (data_path_.empty() || !IsInOriginSet(origin_url)) 133 if (data_path_.empty() || !IsInOriginSet(origin_url))
133 return base::Time(); 134 return base::Time();
134 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url); 135 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url);
135 FilePath idb_directory = GetIndexedDBFilePath(origin_id); 136 base::FilePath idb_directory = GetIndexedDBFilePath(origin_id);
136 base::PlatformFileInfo file_info; 137 base::PlatformFileInfo file_info;
137 if (!file_util::GetFileInfo(idb_directory, &file_info)) 138 if (!file_util::GetFileInfo(idb_directory, &file_info))
138 return base::Time(); 139 return base::Time();
139 return file_info.last_modified; 140 return file_info.last_modified;
140 } 141 }
141 142
142 void IndexedDBContextImpl::DeleteForOrigin(const GURL& origin_url) { 143 void IndexedDBContextImpl::DeleteForOrigin(const GURL& origin_url) {
143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
144 if (data_path_.empty() || !IsInOriginSet(origin_url)) 145 if (data_path_.empty() || !IsInOriginSet(origin_url))
145 return; 146 return;
146 147
147 if (connections_.find(origin_url) != connections_.end()) { 148 if (connections_.find(origin_url) != connections_.end()) {
148 ConnectionSet& connections = connections_[origin_url]; 149 ConnectionSet& connections = connections_[origin_url];
149 ConnectionSet::iterator it = connections.begin(); 150 ConnectionSet::iterator it = connections.begin();
150 while (it != connections.end()) { 151 while (it != connections.end()) {
151 // Remove before closing so callbacks don't double-erase 152 // Remove before closing so callbacks don't double-erase
152 WebKit::WebIDBDatabase* db = *it; 153 WebKit::WebIDBDatabase* db = *it;
153 connections.erase(it++); 154 connections.erase(it++);
154 db->forceClose(); 155 db->forceClose();
155 } 156 }
156 DCHECK(connections_[origin_url].size() == 0); 157 DCHECK(connections_[origin_url].size() == 0);
157 connections_.erase(origin_url); 158 connections_.erase(origin_url);
158 } 159 }
159 160
160 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url); 161 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url);
161 FilePath idb_directory = GetIndexedDBFilePath(origin_id); 162 base::FilePath idb_directory = GetIndexedDBFilePath(origin_id);
162 EnsureDiskUsageCacheInitialized(origin_url); 163 EnsureDiskUsageCacheInitialized(origin_url);
163 const bool recursive = true; 164 const bool recursive = true;
164 bool deleted = file_util::Delete(idb_directory, recursive); 165 bool deleted = file_util::Delete(idb_directory, recursive);
165 166
166 QueryDiskAndUpdateQuotaUsage(origin_url); 167 QueryDiskAndUpdateQuotaUsage(origin_url);
167 if (deleted) { 168 if (deleted) {
168 RemoveFromOriginSet(origin_url); 169 RemoveFromOriginSet(origin_url);
169 origin_size_map_.erase(origin_url); 170 origin_size_map_.erase(origin_url);
170 space_available_map_.erase(origin_url); 171 space_available_map_.erase(origin_url);
171 } 172 }
172 } 173 }
173 174
174 FilePath IndexedDBContextImpl::GetFilePathForTesting( 175 base::FilePath IndexedDBContextImpl::GetFilePathForTesting(
175 const string16& origin_id) const { 176 const string16& origin_id) const {
176 return GetIndexedDBFilePath(origin_id); 177 return GetIndexedDBFilePath(origin_id);
177 } 178 }
178 179
179 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url, 180 void IndexedDBContextImpl::ConnectionOpened(const GURL& origin_url,
180 WebIDBDatabase* connection) { 181 WebIDBDatabase* connection) {
181 DCHECK(connections_[origin_url].count(connection) == 0); 182 DCHECK(connections_[origin_url].count(connection) == 0);
182 if (quota_manager_proxy()) { 183 if (quota_manager_proxy()) {
183 quota_manager_proxy()->NotifyStorageAccessed( 184 quota_manager_proxy()->NotifyStorageAccessed(
184 quota::QuotaClient::kIndexedDatabase, origin_url, 185 quota::QuotaClient::kIndexedDatabase, origin_url,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 263
263 // No WEBKIT thread here means we are running in a unit test where no clean 264 // No WEBKIT thread here means we are running in a unit test where no clean
264 // up is needed. 265 // up is needed.
265 BrowserThread::PostTask( 266 BrowserThread::PostTask(
266 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, 267 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
267 base::Bind(&ClearSessionOnlyOrigins, 268 base::Bind(&ClearSessionOnlyOrigins,
268 data_path_, 269 data_path_,
269 special_storage_policy_)); 270 special_storage_policy_));
270 } 271 }
271 272
272 FilePath IndexedDBContextImpl::GetIndexedDBFilePath( 273 base::FilePath IndexedDBContextImpl::GetIndexedDBFilePath(
273 const string16& origin_id) const { 274 const string16& origin_id) const {
274 DCHECK(!data_path_.empty()); 275 DCHECK(!data_path_.empty());
275 FilePath::StringType id = 276 base::FilePath::StringType id =
276 webkit_base::WebStringToFilePathString(origin_id).append( 277 webkit_base::WebStringToFilePathString(origin_id).append(
277 FILE_PATH_LITERAL(".indexeddb")); 278 FILE_PATH_LITERAL(".indexeddb"));
278 return data_path_.Append(id.append(kIndexedDBExtension)); 279 return data_path_.Append(id.append(kIndexedDBExtension));
279 } 280 }
280 281
281 int64 IndexedDBContextImpl::ReadUsageFromDisk(const GURL& origin_url) const { 282 int64 IndexedDBContextImpl::ReadUsageFromDisk(const GURL& origin_url) const {
282 if (data_path_.empty()) 283 if (data_path_.empty())
283 return 0; 284 return 0;
284 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url); 285 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url);
285 FilePath file_path = GetIndexedDBFilePath(origin_id); 286 base::FilePath file_path = GetIndexedDBFilePath(origin_id);
286 return file_util::ComputeDirectorySize(file_path); 287 return file_util::ComputeDirectorySize(file_path);
287 } 288 }
288 289
289 void IndexedDBContextImpl::EnsureDiskUsageCacheInitialized( 290 void IndexedDBContextImpl::EnsureDiskUsageCacheInitialized(
290 const GURL& origin_url) { 291 const GURL& origin_url) {
291 if (origin_size_map_.find(origin_url) == origin_size_map_.end()) 292 if (origin_size_map_.find(origin_url) == origin_size_map_.end())
292 origin_size_map_[origin_url] = ReadUsageFromDisk(origin_url); 293 origin_size_map_[origin_url] = ReadUsageFromDisk(origin_url);
293 } 294 }
294 295
295 void IndexedDBContextImpl::QueryDiskAndUpdateQuotaUsage( 296 void IndexedDBContextImpl::QueryDiskAndUpdateQuotaUsage(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 return origin_set_.get(); 364 return origin_set_.get();
364 } 365 }
365 366
366 void IndexedDBContextImpl::ResetCaches() { 367 void IndexedDBContextImpl::ResetCaches() {
367 origin_set_.reset(); 368 origin_set_.reset();
368 origin_size_map_.clear(); 369 origin_size_map_.clear();
369 space_available_map_.clear(); 370 space_available_map_.clear();
370 } 371 }
371 372
372 } // namespace content 373 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698