OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/dom_storage/session_storage_database.h" | 5 #include "content/browser/dom_storage/session_storage_database.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 229 } |
230 DBOperation operation(this); | 230 DBOperation operation(this); |
231 leveldb::WriteBatch batch; | 231 leveldb::WriteBatch batch; |
232 if (!DeleteAreaHelper(namespace_id, origin.spec(), &batch)) | 232 if (!DeleteAreaHelper(namespace_id, origin.spec(), &batch)) |
233 return false; | 233 return false; |
234 leveldb::Status s = db_->Write(leveldb::WriteOptions(), &batch); | 234 leveldb::Status s = db_->Write(leveldb::WriteOptions(), &batch); |
235 return DatabaseErrorCheck(s.ok()); | 235 return DatabaseErrorCheck(s.ok()); |
236 } | 236 } |
237 | 237 |
238 bool SessionStorageDatabase::DeleteNamespace(const std::string& namespace_id) { | 238 bool SessionStorageDatabase::DeleteNamespace(const std::string& namespace_id) { |
239 if (!LazyOpen(false)) { | 239 { |
240 // No need to create the database if it doesn't exist. | 240 // The caller should have called other methods to open the DB before this |
241 return true; | 241 // function. Otherwise, DB stores nothing interesting related to the |
| 242 // specified namespace. |
| 243 // Do nothing if the DB is not open (or we know it has failed already), |
| 244 base::AutoLock auto_lock(db_lock_); |
| 245 if (!IsOpen() || db_error_ || is_inconsistent_) |
| 246 return false; |
242 } | 247 } |
243 DBOperation operation(this); | 248 DBOperation operation(this); |
244 // Itereate through the areas in the namespace. | 249 // Itereate through the areas in the namespace. |
245 leveldb::WriteBatch batch; | 250 leveldb::WriteBatch batch; |
246 std::map<std::string, std::string> areas; | 251 std::map<std::string, std::string> areas; |
247 if (!GetAreasInNamespace(namespace_id, &areas)) | 252 if (!GetAreasInNamespace(namespace_id, &areas)) |
248 return false; | 253 return false; |
249 for (std::map<std::string, std::string>::const_iterator it = areas.begin(); | 254 for (std::map<std::string, std::string>::const_iterator it = areas.begin(); |
250 it != areas.end(); ++it) { | 255 it != areas.end(); ++it) { |
251 const std::string& origin = it->first; | 256 const std::string& origin = it->first; |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 std::string SessionStorageDatabase::MapKey(const std::string& map_id, | 725 std::string SessionStorageDatabase::MapKey(const std::string& map_id, |
721 const std::string& key) { | 726 const std::string& key) { |
722 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); | 727 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); |
723 } | 728 } |
724 | 729 |
725 const char* SessionStorageDatabase::NextMapIdKey() { | 730 const char* SessionStorageDatabase::NextMapIdKey() { |
726 return "next-map-id"; | 731 return "next-map-id"; |
727 } | 732 } |
728 | 733 |
729 } // namespace content | 734 } // namespace content |
OLD | NEW |