Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / net / proxy / proxy_resolver_factory.cc
blob8866b4b1ba8e17fbdf2470d9bccccfae609f1645
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"
10 namespace net {
11 namespace {
13 class Job : public ProxyResolverFactory::Request {
14 public:
15 Job(const scoped_refptr<ProxyResolverScriptData>& pac_script,
16 scoped_ptr<ProxyResolver> resolver,
17 scoped_ptr<ProxyResolver>* resolver_out,
18 const net::CompletionCallback& callback);
19 ~Job() override;
20 int Start();
22 private:
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_;
29 bool in_progress_;
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),
39 callback_(callback),
40 in_progress_(false) {
43 Job::~Job() {
44 if (in_progress_)
45 resolver_->CancelSetPacScript();
48 int Job::Start() {
49 int error = resolver_->SetPacScript(
50 pac_script_,
51 base::Bind(&Job::OnSetPacScriptDone, base::Unretained(this)));
52 if (error != ERR_IO_PENDING) {
53 if (error == OK)
54 *resolver_out_ = resolver_.Pass();
55 return error;
58 in_progress_ = true;
59 return ERR_IO_PENDING;
62 void Job::OnSetPacScriptDone(int error) {
63 if (error == OK)
64 *resolver_out_ = resolver_.Pass();
66 CompletionCallback callback = callback_;
67 in_progress_ = false;
68 if (!callback.is_null())
69 callback.Run(error);
72 } // namespace
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) {
93 scoped_ptr<Job> job(
94 new Job(pac_script, CreateProxyResolver(), resolver, callback));
95 int error = job->Start();
96 if (error != ERR_IO_PENDING)
97 return error;
99 *request = job.Pass();
100 return ERR_IO_PENDING;
103 } // namespace net