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

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

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

Powered by Google App Engine
This is Rietveld 408576698