Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / renderer_host / pepper / pepper_lookup_request.h
blobb36bd5e2f4e929bbd98c06e959bfb48f0dc4c20d
1 // Copyright (c) 2012 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_LOOKUP_REQUEST_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_LOOKUP_REQUEST_H_
8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "net/base/address_list.h"
11 #include "net/base/net_errors.h"
12 #include "net/dns/host_resolver.h"
13 #include "net/dns/single_request_host_resolver.h"
15 namespace content {
17 template <class T>
18 class PepperLookupRequest {
19 public:
20 typedef base::Callback<void(int, const net::AddressList&, const T&)>
21 LookupRequestCallback;
23 // Takes ownership over |bound_info|. |bound_info| will be passed to
24 // callback, when lookup will finish.
25 PepperLookupRequest(net::HostResolver* resolver,
26 const net::HostResolver::RequestInfo& request_info,
27 net::RequestPriority priority,
28 T* bound_info,
29 const LookupRequestCallback& callback)
30 : resolver_(resolver),
31 request_info_(request_info),
32 priority_(priority),
33 bound_info_(bound_info),
34 callback_(callback) {}
36 void Start() {
37 int result =
38 resolver_.Resolve(request_info_,
39 priority_,
40 &addresses_,
41 base::Bind(&PepperLookupRequest<T>::OnLookupFinished,
42 base::Unretained(this)),
43 net::BoundNetLog());
44 if (result != net::ERR_IO_PENDING)
45 OnLookupFinished(result);
48 private:
49 void OnLookupFinished(int result) {
50 callback_.Run(result, addresses_, *bound_info_);
51 delete this;
54 net::SingleRequestHostResolver resolver_;
55 net::HostResolver::RequestInfo request_info_;
56 net::RequestPriority priority_;
57 scoped_ptr<T> bound_info_;
58 LookupRequestCallback callback_;
60 net::AddressList addresses_;
62 DISALLOW_COPY_AND_ASSIGN(PepperLookupRequest);
65 } // namespace content
67 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_LOOKUP_REQUEST_H_