Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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_CLIENT_IOS_FACADE_HOST_LIST_FETCHER_H_ | |
| 6 #define REMOTING_CLIENT_IOS_FACADE_HOST_LIST_FETCHER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/callback.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "base/memory/ref_counted.h" | |
| 15 #include "net/url_request/url_fetcher_delegate.h" | |
| 16 #include "net/url_request/url_request_context_getter.h" | |
| 17 #include "remoting/client/ios/facade/host_info.h" | |
| 18 | |
| 19 namespace remoting { | |
| 20 | |
| 21 // Used by the HostlistFetcher to make HTTP requests and also by the | |
| 22 // unittests for this class to set fake response data for these URLs. | |
| 23 const char kHostListProdRequestUrl[] = | |
| 24 "https://www.googleapis.com/" | |
| 25 "chromoting/v1/@me/hosts"; | |
|
joedow
2017/04/05 22:30:55
I don't think this line needs to be broken, looks
nicholss
2017/04/07 18:16:15
git cl format!!!
fixed.
| |
| 26 const char kHostListTestRequestUrl[] = | |
| 27 "https://www-googleapis-test.sandbox.google.com/chromoting/v1/@me/hosts"; | |
|
joedow
2017/04/05 22:30:55
Are you using this? I'd remove it if you don't in
nicholss
2017/04/07 18:16:15
I will remove this but I am going to add a todo to
| |
| 28 | |
| 29 // Requests a host list from the directory service for an access token. | |
| 30 // Destroying the RemoteHostInfoFetcher while a request is outstanding | |
| 31 // will cancel the request. It is safe to delete the fetcher from within a | |
| 32 // completion callback. Must be used from a thread running a message loop. | |
| 33 // The public method is virtual to allow for mocking and fakes. | |
| 34 class HostListFetcher : public net::URLFetcherDelegate { | |
| 35 public: | |
| 36 HostListFetcher(const scoped_refptr<net::URLRequestContextGetter>& | |
| 37 url_request_context_getter); | |
| 38 ~HostListFetcher() override; | |
| 39 | |
| 40 // Supplied by the client for each hostlist request and returns a valid, | |
| 41 // initialized Hostlist object on success. | |
| 42 typedef base::Callback<void(const std::vector<remoting::HostInfo>& hostlist)> | |
| 43 HostlistCallback; | |
| 44 | |
| 45 // Makes a service call to retrieve a hostlist. The | |
| 46 // callback will be called once the HTTP request has completed. | |
| 47 virtual void RetrieveHostlist(const std::string& access_token, | |
| 48 const HostlistCallback& callback); | |
| 49 | |
| 50 private: | |
| 51 // Processes the response from the directory service. | |
| 52 bool ProcessResponse(std::vector<remoting::HostInfo>* hostlist); | |
| 53 | |
| 54 // net::URLFetcherDelegate interface. | |
| 55 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 56 | |
| 57 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | |
| 58 | |
| 59 // Holds the URLFetcher for the Host List request. | |
| 60 std::unique_ptr<net::URLFetcher> request_; | |
| 61 | |
| 62 // Caller-supplied callback used to return hostlist on success. | |
| 63 HostlistCallback hostlist_callback_; | |
| 64 | |
| 65 DISALLOW_COPY_AND_ASSIGN(HostListFetcher); | |
| 66 }; | |
| 67 | |
| 68 } // namespace remoting | |
| 69 | |
| 70 #endif // REMOTING_CLIENT_IOS_FACADE_HOST_LIST_FETCHER_H_ | |
| OLD | NEW |