[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / content / browser / renderer_host / pepper / pepper_lookup_request.h
blobf5723e5edc27a84600c3892b050d568db6c2ba27
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 "base/profiler/scoped_tracker.h"
11 #include "net/base/address_list.h"
12 #include "net/base/net_errors.h"
13 #include "net/dns/host_resolver.h"
14 #include "net/dns/single_request_host_resolver.h"
16 namespace content {
18 template <class T>
19 class PepperLookupRequest {
20 public:
21 typedef base::Callback<void(int, const net::AddressList&, const T&)>
22 LookupRequestCallback;
24 // Takes ownership over |bound_info|. |bound_info| will be passed to
25 // callback, when lookup will finish.
26 PepperLookupRequest(net::HostResolver* resolver,
27 const net::HostResolver::RequestInfo& request_info,
28 net::RequestPriority priority,
29 T* bound_info,
30 const LookupRequestCallback& callback)
31 : resolver_(resolver),
32 request_info_(request_info),
33 priority_(priority),
34 bound_info_(bound_info),
35 callback_(callback) {}
37 void Start() {
38 int result =
39 resolver_.Resolve(request_info_,
40 priority_,
41 &addresses_,
42 base::Bind(&PepperLookupRequest<T>::OnLookupFinished,
43 base::Unretained(this)),
44 net::BoundNetLog());
45 if (result != net::ERR_IO_PENDING)
46 OnLookupFinished(result);
49 private:
50 void OnLookupFinished(int result) {
51 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed.
52 tracked_objects::ScopedTracker tracking_profile(
53 FROM_HERE_WITH_EXPLICIT_FUNCTION(
54 "436634 PepperLookupRequest::OnLookupFinished"));
56 callback_.Run(result, addresses_, *bound_info_);
57 delete this;
60 net::SingleRequestHostResolver resolver_;
61 net::HostResolver::RequestInfo request_info_;
62 net::RequestPriority priority_;
63 scoped_ptr<T> bound_info_;
64 LookupRequestCallback callback_;
66 net::AddressList addresses_;
68 DISALLOW_COPY_AND_ASSIGN(PepperLookupRequest);
71 } // namespace content
73 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_LOOKUP_REQUEST_H_