Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: chrome/browser/extensions/fake_safe_browsing_database_manager.cc

Issue 1420053005: Move code in components/safe_browsing_db and chrome/browser/s_b/ under the safe_browsing namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@02_components_move
Patch Set: Remove '// namespace safe_browsing' for a small fwd decl block. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
16 #include "chrome/browser/safe_browsing/safe_browsing_util.h" 16 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
17 17
18 namespace extensions { 18 namespace extensions {
19 19
20 FakeSafeBrowsingDatabaseManager::FakeSafeBrowsingDatabaseManager(bool enabled) 20 FakeSafeBrowsingDatabaseManager::FakeSafeBrowsingDatabaseManager(bool enabled)
21 : LocalSafeBrowsingDatabaseManager( 21 : LocalSafeBrowsingDatabaseManager(make_scoped_refptr(
22 make_scoped_refptr(SafeBrowsingService::CreateSafeBrowsingService())), 22 safe_browsing::SafeBrowsingService::CreateSafeBrowsingService())),
23 enabled_(enabled) { 23 enabled_(enabled) {}
24 }
25 24
26 FakeSafeBrowsingDatabaseManager::~FakeSafeBrowsingDatabaseManager() { 25 FakeSafeBrowsingDatabaseManager::~FakeSafeBrowsingDatabaseManager() {
27 } 26 }
28 27
29 FakeSafeBrowsingDatabaseManager& FakeSafeBrowsingDatabaseManager::Enable() { 28 FakeSafeBrowsingDatabaseManager& FakeSafeBrowsingDatabaseManager::Enable() {
30 enabled_ = true; 29 enabled_ = true;
31 return *this; 30 return *this;
32 } 31 }
33 32
34 FakeSafeBrowsingDatabaseManager& FakeSafeBrowsingDatabaseManager::Disable() { 33 FakeSafeBrowsingDatabaseManager& FakeSafeBrowsingDatabaseManager::Disable() {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 bool FakeSafeBrowsingDatabaseManager::CheckExtensionIDs( 89 bool FakeSafeBrowsingDatabaseManager::CheckExtensionIDs(
91 const std::set<std::string>& extension_ids, 90 const std::set<std::string>& extension_ids,
92 Client* client) { 91 Client* client) {
93 if (!enabled_) 92 if (!enabled_)
94 return true; 93 return true;
95 94
96 // Need to construct the full SafeBrowsingCheck rather than calling 95 // Need to construct the full SafeBrowsingCheck rather than calling
97 // OnCheckExtensionsResult directly because it's protected. Grr! 96 // OnCheckExtensionsResult directly because it's protected. Grr!
98 std::vector<std::string> extension_ids_vector(extension_ids.begin(), 97 std::vector<std::string> extension_ids_vector(extension_ids.begin(),
99 extension_ids.end()); 98 extension_ids.end());
100 std::vector<SBFullHash> extension_id_hashes; 99 std::vector<safe_browsing::SBFullHash> extension_id_hashes;
101 std::transform(extension_ids_vector.begin(), extension_ids_vector.end(), 100 std::transform(extension_ids_vector.begin(), extension_ids_vector.end(),
102 std::back_inserter(extension_id_hashes), 101 std::back_inserter(extension_id_hashes),
103 safe_browsing::StringToSBFullHash); 102 safe_browsing::StringToSBFullHash);
104 103
105 scoped_ptr<SafeBrowsingCheck> safe_browsing_check( 104 scoped_ptr<SafeBrowsingCheck> safe_browsing_check(
106 new SafeBrowsingCheck( 105 new SafeBrowsingCheck(std::vector<GURL>(), extension_id_hashes, client,
107 std::vector<GURL>(), 106 safe_browsing::EXTENSIONBLACKLIST,
108 extension_id_hashes, 107 std::vector<safe_browsing::SBThreatType>(
109 client, 108 1, safe_browsing::SB_THREAT_TYPE_EXTENSION)));
110 safe_browsing::EXTENSIONBLACKLIST,
111 std::vector<SBThreatType>(1, SB_THREAT_TYPE_EXTENSION)));
112 109
113 for (size_t i = 0; i < extension_ids_vector.size(); ++i) { 110 for (size_t i = 0; i < extension_ids_vector.size(); ++i) {
114 const std::string& extension_id = extension_ids_vector[i]; 111 const std::string& extension_id = extension_ids_vector[i];
115 if (unsafe_ids_.count(extension_id)) 112 if (unsafe_ids_.count(extension_id))
116 safe_browsing_check->full_hash_results[i] = SB_THREAT_TYPE_EXTENSION; 113 safe_browsing_check->full_hash_results[i] =
114 safe_browsing::SB_THREAT_TYPE_EXTENSION;
117 } 115 }
118 116
119 base::ThreadTaskRunnerHandle::Get()->PostTask( 117 base::ThreadTaskRunnerHandle::Get()->PostTask(
120 FROM_HERE, 118 FROM_HERE,
121 base::Bind(&FakeSafeBrowsingDatabaseManager::OnSafeBrowsingResult, this, 119 base::Bind(&FakeSafeBrowsingDatabaseManager::OnSafeBrowsingResult, this,
122 base::Passed(&safe_browsing_check))); 120 base::Passed(&safe_browsing_check)));
123 return false; 121 return false;
124 } 122 }
125 123
126 void FakeSafeBrowsingDatabaseManager::OnSafeBrowsingResult( 124 void FakeSafeBrowsingDatabaseManager::OnSafeBrowsingResult(
127 scoped_ptr<SafeBrowsingCheck> result) { 125 scoped_ptr<SafeBrowsingCheck> result) {
128 result->OnSafeBrowsingResult(); 126 result->OnSafeBrowsingResult();
129 } 127 }
130 128
131 } // namespace extensions 129 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698