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

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

Issue 2441923003: PVer4: Add UMA metrics for time taken to: load DB, do prefix check, (Closed)
Patch Set: nparker@'s review Created 4 years, 1 month 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/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
12 #include "components/safe_browsing_db/v4_database.h" 13 #include "components/safe_browsing_db/v4_database.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 15
15 using content::BrowserThread; 16 using content::BrowserThread;
17 using base::TimeTicks;
16 18
17 namespace safe_browsing { 19 namespace safe_browsing {
18 20
19 // static 21 // static
20 V4StoreFactory* V4Database::factory_ = NULL; 22 V4StoreFactory* V4Database::factory_ = NULL;
21 23
22 // static 24 // static
23 void V4Database::Create( 25 void V4Database::Create(
24 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 26 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
25 const base::FilePath& base_path, 27 const base::FilePath& base_path,
26 const ListInfos& list_infos, 28 const ListInfos& list_infos,
27 NewDatabaseReadyCallback new_db_callback) { 29 NewDatabaseReadyCallback new_db_callback) {
28 DCHECK(base_path.IsAbsolute()); 30 DCHECK(base_path.IsAbsolute());
29 DCHECK(!list_infos.empty()); 31 DCHECK(!list_infos.empty());
30 32
31 const scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner = 33 const scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner =
32 base::ThreadTaskRunnerHandle::Get(); 34 base::ThreadTaskRunnerHandle::Get();
33 db_task_runner->PostTask( 35 db_task_runner->PostTask(
34 FROM_HERE, 36 FROM_HERE, base::Bind(&V4Database::CreateOnTaskRunner, db_task_runner,
35 base::Bind(&V4Database::CreateOnTaskRunner, db_task_runner, base_path, 37 base_path, list_infos, callback_task_runner,
36 list_infos, callback_task_runner, new_db_callback)); 38 new_db_callback, TimeTicks::Now()));
37 } 39 }
38 40
39 // static 41 // static
40 void V4Database::CreateOnTaskRunner( 42 void V4Database::CreateOnTaskRunner(
41 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 43 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
42 const base::FilePath& base_path, 44 const base::FilePath& base_path,
43 const ListInfos& list_infos, 45 const ListInfos& list_infos,
44 const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner, 46 const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner,
45 NewDatabaseReadyCallback new_db_callback) { 47 NewDatabaseReadyCallback new_db_callback,
48 const TimeTicks create_start_time) {
46 DCHECK(db_task_runner->RunsTasksOnCurrentThread()); 49 DCHECK(db_task_runner->RunsTasksOnCurrentThread());
47 50
48 if (!factory_) { 51 if (!factory_) {
49 factory_ = new V4StoreFactory(); 52 factory_ = new V4StoreFactory();
50 ANNOTATE_LEAKING_OBJECT_PTR(factory_); 53 ANNOTATE_LEAKING_OBJECT_PTR(factory_);
51 } 54 }
52 55
53 if (!base::CreateDirectory(base_path)) { 56 if (!base::CreateDirectory(base_path)) {
54 NOTREACHED(); 57 NOTREACHED();
55 } 58 }
56 59
57 std::unique_ptr<StoreMap> store_map = base::MakeUnique<StoreMap>(); 60 std::unique_ptr<StoreMap> store_map = base::MakeUnique<StoreMap>();
58 for (const auto& it : list_infos) { 61 for (const auto& it : list_infos) {
59 if (!it.fetch_updates()) { 62 if (!it.fetch_updates()) {
60 // This list doesn't need to be fetched or stored on disk. 63 // This list doesn't need to be fetched or stored on disk.
61 continue; 64 continue;
62 } 65 }
63 66
64 const base::FilePath store_path = base_path.AppendASCII(it.filename()); 67 const base::FilePath store_path = base_path.AppendASCII(it.filename());
65 (*store_map)[it.list_id()].reset( 68 (*store_map)[it.list_id()].reset(
66 factory_->CreateV4Store(db_task_runner, store_path)); 69 factory_->CreateV4Store(db_task_runner, store_path));
67 } 70 }
68 std::unique_ptr<V4Database> v4_database( 71 std::unique_ptr<V4Database> v4_database(
69 new V4Database(db_task_runner, std::move(store_map))); 72 new V4Database(db_task_runner, std::move(store_map)));
70 73
71 // Database is done loading, pass it to the new_db_callback on the caller's 74 // Database is done loading, pass it to the new_db_callback on the caller's
72 // thread. This would unblock resource loads. 75 // thread. This would unblock resource loads.
73 callback_task_runner->PostTask( 76 callback_task_runner->PostTask(
74 FROM_HERE, base::Bind(new_db_callback, base::Passed(&v4_database))); 77 FROM_HERE, base::Bind(new_db_callback, base::Passed(&v4_database)));
78
79 UMA_HISTOGRAM_TIMES("SafeBrowsing.V4DatabaseOpen.Time",
80 TimeTicks::Now() - create_start_time);
75 } 81 }
76 82
77 V4Database::V4Database( 83 V4Database::V4Database(
78 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 84 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
79 std::unique_ptr<StoreMap> store_map) 85 std::unique_ptr<StoreMap> store_map)
80 : db_task_runner_(db_task_runner), 86 : db_task_runner_(db_task_runner),
81 store_map_(std::move(store_map)), 87 store_map_(std::move(store_map)),
82 pending_store_updates_(0) { 88 pending_store_updates_(0) {
83 DCHECK(db_task_runner->RunsTasksOnCurrentThread()); 89 DCHECK(db_task_runner->RunsTasksOnCurrentThread());
84 } 90 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 filename_(filename), 228 filename_(filename),
223 list_id_(list_id), 229 list_id_(list_id),
224 sb_threat_type_(sb_threat_type) { 230 sb_threat_type_(sb_threat_type) {
225 DCHECK(!fetch_updates_ || !filename_.empty()); 231 DCHECK(!fetch_updates_ || !filename_.empty());
226 DCHECK_NE(SB_THREAT_TYPE_SAFE, sb_threat_type_); 232 DCHECK_NE(SB_THREAT_TYPE_SAFE, sb_threat_type_);
227 } 233 }
228 234
229 ListInfo::~ListInfo() {} 235 ListInfo::~ListInfo() {}
230 236
231 } // namespace safe_browsing 237 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698