Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: remoting/test/chromoting_host_list_fetcher.h

Issue 1212333011: Retrieved Hostlist information from Directory service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleaned up fetcher code and added more unit test coverage. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_CHROMOTING_HOST_LIST_FETCHER_H_
6 #define REMOTING_TEST_CHROMOTING_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/chromoting_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 kChromotingHostListProdRequestUrl[] = "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 an IO message loop.
36 // The public method is virtual to allow for mocking and fakes.
37 class ChromotingHostListFetcher : public net::URLFetcherDelegate {
38 public:
39 ChromotingHostListFetcher();
40 ~ChromotingHostListFetcher() 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<ChromotingHostInfo>& hostlist,
45 bool request_success)>
Sergey Ulanov 2015/07/08 19:57:34 nit: it's better to reverse the order of the param
tonychun 2015/07/08 22:38:16 I've decided to take this out for two reasons: 1)
46 HostlistCallback;
47
48 // Makes a service call to retrieve a hostlist. The
49 // callback will be called once the HTTP request has completed.
50 virtual void RetrieveHostlist(const std::string& access_token,
51 const HostlistCallback& callback);
52
53 private:
54 // Provides the callback a way to distinguish between an empty list from a
55 // a failed request.
joedow 2015/07/08 17:19:07 I think this comment is a little off, this functio
tonychun 2015/07/08 22:38:16 Done.
56 bool ProcessResponse(std::vector<ChromotingHostInfo>* hostlist);
57
58 // net::URLFetcherDelegate interface.
59 void OnURLFetchComplete(const net::URLFetcher* source) override;
60
61 // Holds the URLFetcher for the Chromoting Host List request.
62 scoped_ptr<net::URLFetcher> request_;
63
64 // Provides application-specific context for the network request.
65 scoped_refptr<remoting::URLRequestContextGetter> request_context_getter_;
66
67 // Caller-supplied callback used to return hostlist on success.
68 HostlistCallback hostlist_callback_;
69
70 DISALLOW_COPY_AND_ASSIGN(ChromotingHostListFetcher);
71 };
72
73 } // namespace test
74 } // namespace remoting
75
76 #endif // REMOTING_TEST_CHROMOTING_HOST_LIST_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698