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

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: schedule destroying the v4_database off IO thread if the local_db_manager isn't enabled, and update… 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( 59 // Destroys the provided v4_database on its task_runner since this may be a
56 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 60 // long operation.
57 StoreMap store_map); 61 static void Destroy(std::unique_ptr<V4Database> v4_database);
62
58 virtual ~V4Database(); 63 virtual ~V4Database();
59 64
60 // Deletes the current database and creates a new one. 65 // Deletes the current database and creates a new one.
61 virtual bool ResetDatabase(); 66 virtual bool ResetDatabase();
62 67
63 // Makes the passed |factory| the factory used to instantiate 68 // Makes the passed |factory| the factory used to instantiate
64 // a V4Database. Only for tests. 69 // a V4Database. Only for tests.
65 static void RegisterFactoryForTest(V4DatabaseFactory* factory) { 70 static void RegisterFactoryForTest(V4DatabaseFactory* factory) {
66 factory_ = factory; 71 factory_ = factory;
67 } 72 }
68 73
74 protected:
75 V4Database(const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
76 StoreMap store_map);
77
69 private: 78 private:
79 // Factory method to create a V4Database. When the database creation is
80 // complete, it calls the NewDatabaseReadyCallback on |callback_task_runner|.
81 static void CreateOnTaskRunner(
82 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
83 const base::FilePath& base_path,
84 ListInfoMap list_info_map,
85 const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner,
86 NewDatabaseReadyCallback callback);
87
88 const scoped_refptr<base::SequencedTaskRunner> db_task_runner_;
89
90 // Map of UpdateListIdentifier to the V4Store.
91 StoreMap store_map_;
92
70 // The factory that controls the creation of V4Database objects. 93 // The factory that controls the creation of V4Database objects.
71 // This is used *only* by tests. 94 // This is used *only* by tests.
72 static V4DatabaseFactory* factory_; 95 static V4DatabaseFactory* factory_;
73 96
74 DISALLOW_COPY_AND_ASSIGN(V4Database); 97 DISALLOW_COPY_AND_ASSIGN(V4Database);
75 }; 98 };
76 99
77 } // namespace safe_browsing 100 } // namespace safe_browsing
78 101
79 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_DATABASE_H_ 102 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698