Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 CHROME_BROWSER_SAFE_BROWSING_V4_TEST_UTILS_H_ | |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_V4_TEST_UTILS_H_ | |
| 7 | |
| 8 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" | |
|
mattm
2017/02/17 21:49:53
Is this needed?
melandory
2017/02/27 15:01:48
Done.
| |
| 9 #include "components/safe_browsing_db/v4_database.h" | |
| 10 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" | |
| 11 | |
| 12 namespace safe_browsing { | |
| 13 | |
| 14 class TestV4Store : public V4Store { | |
| 15 public: | |
| 16 TestV4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner, | |
| 17 const base::FilePath& store_path); | |
| 18 | |
| 19 bool HasValidData() const override; | |
| 20 | |
| 21 void MarkPrefixAsBad(HashPrefix prefix); | |
| 22 }; | |
| 23 | |
| 24 class TestV4StoreFactory : public V4StoreFactory { | |
| 25 public: | |
| 26 V4Store* CreateV4Store( | |
| 27 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | |
| 28 const base::FilePath& store_path) override; | |
| 29 }; | |
| 30 | |
| 31 class TestV4Database : public V4Database { | |
| 32 public: | |
| 33 TestV4Database(const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | |
| 34 std::unique_ptr<StoreMap> store_map); | |
| 35 | |
| 36 void MarkPrefixAsBad(ListIdentifier list_id, HashPrefix prefix); | |
| 37 }; | |
| 38 | |
| 39 class TestV4DatabaseFactory : public V4DatabaseFactory { | |
| 40 public: | |
| 41 TestV4DatabaseFactory(); | |
| 42 | |
| 43 std::unique_ptr<V4Database> Create( | |
| 44 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | |
| 45 std::unique_ptr<StoreMap> store_map) override; | |
| 46 | |
| 47 void MarkPrefixAsBad(ListIdentifier list_id, HashPrefix prefix); | |
| 48 | |
| 49 private: | |
| 50 // Owned by V4LocalDatabaseManager. Each test in the V4SafeBrowsingServiceTest | |
|
mattm
2017/02/17 21:49:53
update comment (no longer specific to V4SafeBrowsi
melandory
2017/02/27 15:01:48
Done.
| |
| 51 // class instantiates a new SafebrowsingService instance, which instantiates a | |
| 52 // new V4LocalDatabaseManager, which instantiates a new V4Database using this | |
| 53 // method so use-after-free isn't possible. | |
| 54 TestV4Database* v4_db_; | |
| 55 }; | |
| 56 | |
| 57 class TestV4GetHashProtocolManager : public V4GetHashProtocolManager { | |
| 58 public: | |
| 59 TestV4GetHashProtocolManager( | |
| 60 net::URLRequestContextGetter* request_context_getter, | |
| 61 const StoresToCheck& stores_to_check, | |
| 62 const V4ProtocolConfig& config); | |
| 63 | |
| 64 void AddToFullHashCache(FullHashInfo fhi); | |
| 65 }; | |
| 66 | |
| 67 class TestV4GetHashProtocolManagerFactory | |
| 68 : public V4GetHashProtocolManagerFactory { | |
| 69 public: | |
| 70 std::unique_ptr<V4GetHashProtocolManager> CreateProtocolManager( | |
| 71 net::URLRequestContextGetter* request_context_getter, | |
| 72 const StoresToCheck& stores_to_check, | |
| 73 const V4ProtocolConfig& config) override; | |
| 74 | |
| 75 void AddToFullHashCache(FullHashInfo fhi) { pm_->AddToFullHashCache(fhi); } | |
| 76 | |
| 77 private: | |
| 78 // Owned by the SafeBrowsingService. | |
| 79 TestV4GetHashProtocolManager* pm_; | |
| 80 }; | |
| 81 | |
| 82 // Returns a FullHash for the basic host+path pattern for a given URL after | |
| 83 // canonicalization. | |
| 84 FullHash GetFullHash(const GURL& url); | |
| 85 | |
| 86 // Returns FullHashInfo object for the basic host+path pattern for a given URL | |
| 87 // after canonicalization. | |
| 88 FullHashInfo GetFullHashInfo(const GURL& url, const ListIdentifier& list_id); | |
| 89 | |
| 90 // Returns a FullHashInfo info for the basic host+path pattern for a given URL | |
| 91 // after canonicalization. Also adds metadata information to the FullHashInfo | |
| 92 // object. | |
| 93 FullHashInfo GetFullHashInfoWithMetadata(const GURL& url, | |
| 94 const ListIdentifier& list_id, | |
| 95 ThreatPatternType threat_pattern_type); | |
| 96 | |
| 97 } // namespace safe_browsing | |
| 98 | |
| 99 #endif // CHROME_BROWSER_SAFE_BROWSING_V4_TEST_UTILS_H_ | |
| OLD | NEW |