Home | History | Annotate | Download | only in proxy
      1 // Copyright (c) 2011 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 NET_PROXY_SYNC_HOST_RESOLVER_BRIDGE_H_
      6 #define NET_PROXY_SYNC_HOST_RESOLVER_BRIDGE_H_
      7 #pragma once
      8 
      9 #include "base/memory/scoped_ptr.h"
     10 #include "net/base/host_resolver.h"
     11 
     12 class MessageLoop;
     13 
     14 namespace net {
     15 
     16 // Wrapper around HostResolver to give a sync API while running the resolver
     17 // in async mode on |host_resolver_loop|.
     18 class SyncHostResolverBridge : public HostResolver {
     19  public:
     20   SyncHostResolverBridge(HostResolver* host_resolver,
     21                          MessageLoop* host_resolver_loop);
     22 
     23   virtual ~SyncHostResolverBridge();
     24 
     25   // HostResolver methods:
     26   virtual int Resolve(const RequestInfo& info,
     27                       AddressList* addresses,
     28                       CompletionCallback* callback,
     29                       RequestHandle* out_req,
     30                       const BoundNetLog& net_log);
     31   virtual void CancelRequest(RequestHandle req);
     32   virtual void AddObserver(Observer* observer);
     33   virtual void RemoveObserver(Observer* observer);
     34 
     35   // The Shutdown() method should be called prior to destruction, from
     36   // |host_resolver_loop_|. It aborts any in progress synchronous resolves, to
     37   // prevent deadlocks from happening.
     38   virtual void Shutdown();
     39 
     40  private:
     41   class Core;
     42 
     43   MessageLoop* const host_resolver_loop_;
     44   scoped_refptr<Core> core_;
     45 };
     46 
     47 }  // namespace net
     48 
     49 #endif  // NET_PROXY_SYNC_HOST_RESOLVER_BRIDGE_H_
     50