OLD | NEW |
---|---|
(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 api_handler_(new AndroidSafeBrowsingAPIHandler()), | |
18 weak_ptr_factory_(this) { | |
19 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
20 VLOG(1) << "RemoteSafeBrowsing selected."; | |
21 // TODO(nparker): Implement the initialization glue. | |
22 // Check flag to see if this is enabled. | |
23 // Ask AndroidSafeBrowsingAPIHandler if Java API is correct version. | |
24 } | |
25 | |
26 RemoteSafeBrowsingDatabaseManager::~RemoteSafeBrowsingDatabaseManager() { | |
27 DCHECK(!enabled_); | |
28 } | |
29 | |
30 bool RemoteSafeBrowsingDatabaseManager::CanCheckUrl(const GURL& url) const { | |
31 return url.SchemeIs(url::kHttpsScheme) || url.SchemeIs(url::kHttpScheme) || | |
32 url.SchemeIs(url::kFtpScheme); | |
33 } | |
34 | |
35 bool RemoteSafeBrowsingDatabaseManager::CheckDownloadUrl( | |
36 const std::vector<GURL>& url_chain, | |
37 Client* client) { | |
38 DCHECK(false) << "Not available in this implementation."; | |
mattm
2015/04/29 22:59:59
how about just make these NOTREACHED?
Nathan Parker
2015/05/04 21:17:19
Done.
| |
39 return true; | |
40 } | |
41 | |
42 bool RemoteSafeBrowsingDatabaseManager::CheckExtensionIDs( | |
43 const std::set<std::string>& extension_ids, | |
44 Client* client) { | |
45 DCHECK(false) << "Not available in this implementation."; | |
46 return true; | |
47 } | |
48 | |
49 bool RemoteSafeBrowsingDatabaseManager::MatchMalwareIP( | |
50 const std::string& ip_address) { | |
51 DCHECK(false) << "Not available in this implementation."; | |
52 return false; | |
53 } | |
54 | |
55 bool RemoteSafeBrowsingDatabaseManager::MatchCsdWhitelistUrl(const GURL& url) { | |
56 DCHECK(false) << "Not available in this implementation."; | |
57 return true; | |
58 } | |
59 | |
60 bool RemoteSafeBrowsingDatabaseManager::MatchDownloadWhitelistUrl( | |
61 const GURL& url) { | |
62 DCHECK(false) << "Not available in this implementation."; | |
63 return true; | |
64 } | |
65 | |
66 bool RemoteSafeBrowsingDatabaseManager::MatchDownloadWhitelistString( | |
67 const std::string& str) { | |
68 DCHECK(false) << "Not available in this implementation."; | |
69 return true; | |
70 } | |
71 | |
72 bool RemoteSafeBrowsingDatabaseManager::MatchInclusionWhitelistUrl( | |
73 const GURL& url) { | |
74 DCHECK(false) << "Not available in this implementation."; | |
75 return true; | |
76 } | |
77 | |
78 bool RemoteSafeBrowsingDatabaseManager::IsMalwareKillSwitchOn() { | |
79 DCHECK(false) << "Not available in this implementation."; | |
80 return true; | |
81 } | |
82 | |
83 bool RemoteSafeBrowsingDatabaseManager::IsCsdWhitelistKillSwitchOn() { | |
84 DCHECK(false) << "Not available in this implementation."; | |
85 return true; | |
86 } | |
87 | |
88 bool RemoteSafeBrowsingDatabaseManager::CheckBrowseUrl(const GURL& url, | |
89 Client* client) { | |
90 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
91 if (!enabled_) | |
92 return true; | |
93 | |
94 if (!CanCheckUrl(url)) | |
95 return true; // Safe, continue right away. | |
96 | |
97 ClientRequest* req = new ClientRequest(); | |
98 req->db_manager = weak_ptr_factory_.GetWeakPtr(); | |
99 req->url = url; | |
100 req->client = client; | |
101 | |
102 VLOG(1) << "Checking URL " << url; | |
103 DCHECK(api_handler_->StartRequest(req)) << "Request failed to start"; | |
mattm
2015/04/29 22:59:59
don't put real code in a DCHECK
Nathan Parker
2015/05/04 21:17:19
Indeed. Fixed.
| |
104 current_requests_.insert(req); | |
105 | |
106 // Defer the resource load. | |
107 return false; | |
108 } | |
109 | |
110 void RemoteSafeBrowsingDatabaseManager::CancelCheck(Client* client) { | |
111 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
112 DCHECK(enabled_); | |
113 std::vector<ClientRequest*> to_delete; | |
mattm
2015/04/29 22:59:59
Doesn't actually delete here. Maybe to_remove?
Nathan Parker
2015/05/04 21:17:19
I've refactored this since it's now a vector of sc
| |
114 for (auto req : current_requests_) { | |
115 if (req->client == client) { | |
116 // This will indicate to the api_handler that the request is canceled. | |
117 req->client = NULL; | |
118 to_delete.push_back(req); | |
119 VLOG(1) << "Canceling check for URL " << req->url; | |
120 } | |
121 } | |
122 // There should be exactly one active request per client. Old requests | |
123 // from this client may still be pending, but they will have their client | |
124 // field cleared previously when canceled. | |
125 DCHECK(to_delete.size() == 1); | |
126 for (auto req : to_delete) { | |
127 current_requests_.erase(req); | |
128 } | |
129 } | |
130 | |
131 void RemoteSafeBrowsingDatabaseManager::StartOnIOThread() { | |
132 VLOG(1) << "RemoteSafeBrowsing starting"; | |
133 enabled_ = true; | |
134 } | |
135 | |
136 void RemoteSafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { | |
137 // |shutdown| is not used. | |
138 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
139 VLOG(1) << "RemoteSafeBrowsing stopping"; | |
140 | |
141 // Call back any remaining clients. | |
142 for (auto req : current_requests_) { | |
143 if (req->client) { | |
144 VLOG(1) << "Stopping: Canceling req for URL " << req->url; | |
145 req->client->OnCheckBrowseUrlResult(req->url, SB_THREAT_TYPE_SAFE, ""); | |
146 req->client = NULL; | |
147 } | |
148 } | |
149 enabled_ = false; | |
150 } | |
151 | |
OLD | NEW |