OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_LOOKUP_REQUEST_H_ | |
6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_LOOKUP_REQUEST_H_ | |
7 #pragma once | |
8 | |
9 #include "base/callback.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "net/base/address_list.h" | |
12 #include "net/base/host_resolver.h" | |
13 #include "net/base/net_errors.h" | |
14 #include "net/base/single_request_host_resolver.h" | |
15 | |
16 template<class T> | |
17 class PepperLookupRequest { | |
18 public: | |
19 typedef base::Callback<void(int, const net::AddressList&, const T&)> | |
20 LookupRequestCallback; | |
21 | |
22 // Takes ownership over |bound_info|. |bound_info| will be passed to | |
23 // callback, when lookup will finish. | |
24 PepperLookupRequest(net::HostResolver* resolver, | |
25 const net::HostResolver::RequestInfo& request_info, | |
26 T* bound_info, | |
27 const LookupRequestCallback& callback) | |
28 : resolver_(resolver), | |
29 request_info_(request_info), | |
30 bound_info_(bound_info), | |
31 callback_(callback) { | |
32 } | |
33 | |
34 void Start() { | |
35 int result = resolver_.Resolve( | |
36 request_info_, &addresses_, | |
37 base::Bind(&PepperLookupRequest<T>::OnLookupFinished, | |
38 base::Unretained(this)), | |
39 net::BoundNetLog()); | |
40 if (result != net::ERR_IO_PENDING) | |
41 OnLookupFinished(result); | |
42 } | |
43 | |
44 private: | |
45 void OnLookupFinished(int result) { | |
46 callback_.Run(result, addresses_, *bound_info_); | |
47 delete this; | |
48 } | |
49 | |
50 net::SingleRequestHostResolver resolver_; | |
51 net::HostResolver::RequestInfo request_info_; | |
52 scoped_ptr<T> bound_info_; | |
53 LookupRequestCallback callback_; | |
54 | |
55 net::AddressList addresses_; | |
56 | |
57 DISALLOW_COPY_AND_ASSIGN(PepperLookupRequest); | |
58 }; | |
59 | |
60 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_LOOKUP_REQUEST_H_ | |
OLD | NEW |