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

Side by Side Diff: components/safe_browsing_db/v4_database.cc

Issue 2687023007: Revert of Browser tests for using the new SafeBrowsing protocol (v4) (Closed)
Patch Set: Created 3 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <memory> 5 #include <memory>
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/debug/leak_annotations.h" 8 #include "base/debug/leak_annotations.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "components/safe_browsing_db/v4_database.h" 13 #include "components/safe_browsing_db/v4_database.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 15
16 using content::BrowserThread; 16 using content::BrowserThread;
17 using base::TimeTicks; 17 using base::TimeTicks;
18 18
19 namespace safe_browsing { 19 namespace safe_browsing {
20 20
21 namespace { 21 namespace {
22 22
23 const char kV4DatabaseSizeMetric[] = "SafeBrowsing.V4Database.Size"; 23 const char kV4DatabaseSizeMetric[] = "SafeBrowsing.V4Database.Size";
24 24
25 } // namespace 25 } // namespace
26 26
27 // static 27 // static
28 std::unique_ptr<V4DatabaseFactory> V4Database::db_factory_; 28 V4StoreFactory* V4Database::factory_ = NULL;
29
30 // static
31 std::unique_ptr<V4StoreFactory> V4Database::store_factory_;
32
33 std::unique_ptr<V4Database> V4DatabaseFactory::Create(
34 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
35 std::unique_ptr<StoreMap> store_map) {
36 // Not using MakeUnique since the constructor of V4Database is protected.
37 return std::unique_ptr<V4Database>(
38 new V4Database(db_task_runner, std::move(store_map)));
39 }
40 29
41 // static 30 // static
42 void V4Database::Create( 31 void V4Database::Create(
43 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 32 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
44 const base::FilePath& base_path, 33 const base::FilePath& base_path,
45 const ListInfos& list_infos, 34 const ListInfos& list_infos,
46 NewDatabaseReadyCallback new_db_callback) { 35 NewDatabaseReadyCallback new_db_callback) {
47 DCHECK(base_path.IsAbsolute()); 36 DCHECK(base_path.IsAbsolute());
48 DCHECK(!list_infos.empty()); 37 DCHECK(!list_infos.empty());
49 38
50 const scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner = 39 const scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner =
51 base::ThreadTaskRunnerHandle::Get(); 40 base::ThreadTaskRunnerHandle::Get();
52 db_task_runner->PostTask( 41 db_task_runner->PostTask(
53 FROM_HERE, base::Bind(&V4Database::CreateOnTaskRunner, db_task_runner, 42 FROM_HERE, base::Bind(&V4Database::CreateOnTaskRunner, db_task_runner,
54 base_path, list_infos, callback_task_runner, 43 base_path, list_infos, callback_task_runner,
55 new_db_callback, TimeTicks::Now())); 44 new_db_callback, TimeTicks::Now()));
56 } 45 }
57 46
58 // static 47 // static
59 void V4Database::CreateOnTaskRunner( 48 void V4Database::CreateOnTaskRunner(
60 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 49 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
61 const base::FilePath& base_path, 50 const base::FilePath& base_path,
62 const ListInfos& list_infos, 51 const ListInfos& list_infos,
63 const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner, 52 const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner,
64 NewDatabaseReadyCallback new_db_callback, 53 NewDatabaseReadyCallback new_db_callback,
65 const TimeTicks create_start_time) { 54 const TimeTicks create_start_time) {
66 DCHECK(db_task_runner->RunsTasksOnCurrentThread()); 55 DCHECK(db_task_runner->RunsTasksOnCurrentThread());
67 56
68 if (!store_factory_) { 57 if (!factory_) {
69 store_factory_.reset(new V4StoreFactory()); 58 factory_ = new V4StoreFactory();
59 ANNOTATE_LEAKING_OBJECT_PTR(factory_);
70 } 60 }
71 61
72 if (!base::CreateDirectory(base_path)) { 62 if (!base::CreateDirectory(base_path)) {
73 NOTREACHED(); 63 NOTREACHED();
74 } 64 }
75 65
76 std::unique_ptr<StoreMap> store_map = base::MakeUnique<StoreMap>(); 66 std::unique_ptr<StoreMap> store_map = base::MakeUnique<StoreMap>();
77 for (const auto& it : list_infos) { 67 for (const auto& it : list_infos) {
78 if (!it.fetch_updates()) { 68 if (!it.fetch_updates()) {
79 // This list doesn't need to be fetched or stored on disk. 69 // This list doesn't need to be fetched or stored on disk.
80 continue; 70 continue;
81 } 71 }
82 72
83 const base::FilePath store_path = base_path.AppendASCII(it.filename()); 73 const base::FilePath store_path = base_path.AppendASCII(it.filename());
84 (*store_map)[it.list_id()].reset( 74 (*store_map)[it.list_id()].reset(
85 store_factory_->CreateV4Store(db_task_runner, store_path)); 75 factory_->CreateV4Store(db_task_runner, store_path));
86 }
87
88 if (!db_factory_) {
89 db_factory_.reset(new V4DatabaseFactory());
90 } 76 }
91 std::unique_ptr<V4Database> v4_database( 77 std::unique_ptr<V4Database> v4_database(
92 db_factory_->Create(db_task_runner, std::move(store_map))); 78 new V4Database(db_task_runner, std::move(store_map)));
93 79
94 // Database is done loading, pass it to the new_db_callback on the caller's 80 // Database is done loading, pass it to the new_db_callback on the caller's
95 // thread. This would unblock resource loads. 81 // thread. This would unblock resource loads.
96 callback_task_runner->PostTask( 82 callback_task_runner->PostTask(
97 FROM_HERE, base::Bind(new_db_callback, base::Passed(&v4_database))); 83 FROM_HERE, base::Bind(new_db_callback, base::Passed(&v4_database)));
98 84
99 UMA_HISTOGRAM_TIMES("SafeBrowsing.V4DatabaseOpen.Time", 85 UMA_HISTOGRAM_TIMES("SafeBrowsing.V4DatabaseOpen.Time",
100 TimeTicks::Now() - create_start_time); 86 TimeTicks::Now() - create_start_time);
101 } 87 }
102 88
103 V4Database::V4Database( 89 V4Database::V4Database(
104 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 90 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
105 std::unique_ptr<StoreMap> store_map) 91 std::unique_ptr<StoreMap> store_map)
106 : store_map_(std::move(store_map)), 92 : db_task_runner_(db_task_runner),
107 db_task_runner_(db_task_runner), 93 store_map_(std::move(store_map)),
108 pending_store_updates_(0), 94 pending_store_updates_(0),
109 weak_factory_on_io_(this) { 95 weak_factory_on_io_(this) {
110 DCHECK(db_task_runner->RunsTasksOnCurrentThread()); 96 DCHECK(db_task_runner->RunsTasksOnCurrentThread());
111 } 97 }
112 98
113 // static 99 // static
114 void V4Database::Destroy(std::unique_ptr<V4Database> v4_database) { 100 void V4Database::Destroy(std::unique_ptr<V4Database> v4_database) {
115 DCHECK_CURRENTLY_ON(BrowserThread::IO); 101 DCHECK_CURRENTLY_ON(BrowserThread::IO);
116 V4Database* v4_database_raw = v4_database.release(); 102 V4Database* v4_database_raw = v4_database.release();
117 if (v4_database_raw) { 103 if (v4_database_raw) {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 filename_(filename), 262 filename_(filename),
277 list_id_(list_id), 263 list_id_(list_id),
278 sb_threat_type_(sb_threat_type) { 264 sb_threat_type_(sb_threat_type) {
279 DCHECK(!fetch_updates_ || !filename_.empty()); 265 DCHECK(!fetch_updates_ || !filename_.empty());
280 DCHECK_NE(SB_THREAT_TYPE_SAFE, sb_threat_type_); 266 DCHECK_NE(SB_THREAT_TYPE_SAFE, sb_threat_type_);
281 } 267 }
282 268
283 ListInfo::~ListInfo() {} 269 ListInfo::~ListInfo() {}
284 270
285 } // namespace safe_browsing 271 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « components/safe_browsing_db/v4_database.h ('k') | components/safe_browsing_db/v4_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698