| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/extensions/fake_safe_browsing_database_manager.h" | 5 #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/message_loop/message_loop_proxy.h" | 13 #include "base/message_loop/message_loop_proxy.h" |
| 14 #include "base/run_loop.h" |
| 14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 15 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 16 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
| 16 | 17 |
| 17 namespace extensions { | 18 namespace extensions { |
| 18 | 19 |
| 19 FakeSafeBrowsingDatabaseManager::FakeSafeBrowsingDatabaseManager() | 20 FakeSafeBrowsingDatabaseManager::FakeSafeBrowsingDatabaseManager(bool enabled) |
| 20 : SafeBrowsingDatabaseManager( | 21 : SafeBrowsingDatabaseManager( |
| 21 make_scoped_refptr(SafeBrowsingService::CreateSafeBrowsingService())), | 22 make_scoped_refptr(SafeBrowsingService::CreateSafeBrowsingService())), |
| 22 enabled_(false) { | 23 enabled_(enabled) { |
| 23 } | 24 } |
| 24 | 25 |
| 25 FakeSafeBrowsingDatabaseManager::~FakeSafeBrowsingDatabaseManager() { | 26 FakeSafeBrowsingDatabaseManager::~FakeSafeBrowsingDatabaseManager() { |
| 26 } | 27 } |
| 27 | 28 |
| 29 FakeSafeBrowsingDatabaseManager& FakeSafeBrowsingDatabaseManager::Enable() { |
| 30 enabled_ = true; |
| 31 return *this; |
| 32 } |
| 33 |
| 34 FakeSafeBrowsingDatabaseManager& |
| 35 FakeSafeBrowsingDatabaseManager::ClearUnsafe() { |
| 36 unsafe_ids_.clear(); |
| 37 return *this; |
| 38 } |
| 39 |
| 40 FakeSafeBrowsingDatabaseManager& FakeSafeBrowsingDatabaseManager::SetUnsafe( |
| 41 const std::string& a) { |
| 42 ClearUnsafe(); |
| 43 unsafe_ids_.insert(a); |
| 44 return *this; |
| 45 } |
| 46 |
| 47 FakeSafeBrowsingDatabaseManager& FakeSafeBrowsingDatabaseManager::SetUnsafe( |
| 48 const std::string& a, const std::string& b) { |
| 49 SetUnsafe(a); |
| 50 unsafe_ids_.insert(b); |
| 51 return *this; |
| 52 } |
| 53 |
| 54 FakeSafeBrowsingDatabaseManager& FakeSafeBrowsingDatabaseManager::SetUnsafe( |
| 55 const std::string& a, const std::string& b, const std::string& c) { |
| 56 SetUnsafe(a, b); |
| 57 unsafe_ids_.insert(c); |
| 58 return *this; |
| 59 } |
| 60 |
| 61 void FakeSafeBrowsingDatabaseManager::NotifyUpdate() { |
| 62 SafeBrowsingDatabaseManager::NotifyDatabaseUpdateFinished(true); |
| 63 } |
| 64 |
| 28 bool FakeSafeBrowsingDatabaseManager::CheckExtensionIDs( | 65 bool FakeSafeBrowsingDatabaseManager::CheckExtensionIDs( |
| 29 const std::set<std::string>& extension_ids, | 66 const std::set<std::string>& extension_ids, |
| 30 Client* client) { | 67 Client* client) { |
| 31 if (!enabled_) | 68 if (!enabled_) |
| 32 return true; | 69 return true; |
| 33 | 70 |
| 34 // Need to construct the full SafeBrowsingCheck rather than calling | 71 // Need to construct the full SafeBrowsingCheck rather than calling |
| 35 // OnCheckExtensionsResult directly because it's protected. Grr! | 72 // OnCheckExtensionsResult directly because it's protected. Grr! |
| 36 std::vector<std::string> extension_ids_vector(extension_ids.begin(), | 73 std::vector<std::string> extension_ids_vector(extension_ids.begin(), |
| 37 extension_ids.end()); | 74 extension_ids.end()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 63 return false; | 100 return false; |
| 64 } | 101 } |
| 65 | 102 |
| 66 void FakeSafeBrowsingDatabaseManager::OnSafeBrowsingResult( | 103 void FakeSafeBrowsingDatabaseManager::OnSafeBrowsingResult( |
| 67 scoped_ptr<SafeBrowsingCheck> result, | 104 scoped_ptr<SafeBrowsingCheck> result, |
| 68 Client* client) { | 105 Client* client) { |
| 69 client->OnSafeBrowsingResult(*result); | 106 client->OnSafeBrowsingResult(*result); |
| 70 } | 107 } |
| 71 | 108 |
| 72 } // namespace extensions | 109 } // namespace extensions |
| OLD | NEW |