| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/service_worker/service_worker_database.h" | 5 #include "content/browser/service_worker/service_worker_database.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 bool ServiceWorkerDatabase::WritePurgeableResourceIds( | 492 bool ServiceWorkerDatabase::WritePurgeableResourceIds( |
| 493 const std::set<int64>& ids) { | 493 const std::set<int64>& ids) { |
| 494 return WriteResourceIds(kPurgeableResIdKeyPrefix, ids); | 494 return WriteResourceIds(kPurgeableResIdKeyPrefix, ids); |
| 495 } | 495 } |
| 496 | 496 |
| 497 bool ServiceWorkerDatabase::ClearPurgeableResourceIds( | 497 bool ServiceWorkerDatabase::ClearPurgeableResourceIds( |
| 498 const std::set<int64>& ids) { | 498 const std::set<int64>& ids) { |
| 499 return DeleteResourceIds(kPurgeableResIdKeyPrefix, ids); | 499 return DeleteResourceIds(kPurgeableResIdKeyPrefix, ids); |
| 500 } | 500 } |
| 501 | 501 |
| 502 bool ServiceWorkerDatabase::DeleteAllDataForOrigin(const GURL& origin) { |
| 503 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 504 if (!LazyOpen(true) || is_disabled_ || !origin.is_valid()) |
| 505 return false; |
| 506 |
| 507 leveldb::WriteBatch batch; |
| 508 |
| 509 // Delete from the unique origin list. |
| 510 batch.Delete(CreateUniqueOriginKey(origin)); |
| 511 |
| 512 std::vector<RegistrationData> registrations; |
| 513 if (!GetRegistrationsForOrigin(origin, ®istrations)) |
| 514 return false; |
| 515 |
| 516 // Delete registrations and resource records. |
| 517 for (std::vector<RegistrationData>::const_iterator itr = |
| 518 registrations.begin(); itr != registrations.end(); ++itr) { |
| 519 batch.Delete(CreateRegistrationKey(itr->registration_id, origin)); |
| 520 if (!DeleteResourceRecords(itr->version_id, &batch)) |
| 521 return false; |
| 522 } |
| 523 |
| 524 return WriteBatch(&batch); |
| 525 } |
| 526 |
| 502 bool ServiceWorkerDatabase::LazyOpen(bool create_if_needed) { | 527 bool ServiceWorkerDatabase::LazyOpen(bool create_if_needed) { |
| 503 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 528 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 504 if (IsOpen()) | 529 if (IsOpen()) |
| 505 return true; | 530 return true; |
| 506 | 531 |
| 507 // Do not try to open a database if we tried and failed once. | 532 // Do not try to open a database if we tried and failed once. |
| 508 if (is_disabled_) | 533 if (is_disabled_) |
| 509 return false; | 534 return false; |
| 510 | 535 |
| 511 // When |path_| is empty, open a database in-memory. | 536 // When |path_| is empty, open a database in-memory. |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 // TODO(nhiroki): Add an UMA histogram. | 832 // TODO(nhiroki): Add an UMA histogram. |
| 808 DLOG(ERROR) << "Failed at: " << from_here.ToString() | 833 DLOG(ERROR) << "Failed at: " << from_here.ToString() |
| 809 << " with error: " << status.ToString(); | 834 << " with error: " << status.ToString(); |
| 810 is_disabled_ = true; | 835 is_disabled_ = true; |
| 811 if (status.IsCorruption()) | 836 if (status.IsCorruption()) |
| 812 was_corruption_detected_ = true; | 837 was_corruption_detected_ = true; |
| 813 db_.reset(); | 838 db_.reset(); |
| 814 } | 839 } |
| 815 | 840 |
| 816 } // namespace content | 841 } // namespace content |
| OLD | NEW |