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

Side by Side Diff: chrome/browser/safe_browsing/remote_database_manager.cc

Issue 1110723002: Split to SafeBrowsingDatabaseManager into Local* and Remote*. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move delegate mgmt to sb service. Use weak_ptr for ClientRequest Created 5 years, 7 months 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
(Empty)
1 // Copyright (c) 2015 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/remote_database_manager.h"
6
7 #include <vector>
8
9 #include "chrome/browser/safe_browsing/android_safe_browsing_api_handler.h"
10 #include "content/public/browser/browser_thread.h"
11
12 using content::BrowserThread;
13
14 // TODO(nparker): Add tests for this class once implemented.
15 RemoteSafeBrowsingDatabaseManager::RemoteSafeBrowsingDatabaseManager()
16 : enabled_(false) {
17 DCHECK_CURRENTLY_ON(BrowserThread::UI);
18 // TODO(nparker): Implement the initialization glue.
19 // Check flag to see if this is enabled.
20 // Ask AndroidSafeBrowsingAPIHandler if Java API is correct version.
21 }
22
23 RemoteSafeBrowsingDatabaseManager::~RemoteSafeBrowsingDatabaseManager() {
24 DCHECK(!enabled_);
25 }
26
27 bool RemoteSafeBrowsingDatabaseManager::CanCheckUrl(const GURL& url) const {
28 return url.SchemeIs(url::kHttpsScheme) || url.SchemeIs(url::kHttpScheme) ||
29 url.SchemeIs(url::kFtpScheme);
30 }
31
32 bool RemoteSafeBrowsingDatabaseManager::download_protection_enabled()
33 const {
34 return false;
35 }
36
37 bool RemoteSafeBrowsingDatabaseManager::CheckDownloadUrl(
38 const std::vector<GURL>& url_chain,
39 Client* client) {
40 NOTREACHED();
41 return true;
42 }
43
44 bool RemoteSafeBrowsingDatabaseManager::CheckExtensionIDs(
45 const std::set<std::string>& extension_ids,
46 Client* client) {
47 NOTREACHED();
48 return true;
49 }
50
51 bool RemoteSafeBrowsingDatabaseManager::MatchMalwareIP(
52 const std::string& ip_address) {
53 NOTREACHED();
54 return false;
55 }
56
57 bool RemoteSafeBrowsingDatabaseManager::MatchCsdWhitelistUrl(const GURL& url) {
58 NOTREACHED();
59 return true;
60 }
61
62 bool RemoteSafeBrowsingDatabaseManager::MatchDownloadWhitelistUrl(
63 const GURL& url) {
64 NOTREACHED();
65 return true;
66 }
67
68 bool RemoteSafeBrowsingDatabaseManager::MatchDownloadWhitelistString(
69 const std::string& str) {
70 NOTREACHED();
71 return true;
72 }
73
74 bool RemoteSafeBrowsingDatabaseManager::MatchInclusionWhitelistUrl(
75 const GURL& url) {
76 NOTREACHED();
77 return true;
78 }
79
80 bool RemoteSafeBrowsingDatabaseManager::IsMalwareKillSwitchOn() {
81 NOTREACHED();
82 return true;
83 }
84
85 bool RemoteSafeBrowsingDatabaseManager::IsCsdWhitelistKillSwitchOn() {
86 NOTREACHED();
87 return true;
88 }
89
90 bool RemoteSafeBrowsingDatabaseManager::CheckBrowseUrl(const GURL& url,
91 Client* client) {
92 DCHECK_CURRENTLY_ON(BrowserThread::IO);
93 if (!enabled_)
94 return true;
95
96 if (!CanCheckUrl(url))
97 return true; // Safe, continue right away.
98
99 scoped_ptr<ClientRequest> req(new ClientRequest());
100 req->db_manager_ = this;
101 req->client_ = client;
102 req->url_ = url;
mattm 2015/05/08 02:17:26 could just have ClientRequest constructor take the
Nathan Parker 2015/05/12 01:04:01 Done, while making them private.
103
104 std::vector<SBThreatType> threat_types { SB_THREAT_TYPE_URL_MALWARE };
105
106 VLOG(1) << "Checking for client " << client << " and URL " << url;
107 bool started =
108 api_handler_.StartURLCheck(base::Bind(&ClientRequest::OnRequestDoneWeak,
109 req->weak_factory_.GetWeakPtr()),
110 url, threat_types);
111 if (!started) {
112 LOG(DFATAL) << "Failed to start Safe Browsing request";
113 return true;
114 }
115
116 current_requests_.push_back(req.release());
117
118 // Defer the resource load.
119 return false;
120 }
121
122 void RemoteSafeBrowsingDatabaseManager::CancelCheck(Client* client) {
123 DCHECK_CURRENTLY_ON(BrowserThread::IO);
124 DCHECK(enabled_);
125 for (auto itr = current_requests_.begin(); itr != current_requests_.end();
126 ++itr) {
127 if ((*itr)->client_ == client) {
128 VLOG(1) << "Canceling check for URL " << (*itr)->url_;
129 delete *itr;
130 current_requests_.erase(itr);
131 return;
132 }
133 }
134 NOTREACHED();
135 }
136
137 void RemoteSafeBrowsingDatabaseManager::StartOnIOThread() {
138 VLOG(1) << "RemoteSafeBrowsing starting";
139 enabled_ = true;
140 }
141
142 void RemoteSafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) {
143 // |shutdown| is not used.
144 DCHECK_CURRENTLY_ON(BrowserThread::IO);
145 VLOG(1) << "RemoteSafeBrowsing stopping";
146
147 // Call back and delete any remaining clients. OnRequestDone() modifies
148 // |current_requests_|, so we make a copy first.
149 std::vector<ClientRequest*> to_callback(current_requests_);
150 for (auto req : to_callback) {
151 VLOG(1) << "Stopping: Invoking unfinished req for URL " << req->url_;
152 req->OnRequestDone(SB_THREAT_TYPE_SAFE, std::string());
153 }
154 enabled_ = false;
155 }
156
157 //
158 // RemoteSafeBrowsingDatabaseManager::ClientRequest methods
159 //
160
161 // Static
162 void RemoteSafeBrowsingDatabaseManager::ClientRequest::OnRequestDoneWeak(
163 const base::WeakPtr<ClientRequest>& req,
164 SBThreatType matched_threat_type,
165 const std::string& metadata) {
166 DCHECK_CURRENTLY_ON(BrowserThread::IO);
167 if (!req)
168 return; // Previously canceled
169 req->OnRequestDone(matched_threat_type, metadata);
170 }
171
172 void RemoteSafeBrowsingDatabaseManager::ClientRequest::OnRequestDone(
173 SBThreatType matched_threat_type,
174 const std::string& metadata) {
175 VLOG(1) << "OnRequestDone for client " << client_ << " and URL " << url_;
176 client_->OnCheckBrowseUrlResult(url_, matched_threat_type, metadata);
177 db_manager_->CancelCheck(client_);
178 }
179
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698