Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #ifndef REMOTING_TEST_HOST_LIST_FETCHER_H_ | |
| 6 #define REMOTING_TEST_HOST_LIST_FETCHER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 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" | |
| 16 | |
| 17 namespace net { | |
| 18 class UrlFetcher; | |
| 19 } | |
| 20 namespace remoting { | |
| 21 class URLRequestContextGetter; | |
| 22 } | |
| 23 | |
| 24 namespace remoting { | |
| 25 namespace test { | |
| 26 | |
| 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"; | |
| 31 | |
| 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 { | |
| 38 public: | |
| 39 HostListFetcher(); | |
| 40 ~HostListFetcher() override; | |
| 41 | |
| 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)> | |
| 45 HostlistCallback; | |
| 46 | |
| 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); | |
| 51 | |
| 52 private: | |
| 53 // Processes the response from the directory service | |
|
joedow
2015/07/09 02:41:18
nit: add period to end of comment
tonychun
2015/07/09 03:02:46
Done.
| |
| 54 bool ProcessResponse(std::vector<HostInfo>* hostlist); | |
| 55 | |
| 56 // net::URLFetcherDelegate interface. | |
| 57 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 58 | |
| 59 // Holds the URLFetcher for the Host List request. | |
| 60 scoped_ptr<net::URLFetcher> request_; | |
| 61 | |
| 62 // Provides application-specific context for the network request. | |
| 63 scoped_refptr<remoting::URLRequestContextGetter> request_context_getter_; | |
| 64 | |
| 65 // Caller-supplied callback used to return hostlist on success. | |
| 66 HostlistCallback hostlist_callback_; | |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(HostListFetcher); | |
| 69 }; | |
| 70 | |
| 71 } // namespace test | |
| 72 } // namespace remoting | |
| 73 | |
| 74 #endif // REMOTING_TEST_HOST_LIST_FETCHER_H_ | |
| OLD | NEW |