| 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 #include "components/safe_browsing_db/database_manager.h" | 5 #include "components/safe_browsing_db/database_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/location.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 16 #include "base/message_loop/message_loop.h" | |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "components/safe_browsing_db/test_database_manager.h" | 20 #include "components/safe_browsing_db/test_database_manager.h" |
| 19 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" | 21 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" |
| 20 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/test/test_browser_thread_bundle.h" | 23 #include "content/public/test/test_browser_thread_bundle.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 24 | 26 |
| 25 using content::BrowserThread; | 27 using content::BrowserThread; |
| 26 | 28 |
| 27 namespace safe_browsing { | 29 namespace safe_browsing { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 43 net::URLRequestContextGetter* request_context_getter, | 45 net::URLRequestContextGetter* request_context_getter, |
| 44 const V4ProtocolConfig& config) | 46 const V4ProtocolConfig& config) |
| 45 : V4GetHashProtocolManager(request_context_getter, config), | 47 : V4GetHashProtocolManager(request_context_getter, config), |
| 46 negative_cache_expire_(base::Time()), delay_seconds_(0) {} | 48 negative_cache_expire_(base::Time()), delay_seconds_(0) {} |
| 47 | 49 |
| 48 ~TestV4GetHashProtocolManager() override {} | 50 ~TestV4GetHashProtocolManager() override {} |
| 49 | 51 |
| 50 void GetFullHashesWithApis(const std::vector<SBPrefix>& prefixes, | 52 void GetFullHashesWithApis(const std::vector<SBPrefix>& prefixes, |
| 51 FullHashCallback callback) override { | 53 FullHashCallback callback) override { |
| 52 prefixes_ = prefixes; | 54 prefixes_ = prefixes; |
| 53 base::MessageLoop::current()->PostDelayedTask( | 55 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 54 FROM_HERE, base::Bind(InvokeFullHashCallback, callback, full_hashes_, | 56 FROM_HERE, base::Bind(InvokeFullHashCallback, callback, full_hashes_, |
| 55 negative_cache_expire_), | 57 negative_cache_expire_), |
| 56 base::TimeDelta::FromSeconds(delay_seconds_)); | 58 base::TimeDelta::FromSeconds(delay_seconds_)); |
| 57 } | 59 } |
| 58 | 60 |
| 59 void SetDelaySeconds(int delay) { | 61 void SetDelaySeconds(int delay) { |
| 60 delay_seconds_ = delay; | 62 delay_seconds_ = delay; |
| 61 } | 63 } |
| 62 | 64 |
| 63 void SetNegativeCacheDurationMins(base::Time now, | 65 void SetNegativeCacheDurationMins(base::Time now, |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 EXPECT_NE(cache.end(), entry); | 531 EXPECT_NE(cache.end(), entry); |
| 530 EXPECT_EQ(epoch, entry->second.expire_after); | 532 EXPECT_EQ(epoch, entry->second.expire_after); |
| 531 EXPECT_EQ(1ul, entry->second.full_hashes.size()); | 533 EXPECT_EQ(1ul, entry->second.full_hashes.size()); |
| 532 EXPECT_TRUE(SBFullHashEqual(full_hash_result.hash, | 534 EXPECT_TRUE(SBFullHashEqual(full_hash_result.hash, |
| 533 entry->second.full_hashes[0].hash)); | 535 entry->second.full_hashes[0].hash)); |
| 534 EXPECT_EQ(base::Time::Max(), | 536 EXPECT_EQ(base::Time::Max(), |
| 535 entry->second.full_hashes[0].cache_expire_after); | 537 entry->second.full_hashes[0].cache_expire_after); |
| 536 } | 538 } |
| 537 | 539 |
| 538 } // namespace safe_browsing | 540 } // namespace safe_browsing |
| OLD | NEW |