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_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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 WebKit::WebString origin_id_webstring = | 54 WebKit::WebString origin_id_webstring = |
55 webkit_glue::FilePathToWebString(file_path.BaseName()); | 55 webkit_glue::FilePathToWebString(file_path.BaseName()); |
56 origins->push_back( | 56 origins->push_back( |
57 DatabaseUtil::GetOriginFromIdentifier(origin_id_webstring)); | 57 DatabaseUtil::GetOriginFromIdentifier(origin_id_webstring)); |
58 if (file_paths) | 58 if (file_paths) |
59 file_paths->push_back(file_path); | 59 file_paths->push_back(file_path); |
60 } | 60 } |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 // If clear_all_databases is true, deletes all databases not protected by | 64 // Deletes session-only databases. |
65 // special storage policy. Otherwise deletes session-only databases. | 65 void ClearSessionOnlyOrigins( |
66 void ClearLocalState( | |
67 const FilePath& indexeddb_path, | 66 const FilePath& indexeddb_path, |
68 bool clear_all_databases, | |
69 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { | 67 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { |
70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
71 std::vector<GURL> origins; | 69 std::vector<GURL> origins; |
72 std::vector<FilePath> file_paths; | 70 std::vector<FilePath> file_paths; |
73 GetAllOriginsAndPaths(indexeddb_path, &origins, &file_paths); | 71 GetAllOriginsAndPaths(indexeddb_path, &origins, &file_paths); |
74 DCHECK_EQ(origins.size(), file_paths.size()); | 72 DCHECK_EQ(origins.size(), file_paths.size()); |
75 std::vector<FilePath>::const_iterator file_path_iter = file_paths.begin(); | 73 std::vector<FilePath>::const_iterator file_path_iter = file_paths.begin(); |
76 for (std::vector<GURL>::const_iterator iter = origins.begin(); | 74 for (std::vector<GURL>::const_iterator iter = origins.begin(); |
77 iter != origins.end(); ++iter, ++file_path_iter) { | 75 iter != origins.end(); ++iter, ++file_path_iter) { |
78 if (!clear_all_databases && | 76 if (!special_storage_policy->IsStorageSessionOnly(*iter)) |
79 !special_storage_policy->IsStorageSessionOnly(*iter)) { | |
80 continue; | 77 continue; |
81 } | 78 if (special_storage_policy->IsStorageProtected(*iter)) |
82 if (special_storage_policy.get() && | |
83 special_storage_policy->IsStorageProtected(*iter)) | |
84 continue; | 79 continue; |
85 file_util::Delete(*file_path_iter, true); | 80 file_util::Delete(*file_path_iter, true); |
86 } | 81 } |
87 } | 82 } |
88 | 83 |
89 } // namespace | 84 } // namespace |
90 | 85 |
91 IndexedDBContextImpl::IndexedDBContextImpl( | 86 IndexedDBContextImpl::IndexedDBContextImpl( |
92 const FilePath& data_path, | 87 const FilePath& data_path, |
93 quota::SpecialStoragePolicy* special_storage_policy, | 88 quota::SpecialStoragePolicy* special_storage_policy, |
94 quota::QuotaManagerProxy* quota_manager_proxy, | 89 quota::QuotaManagerProxy* quota_manager_proxy, |
95 base::MessageLoopProxy* webkit_thread_loop) | 90 base::MessageLoopProxy* webkit_thread_loop) |
96 : clear_local_state_on_exit_(false), | 91 : force_keep_session_state_(false), |
97 save_session_state_(false), | |
98 special_storage_policy_(special_storage_policy), | 92 special_storage_policy_(special_storage_policy), |
99 quota_manager_proxy_(quota_manager_proxy) { | 93 quota_manager_proxy_(quota_manager_proxy) { |
100 if (!data_path.empty()) | 94 if (!data_path.empty()) |
101 data_path_ = data_path.Append(kIndexedDBDirectory); | 95 data_path_ = data_path.Append(kIndexedDBDirectory); |
102 if (quota_manager_proxy && | 96 if (quota_manager_proxy && |
103 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) { | 97 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) { |
104 quota_manager_proxy->RegisterClient( | 98 quota_manager_proxy->RegisterClient( |
105 new IndexedDBQuotaClient(webkit_thread_loop, this)); | 99 new IndexedDBQuotaClient(webkit_thread_loop, this)); |
106 } | 100 } |
107 } | 101 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 WebKit::WebIDBFactory* factory = idb_factory_.release(); | 224 WebKit::WebIDBFactory* factory = idb_factory_.release(); |
231 if (factory) { | 225 if (factory) { |
232 if (!BrowserThread::DeleteSoon(BrowserThread::WEBKIT_DEPRECATED, | 226 if (!BrowserThread::DeleteSoon(BrowserThread::WEBKIT_DEPRECATED, |
233 FROM_HERE, factory)) | 227 FROM_HERE, factory)) |
234 delete factory; | 228 delete factory; |
235 } | 229 } |
236 | 230 |
237 if (data_path_.empty()) | 231 if (data_path_.empty()) |
238 return; | 232 return; |
239 | 233 |
240 if (save_session_state_) | 234 if (force_keep_session_state_) |
241 return; | 235 return; |
242 | 236 |
243 bool has_session_only_databases = | 237 bool has_session_only_databases = |
244 special_storage_policy_.get() && | 238 special_storage_policy_.get() && |
245 special_storage_policy_->HasSessionOnlyOrigins(); | 239 special_storage_policy_->HasSessionOnlyOrigins(); |
246 | 240 |
247 // Clearning only session-only databases, and there are none. | 241 // Clearning only session-only databases, and there are none. |
248 if (!clear_local_state_on_exit_ && !has_session_only_databases) | 242 if (!has_session_only_databases) |
249 return; | 243 return; |
250 | 244 |
251 // No WEBKIT thread here means we are running in a unit test where no clean | 245 // No WEBKIT thread here means we are running in a unit test where no clean |
252 // up is needed. | 246 // up is needed. |
253 BrowserThread::PostTask( | 247 BrowserThread::PostTask( |
254 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 248 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
255 base::Bind(&ClearLocalState, data_path_, clear_local_state_on_exit_, | 249 base::Bind(&ClearSessionOnlyOrigins, |
| 250 data_path_, |
256 special_storage_policy_)); | 251 special_storage_policy_)); |
257 } | 252 } |
258 | 253 |
259 FilePath IndexedDBContextImpl::GetIndexedDBFilePath( | 254 FilePath IndexedDBContextImpl::GetIndexedDBFilePath( |
260 const string16& origin_id) const { | 255 const string16& origin_id) const { |
261 DCHECK(!data_path_.empty()); | 256 DCHECK(!data_path_.empty()); |
262 FilePath::StringType id = | 257 FilePath::StringType id = |
263 webkit_glue::WebStringToFilePathString(origin_id).append( | 258 webkit_glue::WebStringToFilePathString(origin_id).append( |
264 FILE_PATH_LITERAL(".indexeddb")); | 259 FILE_PATH_LITERAL(".indexeddb")); |
265 return data_path_.Append(id.append(kIndexedDBExtension)); | 260 return data_path_.Append(id.append(kIndexedDBExtension)); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 } | 343 } |
349 } | 344 } |
350 return origin_set_.get(); | 345 return origin_set_.get(); |
351 } | 346 } |
352 | 347 |
353 void IndexedDBContextImpl::ResetCaches() { | 348 void IndexedDBContextImpl::ResetCaches() { |
354 origin_set_.reset(); | 349 origin_set_.reset(); |
355 origin_size_map_.clear(); | 350 origin_size_map_.clear(); |
356 space_available_map_.clear(); | 351 space_available_map_.clear(); |
357 } | 352 } |
OLD | NEW |