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

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

Issue 1983723002: Reland: Initialize and reset V4LocalDBManager. Instantiate V4Stores. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add check for v4_update_protocol_manager_ on DatabaseReady callback Created 4 years, 7 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 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_DATABASE_H_ 5 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_DATABASE_H_
6 #define COMPONENTS_SAFE_BROWSING_DB_V4_DATABASE_H_ 6 #define COMPONENTS_SAFE_BROWSING_DB_V4_DATABASE_H_
7 7
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/sequenced_task_runner.h" 10 #include "base/sequenced_task_runner.h"
11 #include "base/single_thread_task_runner.h"
11 #include "components/safe_browsing_db/v4_protocol_manager_util.h" 12 #include "components/safe_browsing_db/v4_protocol_manager_util.h"
12 #include "components/safe_browsing_db/v4_store.h" 13 #include "components/safe_browsing_db/v4_store.h"
13 14
14 namespace safe_browsing { 15 namespace safe_browsing {
15 16
16 class V4Database; 17 class V4Database;
17 18
19 typedef base::Callback<void(std::unique_ptr<V4Database>)>
20 NewDatabaseReadyCallback;
21
18 typedef const base::hash_map<UpdateListIdentifier, 22 typedef const base::hash_map<UpdateListIdentifier,
19 const base::FilePath::CharType> 23 const base::FilePath::CharType>
20 ListInfoMap; 24 ListInfoMap;
21 25
22 typedef std::unique_ptr< 26 typedef std::unique_ptr<
23 base::hash_map<UpdateListIdentifier, std::unique_ptr<V4Store>>> 27 base::hash_map<UpdateListIdentifier, std::unique_ptr<V4Store>>>
24 StoreMap; 28 StoreMap;
25 29
26 // Factory for creating V4Database. Tests implement this factory to create fake 30 // Factory for creating V4Database. Tests implement this factory to create fake
27 // databases for testing. 31 // databases for testing.
28 class V4DatabaseFactory { 32 class V4DatabaseFactory {
29 public: 33 public:
30 virtual ~V4DatabaseFactory() {} 34 virtual ~V4DatabaseFactory() {}
31 virtual V4Database* CreateV4Database( 35 virtual V4Database* CreateV4Database(
32 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 36 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
33 const base::FilePath& base_path, 37 const base::FilePath& base_path,
34 ListInfoMap list_info_map) = 0; 38 ListInfoMap list_info_map) = 0;
35 }; 39 };
36 40
37 // The on-disk databases are shared among all profiles, as it doesn't contain 41 // The on-disk databases are shared among all profiles, as it doesn't contain
38 // user-specific data. This object is not thread-safe, i.e. all its methods 42 // user-specific data. This object is not thread-safe, i.e. all its methods
39 // should be used on the same thread that it was created on, unless specified 43 // should be used on the same thread that it was created on, unless specified
40 // otherwise. 44 // otherwise.
41 // The hash-prefixes of each type are managed by a V4Store (including saving to 45 // The hash-prefixes of each type are managed by a V4Store (including saving to
42 // and reading from disk). 46 // and reading from disk).
43 // The V4Database serves as a single place to manage all the V4Stores. 47 // The V4Database serves as a single place to manage all the V4Stores.
44 class V4Database { 48 class V4Database {
45 public: 49 public:
46 // Factory method for obtaining a V4Database implementation. 50 // Factory method to create a V4Database. It creates the database on the
47 // It is not thread safe. 51 // provided |db_task_runner|. When the database creation is complete, it calls
48 // The availability of each list is controlled by the one flag on this 52 // the NewDatabaseReadyCallback on the same thread as it was called.
49 // method. 53 static void Create(
50 static V4Database* Create(
51 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 54 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
52 const base::FilePath& base_path, 55 const base::FilePath& base_path,
53 ListInfoMap list_info_map); 56 ListInfoMap list_info_map,
57 NewDatabaseReadyCallback callback);
54 58
55 V4Database(
56 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
57 StoreMap store_map);
58 virtual ~V4Database(); 59 virtual ~V4Database();
59 60
60 // Deletes the current database and creates a new one. 61 // Deletes the current database and creates a new one.
61 virtual bool ResetDatabase(); 62 virtual bool ResetDatabase();
62 63
63 // Makes the passed |factory| the factory used to instantiate 64 // Makes the passed |factory| the factory used to instantiate
64 // a V4Database. Only for tests. 65 // a V4Database. Only for tests.
65 static void RegisterFactoryForTest(V4DatabaseFactory* factory) { 66 static void RegisterFactoryForTest(V4DatabaseFactory* factory) {
66 factory_ = factory; 67 factory_ = factory;
67 } 68 }
68 69
70 protected:
71 V4Database(const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
72 StoreMap store_map);
73
69 private: 74 private:
75 // Factory method to create a V4Database. When the database creation is
76 // complete, it calls the NewDatabaseReadyCallback on |callback_task_runner|.
77 static void CreateOnTaskRunner(
78 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
79 const base::FilePath& base_path,
80 ListInfoMap list_info_map,
81 const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner,
82 NewDatabaseReadyCallback callback);
83
84 const scoped_refptr<base::SequencedTaskRunner> db_task_runner_;
85
86 // Map of UpdateListIdentifier to the V4Store.
87 StoreMap store_map_;
88
70 // The factory that controls the creation of V4Database objects. 89 // The factory that controls the creation of V4Database objects.
71 // This is used *only* by tests. 90 // This is used *only* by tests.
72 static V4DatabaseFactory* factory_; 91 static V4DatabaseFactory* factory_;
73 92
74 DISALLOW_COPY_AND_ASSIGN(V4Database); 93 DISALLOW_COPY_AND_ASSIGN(V4Database);
75 }; 94 };
76 95
77 } // namespace safe_browsing 96 } // namespace safe_browsing
78 97
79 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_DATABASE_H_ 98 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698