OLD | NEW |
---|---|
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/callback.h" | 8 #include "base/callback.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 // This callback is scheduled once the database has finished processing the | 23 // This callback is scheduled once the database has finished processing the |
24 // update requests for all stores and is ready to process the next set of update | 24 // update requests for all stores and is ready to process the next set of update |
25 // requests. | 25 // requests. |
26 typedef base::Callback<void()> DatabaseUpdatedCallback; | 26 typedef base::Callback<void()> DatabaseUpdatedCallback; |
27 | 27 |
28 // This hash_map maps the UpdateListIdentifiers to their corresponding in-memory | 28 // This hash_map maps the UpdateListIdentifiers to their corresponding in-memory |
29 // stores, which contain the hash prefixes for that UpdateListIdentifier as well | 29 // stores, which contain the hash prefixes for that UpdateListIdentifier as well |
30 // as manage their storage on disk. | 30 // as manage their storage on disk. |
31 typedef base::hash_map<UpdateListIdentifier, std::unique_ptr<V4Store>> StoreMap; | 31 typedef base::hash_map<UpdateListIdentifier, std::unique_ptr<V4Store>> StoreMap; |
32 | 32 |
33 // The list of stores that had a hash prefix matching the given full hash. | |
34 typedef std::vector<UpdateListIdentifier> StoresMatched; | |
Nathan Parker
2016/07/19 23:05:56
A thought: It might be easier to read to not typed
vakh (use Gerrit instead)
2016/07/20 00:07:43
Now that it is a map of store identifiers to the m
| |
35 | |
33 // Factory for creating V4Database. Tests implement this factory to create fake | 36 // Factory for creating V4Database. Tests implement this factory to create fake |
34 // databases for testing. | 37 // databases for testing. |
35 class V4DatabaseFactory { | 38 class V4DatabaseFactory { |
36 public: | 39 public: |
37 virtual ~V4DatabaseFactory() {} | 40 virtual ~V4DatabaseFactory() {} |
38 virtual V4Database* CreateV4Database( | 41 virtual V4Database* CreateV4Database( |
39 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 42 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
40 const base::FilePath& base_dir_path, | 43 const base::FilePath& base_dir_path, |
41 const StoreFileNameMap& store_file_name_map) = 0; | 44 const StoreFileNameMap& store_file_name_map) = 0; |
42 }; | 45 }; |
(...skipping 24 matching lines...) Expand all Loading... | |
67 virtual ~V4Database(); | 70 virtual ~V4Database(); |
68 | 71 |
69 // Updates the stores with the response received from the SafeBrowsing service | 72 // Updates the stores with the response received from the SafeBrowsing service |
70 // and calls the db_updated_callback when done. | 73 // and calls the db_updated_callback when done. |
71 void ApplyUpdate(std::unique_ptr<ParsedServerResponse> parsed_server_response, | 74 void ApplyUpdate(std::unique_ptr<ParsedServerResponse> parsed_server_response, |
72 DatabaseUpdatedCallback db_updated_callback); | 75 DatabaseUpdatedCallback db_updated_callback); |
73 | 76 |
74 // Returns the current state of each of the stores being managed. | 77 // Returns the current state of each of the stores being managed. |
75 std::unique_ptr<StoreStateMap> GetStoreStateMap(); | 78 std::unique_ptr<StoreStateMap> GetStoreStateMap(); |
76 | 79 |
80 void GetStoresMatchingFullHash(const FullHash& full_hash, | |
81 StoresMatched* stores_matched); | |
82 | |
77 // Deletes the current database and creates a new one. | 83 // Deletes the current database and creates a new one. |
78 virtual bool ResetDatabase(); | 84 virtual bool ResetDatabase(); |
79 | 85 |
80 protected: | 86 protected: |
81 V4Database(const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 87 V4Database(const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
82 std::unique_ptr<StoreMap> store_map); | 88 std::unique_ptr<StoreMap> store_map); |
83 | 89 |
84 private: | 90 private: |
85 friend class V4DatabaseTest; | 91 friend class V4DatabaseTest; |
86 FRIEND_TEST_ALL_PREFIXES(V4DatabaseTest, TestSetupDatabaseWithFakeStores); | 92 FRIEND_TEST_ALL_PREFIXES(V4DatabaseTest, TestSetupDatabaseWithFakeStores); |
87 FRIEND_TEST_ALL_PREFIXES(V4DatabaseTest, | 93 FRIEND_TEST_ALL_PREFIXES(V4DatabaseTest, |
88 TestSetupDatabaseWithFakeStoresFailsReset); | 94 TestSetupDatabaseWithFakeStoresFailsReset); |
89 FRIEND_TEST_ALL_PREFIXES(V4DatabaseTest, TestApplyUpdateWithNewStates); | 95 FRIEND_TEST_ALL_PREFIXES(V4DatabaseTest, TestApplyUpdateWithNewStates); |
90 FRIEND_TEST_ALL_PREFIXES(V4DatabaseTest, TestApplyUpdateWithNoNewState); | 96 FRIEND_TEST_ALL_PREFIXES(V4DatabaseTest, TestApplyUpdateWithNoNewState); |
91 FRIEND_TEST_ALL_PREFIXES(V4DatabaseTest, TestApplyUpdateWithEmptyUpdate); | 97 FRIEND_TEST_ALL_PREFIXES(V4DatabaseTest, TestApplyUpdateWithEmptyUpdate); |
92 FRIEND_TEST_ALL_PREFIXES(V4DatabaseTest, TestApplyUpdateWithInvalidUpdate); | 98 FRIEND_TEST_ALL_PREFIXES(V4DatabaseTest, TestApplyUpdateWithInvalidUpdate); |
99 FRIEND_TEST_ALL_PREFIXES(V4DatabaseTest, TestSomeStoresMatchFullHash); | |
93 | 100 |
94 // Makes the passed |factory| the factory used to instantiate a V4Store. Only | 101 // Makes the passed |factory| the factory used to instantiate a V4Store. Only |
95 // for tests. | 102 // for tests. |
96 static void RegisterStoreFactoryForTest(V4StoreFactory* factory) { | 103 static void RegisterStoreFactoryForTest(V4StoreFactory* factory) { |
97 factory_ = factory; | 104 factory_ = factory; |
98 } | 105 } |
99 | 106 |
100 // Factory method to create a V4Database. When the database creation is | 107 // Factory method to create a V4Database. When the database creation is |
101 // complete, it calls the NewDatabaseReadyCallback on |callback_task_runner|. | 108 // complete, it calls the NewDatabaseReadyCallback on |callback_task_runner|. |
102 static void CreateOnTaskRunner( | 109 static void CreateOnTaskRunner( |
(...skipping 24 matching lines...) Expand all Loading... | |
127 // that needed updating and is ready for the next update. It should only be | 134 // that needed updating and is ready for the next update. It should only be |
128 // accessed on the IO thread. | 135 // accessed on the IO thread. |
129 int pending_store_updates_; | 136 int pending_store_updates_; |
130 | 137 |
131 DISALLOW_COPY_AND_ASSIGN(V4Database); | 138 DISALLOW_COPY_AND_ASSIGN(V4Database); |
132 }; | 139 }; |
133 | 140 |
134 } // namespace safe_browsing | 141 } // namespace safe_browsing |
135 | 142 |
136 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_DATABASE_H_ | 143 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_DATABASE_H_ |
OLD | NEW |