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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_store_file.cc

Issue 910953002: Move SafeBrowsing to the blocking pool via an experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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 "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
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 scoped_refptr<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;
gab 2015/02/19 14:38:23 No need to do this, just have a commented out: //
Alexei Svitkine (slow) 2015/02/20 15:42:44 The issue is that Close() has that check.
563 568
564 Close(); 569 Close();
565 } 570 }
566 571
572 bool SafeBrowsingStoreFile::CalledOnValidThread() {
573 return !task_runner_ || task_runner_->RunsTasksOnCurrentThread();
gab 2015/02/19 14:38:23 You can get rid of this I think and just inline D
Alexei Svitkine (slow) 2015/02/20 15:42:44 I prefer keeping it a separate method, which doesn
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698