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

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

Issue 19610: Safe browsing cleanup:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_database.h" 5 #include "chrome/browser/safe_browsing/safe_browsing_database.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/sha2.h" 10 #include "base/sha2.h"
11 #include "chrome/browser/safe_browsing/safe_browsing_database_impl.h" 11 #include "chrome/browser/safe_browsing/safe_browsing_database_impl.h"
12 #include "chrome/browser/safe_browsing/safe_browsing_database_bloom.h" 12 #include "chrome/browser/safe_browsing/safe_browsing_database_bloom.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
15 15
16 using base::Time; 16 using base::Time;
17 17
18 // Filename suffix for the bloom filter. 18 // Filename suffix for the bloom filter.
19 static const wchar_t kBloomFilterFile[] = L" Filter"; 19 static const FilePath::CharType kBloomFilterFile[] =
20 FILE_PATH_LITERAL(" Filter");
20 21
21 // Factory method. 22 // Factory method.
22 SafeBrowsingDatabase* SafeBrowsingDatabase::Create() { 23 SafeBrowsingDatabase* SafeBrowsingDatabase::Create() {
23 if (CommandLine::ForCurrentProcess()->HasSwitch( 24 if (CommandLine::ForCurrentProcess()->HasSwitch(
24 switches::kUseOldSafeBrowsing)) { 25 switches::kUseOldSafeBrowsing)) {
25 return new SafeBrowsingDatabaseImpl; 26 return new SafeBrowsingDatabaseImpl;
26 } 27 }
27 return new SafeBrowsingDatabaseBloom; 28 return new SafeBrowsingDatabaseBloom;
28 } 29 }
29 30
(...skipping 23 matching lines...) Expand all
53 54
54 if (hosts.size() > 1) { 55 if (hosts.size() > 1) {
55 base::SHA256HashString(hosts[1] + "/", &host_key, sizeof(SBPrefix)); 56 base::SHA256HashString(hosts[1] + "/", &host_key, sizeof(SBPrefix));
56 if (filter->Exists(host_key)) 57 if (filter->Exists(host_key))
57 return true; 58 return true;
58 } 59 }
59 } 60 }
60 return false; 61 return false;
61 } 62 }
62 63
63 std::wstring SafeBrowsingDatabase::BloomFilterFilename( 64 // static
64 const std::wstring& db_filename) { 65 FilePath SafeBrowsingDatabase::BloomFilterFilename(
65 return db_filename + kBloomFilterFile; 66 const FilePath& db_filename) {
67 return FilePath(db_filename.value() + kBloomFilterFile);
66 } 68 }
67 69
68 void SafeBrowsingDatabase::LoadBloomFilter() { 70 void SafeBrowsingDatabase::LoadBloomFilter() {
69 DCHECK(!bloom_filter_filename_.empty()); 71 DCHECK(!bloom_filter_filename_.empty());
70 72
71 int64 size_64; 73 int64 size_64;
72 if (!file_util::GetFileSize(bloom_filter_filename_, &size_64) || 74 if (!file_util::GetFileSize(bloom_filter_filename_, &size_64) ||
73 size_64 == 0) { 75 size_64 == 0) {
74 BuildBloomFilter(); 76 BuildBloomFilter();
75 return; 77 return;
(...skipping 19 matching lines...) Expand all
95 if (!bloom_filter_.get()) 97 if (!bloom_filter_.get())
96 return; 98 return;
97 99
98 Time before = Time::Now(); 100 Time before = Time::Now();
99 file_util::WriteFile(bloom_filter_filename_, 101 file_util::WriteFile(bloom_filter_filename_,
100 bloom_filter_->data(), 102 bloom_filter_->data(),
101 bloom_filter_->size()); 103 bloom_filter_->size());
102 SB_DLOG(INFO) << "SafeBrowsingDatabase wrote bloom filter in " << 104 SB_DLOG(INFO) << "SafeBrowsingDatabase wrote bloom filter in " <<
103 (Time::Now() - before).InMilliseconds() << " ms"; 105 (Time::Now() - before).InMilliseconds() << " ms";
104 } 106 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_database.h ('k') | chrome/browser/safe_browsing/safe_browsing_database_bloom.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698