OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016 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 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" |
| 6 |
| 7 #include "base/strings/string_util.h" |
| 8 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 9 #include "chrome/browser/safe_browsing/ping_manager.h" |
| 10 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 11 #include "components/safe_browsing_db/database_manager.h" |
| 12 #include "components/safe_browsing_db/test_database_manager.h" |
| 13 |
| 14 namespace safe_browsing { |
| 15 |
| 16 // TestSafeBrowsingService functions: |
| 17 TestSafeBrowsingService::TestSafeBrowsingService() |
| 18 : protocol_manager_delegate_disabled_(false), |
| 19 serialized_download_report_(base::EmptyString()) {} |
| 20 |
| 21 TestSafeBrowsingService::~TestSafeBrowsingService() {} |
| 22 |
| 23 SafeBrowsingProtocolConfig TestSafeBrowsingService::GetProtocolConfig() const { |
| 24 if (protocol_config_) |
| 25 return *protocol_config_; |
| 26 return SafeBrowsingService::GetProtocolConfig(); |
| 27 } |
| 28 |
| 29 V4ProtocolConfig TestSafeBrowsingService::GetV4ProtocolConfig() const { |
| 30 if (v4_protocol_config_) |
| 31 return *v4_protocol_config_; |
| 32 return SafeBrowsingService::GetV4ProtocolConfig(); |
| 33 } |
| 34 |
| 35 std::string TestSafeBrowsingService::serilized_download_report() { |
| 36 return serialized_download_report_; |
| 37 } |
| 38 |
| 39 void TestSafeBrowsingService::ClearDownloadReport() { |
| 40 serialized_download_report_.clear(); |
| 41 } |
| 42 |
| 43 void TestSafeBrowsingService::SetDatabaseManager( |
| 44 TestSafeBrowsingDatabaseManager* database_manager) { |
| 45 database_manager_ = database_manager; |
| 46 // Since TestSafeBrowsingDatabaseManager does not implement |
| 47 // SafeBrowsingProtocolManagerDelegate, when it is used we need to disable |
| 48 // protocol_manager_delegate. |
| 49 protocol_manager_delegate_disabled_ = true; |
| 50 } |
| 51 |
| 52 void TestSafeBrowsingService::SetUIManager( |
| 53 TestSafeBrowsingUIManager* ui_manager) { |
| 54 ui_manager->SetSafeBrowsingService(this); |
| 55 ui_manager_ = ui_manager; |
| 56 } |
| 57 |
| 58 SafeBrowsingDatabaseManager* TestSafeBrowsingService::CreateDatabaseManager() { |
| 59 if (database_manager_) |
| 60 return database_manager_.get(); |
| 61 return SafeBrowsingService::CreateDatabaseManager(); |
| 62 } |
| 63 |
| 64 SafeBrowsingUIManager* TestSafeBrowsingService::CreateUIManager() { |
| 65 if (ui_manager_) |
| 66 return ui_manager_.get(); |
| 67 return SafeBrowsingService::CreateUIManager(); |
| 68 } |
| 69 |
| 70 SafeBrowsingProtocolManagerDelegate* |
| 71 TestSafeBrowsingService::GetProtocolManagerDelegate() { |
| 72 if (protocol_manager_delegate_disabled_) |
| 73 return nullptr; |
| 74 return SafeBrowsingService::GetProtocolManagerDelegate(); |
| 75 } |
| 76 |
| 77 void TestSafeBrowsingService::SendSerializedDownloadReport( |
| 78 const std::string& report) { |
| 79 serialized_download_report_ = report; |
| 80 } |
| 81 |
| 82 void TestSafeBrowsingService::SetProtocolConfig( |
| 83 SafeBrowsingProtocolConfig* protocol_config) { |
| 84 protocol_config_.reset(protocol_config); |
| 85 } |
| 86 |
| 87 void TestSafeBrowsingService::SetV4ProtocolConfig( |
| 88 V4ProtocolConfig* v4_protocol_config) { |
| 89 v4_protocol_config_.reset(v4_protocol_config); |
| 90 } |
| 91 |
| 92 // TestSafeBrowsingServiceFactory functions: |
| 93 TestSafeBrowsingServiceFactory::TestSafeBrowsingServiceFactory() |
| 94 : test_safe_browsing_service_(nullptr), test_protocol_config_(nullptr) {} |
| 95 |
| 96 TestSafeBrowsingServiceFactory::~TestSafeBrowsingServiceFactory() {} |
| 97 |
| 98 SafeBrowsingService* |
| 99 TestSafeBrowsingServiceFactory::CreateSafeBrowsingService() { |
| 100 // Instantiate TestSafeBrowsingService. |
| 101 test_safe_browsing_service_ = new TestSafeBrowsingService(); |
| 102 // Plug-in test member clases accordingly. |
| 103 if (test_ui_manager_) |
| 104 test_safe_browsing_service_->SetUIManager(test_ui_manager_.get()); |
| 105 if (test_database_manager_) { |
| 106 test_safe_browsing_service_->SetDatabaseManager( |
| 107 test_database_manager_.get()); |
| 108 } |
| 109 if (test_protocol_config_) |
| 110 test_safe_browsing_service_->SetProtocolConfig(test_protocol_config_); |
| 111 return test_safe_browsing_service_; |
| 112 } |
| 113 |
| 114 TestSafeBrowsingService* |
| 115 TestSafeBrowsingServiceFactory::test_safe_browsing_service() { |
| 116 return test_safe_browsing_service_; |
| 117 } |
| 118 |
| 119 void TestSafeBrowsingServiceFactory::SetTestUIManager( |
| 120 TestSafeBrowsingUIManager* ui_manager) { |
| 121 test_ui_manager_ = ui_manager; |
| 122 } |
| 123 |
| 124 void TestSafeBrowsingServiceFactory::SetTestDatabaseManager( |
| 125 TestSafeBrowsingDatabaseManager* database_manager) { |
| 126 test_database_manager_ = database_manager; |
| 127 } |
| 128 |
| 129 void TestSafeBrowsingServiceFactory::SetTestProtocolConfig( |
| 130 const SafeBrowsingProtocolConfig& protocol_config) { |
| 131 test_protocol_config_ = new SafeBrowsingProtocolConfig(protocol_config); |
| 132 } |
| 133 |
| 134 // TestSafeBrowsingUIManager functions: |
| 135 TestSafeBrowsingUIManager::TestSafeBrowsingUIManager() |
| 136 : SafeBrowsingUIManager(nullptr) {} |
| 137 |
| 138 TestSafeBrowsingUIManager::TestSafeBrowsingUIManager( |
| 139 const scoped_refptr<SafeBrowsingService>& service) |
| 140 : SafeBrowsingUIManager(service) {} |
| 141 |
| 142 void TestSafeBrowsingUIManager::SetSafeBrowsingService( |
| 143 SafeBrowsingService* sb_service) { |
| 144 sb_service_ = sb_service; |
| 145 } |
| 146 |
| 147 void TestSafeBrowsingUIManager::SendSerializedThreatDetails( |
| 148 const std::string& serialized) { |
| 149 details_.push_back(serialized); |
| 150 } |
| 151 |
| 152 std::list<std::string>* TestSafeBrowsingUIManager::GetThreatDetails() { |
| 153 return &details_; |
| 154 } |
| 155 |
| 156 TestSafeBrowsingUIManager::~TestSafeBrowsingUIManager() {} |
| 157 } // namespace safe_browsing |
OLD | NEW |