| 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 "chrome/browser/safe_browsing/safe_browsing_store_file.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/files/scoped_file.h" | 8 #include "base/files/scoped_file.h" |
| 9 #include "base/md5.h" | 9 #include "base/md5.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 | 547 |
| 548 int64 size = 0; | 548 int64 size = 0; |
| 549 if (!base::GetFileSize(filename, &size)) | 549 if (!base::GetFileSize(filename, &size)) |
| 550 return false; | 550 return false; |
| 551 | 551 |
| 552 return static_cast<int64>(ftell(file.get())) == size; | 552 return static_cast<int64>(ftell(file.get())) == size; |
| 553 } | 553 } |
| 554 | 554 |
| 555 } // namespace | 555 } // namespace |
| 556 | 556 |
| 557 SafeBrowsingStoreFile::SafeBrowsingStoreFile() | 557 SafeBrowsingStoreFile::SafeBrowsingStoreFile( |
| 558 : chunks_written_(0), empty_(false), corruption_seen_(false) {} | 558 const scoped_refptr<const base::SequencedTaskRunner>& task_runner) |
| 559 : task_runner_(task_runner), |
| 560 chunks_written_(0), |
| 561 empty_(false), |
| 562 corruption_seen_(false) { |
| 563 } |
| 559 | 564 |
| 560 SafeBrowsingStoreFile::~SafeBrowsingStoreFile() { | 565 SafeBrowsingStoreFile::~SafeBrowsingStoreFile() { |
| 561 // Thread-checking is disabled in the destructor due to crbug.com/338486. | 566 // Thread-checking is disabled in the destructor due to crbug.com/338486. |
| 562 DetachFromThread(); | 567 task_runner_ = nullptr; |
| 563 | 568 |
| 564 Close(); | 569 Close(); |
| 565 } | 570 } |
| 566 | 571 |
| 572 bool SafeBrowsingStoreFile::CalledOnValidThread() { |
| 573 return !task_runner_ || task_runner_->RunsTasksOnCurrentThread(); |
| 574 } |
| 575 |
| 567 bool SafeBrowsingStoreFile::Delete() { | 576 bool SafeBrowsingStoreFile::Delete() { |
| 568 DCHECK(CalledOnValidThread()); | 577 DCHECK(CalledOnValidThread()); |
| 569 | 578 |
| 570 // The database should not be open at this point. But, just in | 579 // The database should not be open at this point. But, just in |
| 571 // case, close everything before deleting. | 580 // case, close everything before deleting. |
| 572 if (!Close()) { | 581 if (!Close()) { |
| 573 NOTREACHED(); | 582 NOTREACHED(); |
| 574 return false; | 583 return false; |
| 575 } | 584 } |
| 576 | 585 |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 // With SQLite support gone, one way to get to this code is if the | 1155 // With SQLite support gone, one way to get to this code is if the |
| 1147 // existing file is a SQLite file. Make sure the journal file is | 1156 // existing file is a SQLite file. Make sure the journal file is |
| 1148 // also removed. | 1157 // also removed. |
| 1149 const base::FilePath journal_filename( | 1158 const base::FilePath journal_filename( |
| 1150 basename.value() + FILE_PATH_LITERAL("-journal")); | 1159 basename.value() + FILE_PATH_LITERAL("-journal")); |
| 1151 if (base::PathExists(journal_filename)) | 1160 if (base::PathExists(journal_filename)) |
| 1152 base::DeleteFile(journal_filename, false); | 1161 base::DeleteFile(journal_filename, false); |
| 1153 | 1162 |
| 1154 return true; | 1163 return true; |
| 1155 } | 1164 } |
| OLD | NEW |