Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 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 "ssl_certificate_error_job.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/strings/stringprintf.h" | |
| 9 #include "base/thread_task_runner_handle.h" | |
| 10 #include "net/url_request/url_request.h" | |
| 11 #include "net/url_request/url_request_filter.h" | |
| 12 #include "net/url_request/url_request_interceptor.h" | |
| 13 | |
| 14 namespace cronet { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 const char kMockHostname[] = "mock.ssl.cert.error.request"; | |
| 19 | |
| 20 class MockJobInterceptor : public net::URLRequestInterceptor { | |
| 21 public: | |
| 22 MockJobInterceptor() {} | |
| 23 ~MockJobInterceptor() override {} | |
| 24 | |
| 25 // net::URLRequestJobFactory::ProtocolHandler implementation: | |
| 26 net::URLRequestJob* MaybeInterceptRequest( | |
| 27 net::URLRequest* request, | |
| 28 net::NetworkDelegate* network_delegate) const override { | |
| 29 return new SSLCertificateErrorJob(request, network_delegate); | |
| 30 } | |
| 31 | |
| 32 private: | |
| 33 DISALLOW_COPY_AND_ASSIGN(MockJobInterceptor); | |
| 34 }; | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 SSLCertificateErrorJob::SSLCertificateErrorJob( | |
| 39 net::URLRequest* request, | |
| 40 net::NetworkDelegate* network_delegate) | |
| 41 : net::URLRequestTestJob(request, network_delegate, "", "", true), | |
| 42 weak_factory_(this) { | |
| 43 } | |
| 44 | |
| 45 void SSLCertificateErrorJob::Start() { | |
| 46 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 47 FROM_HERE, base::Bind(&SSLCertificateErrorJob::NotifyError, | |
| 48 weak_factory_.GetWeakPtr())); | |
| 49 } | |
| 50 | |
| 51 void SSLCertificateErrorJob::NotifyError() { | |
| 52 net::SSLInfo info; | |
| 53 info.cert_status = net::CERT_STATUS_DATE_INVALID; | |
| 54 NotifySSLCertificateError(info, true); | |
| 55 } | |
| 56 | |
| 57 // static | |
| 58 void SSLCertificateErrorJob::AddUrlHandler() { | |
| 59 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); | |
| 60 filter->AddHostnameInterceptor( | |
| 61 "https", kMockHostname, | |
| 62 scoped_ptr<net::URLRequestInterceptor>(new MockJobInterceptor())); | |
| 63 } | |
| 64 | |
| 65 // static | |
|
mmenke
2015/07/17 19:29:59
"// static" is no longer needed before static meth
xunjieli
2015/07/17 20:15:20
Done.
| |
| 66 GURL SSLCertificateErrorJob::GetMockUrl() { | |
| 67 return GURL(base::StringPrintf("https://%s", kMockHostname)); | |
| 68 } | |
| 69 | |
| 70 SSLCertificateErrorJob::~SSLCertificateErrorJob() { | |
|
mmenke
2015/07/17 19:29:59
nit: Definition order should match the declaratio
xunjieli
2015/07/17 20:15:20
Done.
| |
| 71 } | |
| 72 | |
| 73 } // namespace net | |
| OLD | NEW |