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.
5 #include "net/proxy/proxy_resolver_factory.h"
7 #include "net/base/net_errors.h"
8 #include "net/proxy/proxy_resolver.h"
13 class Job
: public ProxyResolverFactory::Request
{
15 Job(const scoped_refptr
<ProxyResolverScriptData
>& pac_script
,
16 scoped_ptr
<ProxyResolver
> resolver
,
17 scoped_ptr
<ProxyResolver
>* resolver_out
,
18 const net::CompletionCallback
& callback
);
23 void OnSetPacScriptDone(int error
);
25 const scoped_refptr
<ProxyResolverScriptData
> pac_script_
;
26 scoped_ptr
<ProxyResolver
> resolver_
;
27 scoped_ptr
<ProxyResolver
>* resolver_out_
;
28 const net::CompletionCallback callback_
;
32 Job::Job(const scoped_refptr
<ProxyResolverScriptData
>& pac_script
,
33 scoped_ptr
<ProxyResolver
> resolver
,
34 scoped_ptr
<ProxyResolver
>* resolver_out
,
35 const net::CompletionCallback
& callback
)
36 : pac_script_(pac_script
),
37 resolver_(resolver
.Pass()),
38 resolver_out_(resolver_out
),
45 resolver_
->CancelSetPacScript();
49 int error
= resolver_
->SetPacScript(
51 base::Bind(&Job::OnSetPacScriptDone
, base::Unretained(this)));
52 if (error
!= ERR_IO_PENDING
) {
54 *resolver_out_
= resolver_
.Pass();
59 return ERR_IO_PENDING
;
62 void Job::OnSetPacScriptDone(int error
) {
64 *resolver_out_
= resolver_
.Pass();
66 CompletionCallback callback
= callback_
;
68 if (!callback
.is_null())
74 ProxyResolverFactory::ProxyResolverFactory(bool expects_pac_bytes
)
75 : expects_pac_bytes_(expects_pac_bytes
) {
78 ProxyResolverFactory::~ProxyResolverFactory() {
81 LegacyProxyResolverFactory::LegacyProxyResolverFactory(bool expects_pac_bytes
)
82 : ProxyResolverFactory(expects_pac_bytes
) {
85 LegacyProxyResolverFactory::~LegacyProxyResolverFactory() {
88 int LegacyProxyResolverFactory::CreateProxyResolver(
89 const scoped_refptr
<ProxyResolverScriptData
>& pac_script
,
90 scoped_ptr
<ProxyResolver
>* resolver
,
91 const net::CompletionCallback
& callback
,
92 scoped_ptr
<ProxyResolverFactory::Request
>* request
) {
94 new Job(pac_script
, CreateProxyResolver(), resolver
, callback
));
95 int error
= job
->Start();
96 if (error
!= ERR_IO_PENDING
)
99 *request
= job
.Pass();
100 return ERR_IO_PENDING
;