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

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

Issue 49253005: Fetch extension blacklist states from SafeBrowsing server (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add unit tests, fix bugs. Created 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/test_blacklist_fetcher.h"
6
7 namespace extensions {
8 namespace {
9
10 static const char kUrlPrefix[] = "https://prefix.com/foo";
11 static const char kBackupConnectUrlPrefix[] = "https://alt1-prefix.com/foo";
12 static const char kBackupHttpUrlPrefix[] = "https://alt2-prefix.com/foo";
13 static const char kBackupNetworkUrlPrefix[] = "https://alt3-prefix.com/foo";
14 static const char kClient[] = "unittest";
15 static const char kAppVer[] = "1.0";
16
17 SafeBrowsingProtocolConfig CreateSafeBrowsingProtocolConfig() {
18 SafeBrowsingProtocolConfig config;
19 config.client_name = kClient;
20 config.url_prefix = kUrlPrefix;
21 config.backup_connect_error_url_prefix = kBackupConnectUrlPrefix;
22 config.backup_http_error_url_prefix = kBackupHttpUrlPrefix;
23 config.backup_network_error_url_prefix = kBackupNetworkUrlPrefix;
24 config.version = kAppVer;
25 return config;
26 }
27
28 } // namespace
29
30 TestBlacklistFetcher::TestBlacklistFetcher(BlacklistFetcher* fetcher)
31 : fetcher_(fetcher) {
32 fetcher_->SetSafeBrowsingConfig(CreateSafeBrowsingProtocolConfig());
33 }
34
35 void TestBlacklistFetcher::SetBlacklistVerdict(
36 const std::string& id, ClientCRXListInfoResponse_Verdict state) {
37 verdicts_[id] = state;
38 }
39
40 bool TestBlacklistFetcher::HandleFetcher(int fetcher_id) {
41 net::TestURLFetcher* url_fetcher = url_fetcher_factory_.GetFetcherByID(
42 fetcher_id);
43 if (!url_fetcher)
44 return false;
45
46 const std::string& request_str = url_fetcher->upload_data();
47 ClientCRXListInfoRequest request;
48 if (!request.ParseFromString(request_str))
49 return false;
50
51 std::string id = request.id();
52
53 ClientCRXListInfoResponse response;
54 if (verdicts_.find(id) != verdicts_.end())
55 response.set_verdict(verdicts_[id]);
56 else
57 response.set_verdict(ClientCRXListInfoResponse::UNKNOWN);
58
59 std::string response_str;
60 response.SerializeToString(&response_str);
61
62 url_fetcher->set_status(net::URLRequestStatus());
63 url_fetcher->set_response_code(200);
64 url_fetcher->SetResponseString(response_str);
65 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher);
66
67 return true;
68 }
69
70 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698