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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: remoting/test/chromoting_host_list_fetcher.h
diff --git a/remoting/test/chromoting_host_list_fetcher.h b/remoting/test/chromoting_host_list_fetcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..758e710f85c12a2a6a4bcd91742973ed4c503bbe
--- /dev/null
+++ b/remoting/test/chromoting_host_list_fetcher.h
@@ -0,0 +1,76 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_TEST_CHROMOTING_HOST_LIST_FETCHER_H_
+#define REMOTING_TEST_CHROMOTING_HOST_LIST_FETCHER_H_
+
+#include <string>
+#include <vector>
+
+#include "base/callback.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "net/url_request/url_fetcher_delegate.h"
+#include "remoting/test/chromoting_host_info.h"
+
+namespace net {
+class UrlFetcher;
+}
+namespace remoting {
+class URLRequestContextGetter;
+}
+
+namespace remoting {
+namespace test {
+
+// Used by the HostlistFetcher to make HTTP requests and also by the
+// unittests for this class to set fake response data for these URLs.
+const char kChromotingHostListProdRequestUrl[] = "https://www.googleapis.com/"
+ "chromoting/v1/@me/hosts";
+
+// Requests a host list from the Directory service for an access token.
+// Destroying the RemoteHostInfoFetcher while a request is outstanding
+// will cancel the request. It is safe to delete the fetcher from within a
+// completion callback. Must be used from a thread running an IO message loop.
+// The public method is virtual to allow for mocking and fakes.
+class ChromotingHostListFetcher : public net::URLFetcherDelegate {
+ public:
+ ChromotingHostListFetcher();
+ ~ChromotingHostListFetcher() override;
+
+ // Supplied by the client for each hostlist request and returns a valid,
+ // initialized Hostlist object on success.
+ typedef base::Callback<void(const std::vector<ChromotingHostInfo>& hostlist,
+ 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)
+ HostlistCallback;
+
+ // Makes a service call to retrieve a hostlist. The
+ // callback will be called once the HTTP request has completed.
+ virtual void RetrieveHostlist(const std::string& access_token,
+ const HostlistCallback& callback);
+
+ private:
+ // Provides the callback a way to distinguish between an empty list from a
+ // 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.
+ bool ProcessResponse(std::vector<ChromotingHostInfo>* hostlist);
+
+ // net::URLFetcherDelegate interface.
+ void OnURLFetchComplete(const net::URLFetcher* source) override;
+
+ // Holds the URLFetcher for the Chromoting Host List request.
+ scoped_ptr<net::URLFetcher> request_;
+
+ // Provides application-specific context for the network request.
+ scoped_refptr<remoting::URLRequestContextGetter> request_context_getter_;
+
+ // Caller-supplied callback used to return hostlist on success.
+ HostlistCallback hostlist_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromotingHostListFetcher);
+};
+
+} // namespace test
+} // namespace remoting
+
+#endif // REMOTING_TEST_CHROMOTING_HOST_LIST_FETCHER_H_

Powered by Google App Engine
This is Rietveld 408576698