OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_DATABASE_H_ | |
6 #define COMPONENTS_SAFE_BROWSING_DB_V4_DATABASE_H_ | |
7 | |
8 #include "base/files/file_path.h" | |
9 #include "base/memory/ref_counted.h" | |
10 #include "base/sequenced_task_runner.h" | |
11 #include "components/safe_browsing_db/v4_protocol_manager_util.h" | |
12 #include "components/safe_browsing_db/v4_store.h" | |
13 | |
14 namespace safe_browsing { | |
15 | |
16 class V4Database; | |
17 | |
18 typedef const base::hash_map<UpdateListIdentifier, | |
19 const base::FilePath::CharType> | |
20 ListInfoMap; | |
21 | |
22 typedef std::unique_ptr< | |
23 base::hash_map<UpdateListIdentifier, std::unique_ptr<V4Store>>> | |
24 StoreMap; | |
25 | |
26 // Factory for creating V4Database. Tests implement this factory to create fake | |
27 // databases for testing. | |
28 class V4DatabaseFactory { | |
29 public: | |
30 virtual ~V4DatabaseFactory() {} | |
31 virtual V4Database* CreateV4Database( | |
32 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | |
33 const base::FilePath& base_path, | |
34 ListInfoMap list_info_map) = 0; | |
35 }; | |
36 | |
37 // 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 | |
39 // should be used on the same thread that it was created on, unless specified | |
40 // otherwise. | |
41 // The hash-prefixes of each type are managed by a V4Store (including saving to | |
42 // and reading from disk). | |
43 // The V4Database serves as a single place to manage all the V4Stores. | |
44 class V4Database { | |
45 public: | |
46 // Factory method for obtaining a V4Database implementation. | |
47 // It is not thread safe. | |
48 // The availability of each list is controlled by the one flag on this | |
49 // method. | |
50 static V4Database* Create( | |
51 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | |
52 const base::FilePath& base_path, | |
53 ListInfoMap list_info_map); | |
54 | |
55 V4Database( | |
56 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | |
57 StoreMap store_map); | |
58 virtual ~V4Database(); | |
59 | |
60 // Deletes the current database and creates a new one. | |
61 virtual bool ResetDatabase(); | |
62 | |
63 // Makes the passed |factory| the factory used to instantiate | |
64 // a V4Database. Only for tests. | |
65 static void RegisterFactoryForTest(V4DatabaseFactory* factory) { | |
66 factory_ = factory; | |
67 } | |
68 | |
69 private: | |
70 // The factory that controls the creation of V4Database objects. | |
71 //This is used *only* by tests. | |
Nathan Parker
2016/05/06 22:47:11
nit: space after //
vakh (use Gerrit instead)
2016/05/06 22:51:36
Done.
| |
72 static V4DatabaseFactory* factory_; | |
73 | |
74 DISALLOW_COPY_AND_ASSIGN(V4Database); | |
75 }; | |
76 | |
77 } // namespace safe_browsing | |
78 | |
79 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_DATABASE_H_ | |
OLD | NEW |