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" |
11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "components/safe_browsing_db/v4_protocol_manager_util.h" | 13 #include "components/safe_browsing_db/v4_protocol_manager_util.h" |
14 #include "components/safe_browsing_db/v4_store.h" | 14 #include "components/safe_browsing_db/v4_store.h" |
15 | 15 |
16 namespace safe_browsing { | 16 namespace safe_browsing { |
17 | 17 |
18 class V4Database; | 18 class V4Database; |
19 | 19 |
20 typedef base::Callback<void(std::unique_ptr<V4Database>)> | 20 typedef base::Callback<void(std::unique_ptr<V4Database>)> |
21 NewDatabaseReadyCallback; | 21 NewDatabaseReadyCallback; |
22 | 22 |
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 // The set of interesting lists and ASCII filenames for their hash prefix |
| 29 // stores. The stores are created inside the user-data directory. |
| 30 // For instance, the UpdateListIdentifier could be for URL expressions for UwS |
| 31 // on Windows platform, and the corresponding file on disk could be named: |
| 32 // "uws_win_url.store" |
| 33 // TODO(vakh): Find the canonical place where these are defined and update the |
| 34 // comment to point to that place. |
| 35 typedef base::hash_map<UpdateListIdentifier, std::string> StoreFileNameMap; |
| 36 |
28 // This hash_map maps the UpdateListIdentifiers to their corresponding in-memory | 37 // This hash_map maps the UpdateListIdentifiers to their corresponding in-memory |
29 // stores, which contain the hash prefixes for that UpdateListIdentifier as well | 38 // stores, which contain the hash prefixes for that UpdateListIdentifier as well |
30 // as manage their storage on disk. | 39 // as manage their storage on disk. |
31 typedef base::hash_map<UpdateListIdentifier, std::unique_ptr<V4Store>> StoreMap; | 40 typedef base::hash_map<UpdateListIdentifier, std::unique_ptr<V4Store>> StoreMap; |
32 | 41 |
33 // Map of identifier for any store that had a hash prefix matching the given | |
34 // full hash to the matching hash prefix. | |
35 typedef base::hash_map<UpdateListIdentifier, HashPrefix> MatchedHashPrefixMap; | |
36 | |
37 // Factory for creating V4Database. Tests implement this factory to create fake | 42 // Factory for creating V4Database. Tests implement this factory to create fake |
38 // databases for testing. | 43 // databases for testing. |
39 class V4DatabaseFactory { | 44 class V4DatabaseFactory { |
40 public: | 45 public: |
41 virtual ~V4DatabaseFactory() {} | 46 virtual ~V4DatabaseFactory() {} |
42 virtual V4Database* CreateV4Database( | 47 virtual V4Database* CreateV4Database( |
43 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 48 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
44 const base::FilePath& base_dir_path, | 49 const base::FilePath& base_dir_path, |
45 const StoreFileNameMap& store_file_name_map) = 0; | 50 const StoreFileNameMap& store_file_name_map) = 0; |
46 }; | 51 }; |
(...skipping 30 matching lines...) Expand all Loading... |
77 | 82 |
78 // Returns the current state of each of the stores being managed. | 83 // Returns the current state of each of the stores being managed. |
79 std::unique_ptr<StoreStateMap> GetStoreStateMap(); | 84 std::unique_ptr<StoreStateMap> GetStoreStateMap(); |
80 | 85 |
81 // Searches for a hash prefix matching the |full_hash| in stores in the | 86 // Searches for a hash prefix matching the |full_hash| in stores in the |
82 // database, filtered by |stores_to_look|, and returns the identifier of the | 87 // database, filtered by |stores_to_look|, and returns the identifier of the |
83 // store along with the matching hash prefix in |matched_hash_prefix_map|. | 88 // store along with the matching hash prefix in |matched_hash_prefix_map|. |
84 virtual void GetStoresMatchingFullHash( | 89 virtual void GetStoresMatchingFullHash( |
85 const FullHash& full_hash, | 90 const FullHash& full_hash, |
86 const base::hash_set<UpdateListIdentifier>& stores_to_look, | 91 const base::hash_set<UpdateListIdentifier>& stores_to_look, |
87 MatchedHashPrefixMap* matched_hash_prefix_map); | 92 StoreAndHashPrefixes* matched_store_and_full_hashes); |
88 | 93 |
89 // Deletes the current database and creates a new one. | 94 // Deletes the current database and creates a new one. |
90 virtual bool ResetDatabase(); | 95 virtual bool ResetDatabase(); |
91 | 96 |
92 protected: | 97 protected: |
93 V4Database(const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 98 V4Database(const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
94 std::unique_ptr<StoreMap> store_map); | 99 std::unique_ptr<StoreMap> store_map); |
95 | 100 |
96 private: | 101 private: |
97 friend class V4DatabaseTest; | 102 friend class V4DatabaseTest; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // that needed updating and is ready for the next update. It should only be | 145 // that needed updating and is ready for the next update. It should only be |
141 // accessed on the IO thread. | 146 // accessed on the IO thread. |
142 int pending_store_updates_; | 147 int pending_store_updates_; |
143 | 148 |
144 DISALLOW_COPY_AND_ASSIGN(V4Database); | 149 DISALLOW_COPY_AND_ASSIGN(V4Database); |
145 }; | 150 }; |
146 | 151 |
147 } // namespace safe_browsing | 152 } // namespace safe_browsing |
148 | 153 |
149 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_DATABASE_H_ | 154 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_DATABASE_H_ |
OLD | NEW |