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 #ifndef REMOTING_TEST_HOST_LIST_FETCHER_H_
6 #define REMOTING_TEST_HOST_LIST_FETCHER_H_
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "net/url_request/url_fetcher_delegate.h"
15 #include "remoting/test/host_info.h"
21 class URLRequestContextGetter
;
27 // Used by the HostlistFetcher to make HTTP requests and also by the
28 // unittests for this class to set fake response data for these URLs.
29 const char kHostListProdRequestUrl
[] = "https://www.googleapis.com/"
30 "chromoting/v1/@me/hosts";
32 // Requests a host list from the directory service for an access token.
33 // Destroying the RemoteHostInfoFetcher while a request is outstanding
34 // will cancel the request. It is safe to delete the fetcher from within a
35 // completion callback. Must be used from a thread running a message loop.
36 // The public method is virtual to allow for mocking and fakes.
37 class HostListFetcher
: public net::URLFetcherDelegate
{
40 ~HostListFetcher() override
;
42 // Supplied by the client for each hostlist request and returns a valid,
43 // initialized Hostlist object on success.
44 typedef base::Callback
<void(const std::vector
<HostInfo
>& hostlist
)>
47 // Makes a service call to retrieve a hostlist. The
48 // callback will be called once the HTTP request has completed.
49 virtual void RetrieveHostlist(const std::string
& access_token
,
50 const HostlistCallback
& callback
);
53 // Processes the response from the directory service.
54 bool ProcessResponse(std::vector
<HostInfo
>* hostlist
);
56 // net::URLFetcherDelegate interface.
57 void OnURLFetchComplete(const net::URLFetcher
* source
) override
;
59 // Holds the URLFetcher for the Host List request.
60 scoped_ptr
<net::URLFetcher
> request_
;
62 // Provides application-specific context for the network request.
63 scoped_refptr
<remoting::URLRequestContextGetter
> request_context_getter_
;
65 // Caller-supplied callback used to return hostlist on success.
66 HostlistCallback hostlist_callback_
;
68 DISALLOW_COPY_AND_ASSIGN(HostListFetcher
);
72 } // namespace remoting
74 #endif // REMOTING_TEST_HOST_LIST_FETCHER_H_