Delete unused Android resources.
[chromium-blink-merge.git] / remoting / test / remote_host_info_fetcher.h
blob83e8b32016e91b5ed6af22e2fca2956895806ff4
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_REMOTE_HOST_INFO_FETCHER_H_
6 #define REMOTING_TEST_REMOTE_HOST_INFO_FETCHER_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "net/url_request/url_fetcher_delegate.h"
14 #include "remoting/test/remote_host_info.h"
16 namespace net {
17 class UrlFetcher;
19 namespace remoting {
20 class URLRequestContextGetter;
23 namespace remoting {
24 namespace test {
26 // Used by the RemoteHostInfoFetcher to make HTTP requests and also by the
27 // unittests for this class to set fake response data for these URLs.
28 const char kDevServiceEnvironmentUrlFormat[] =
29 "https://www-googleapis-test.sandbox.google.com/appremoting/v1beta1_dev/"
30 "applications/%s/run";
31 const char kTestServiceEnvironmentUrlFormat[] =
32 "https://www-googleapis-test.sandbox.google.com/appremoting/v1beta1/"
33 "applications/%s/run";
35 // Specifies the service API to call for app remoting host information.
36 // Note: When adding new environments, add them before kUnknownEnvironment as
37 // the last entry is used for bounds checking.
38 enum ServiceEnvironment {
39 kDeveloperEnvironment,
40 kTestingEnvironment,
41 kUnknownEnvironment
44 // Supplied by the client for each remote host info request and returns a valid,
45 // initialized RemoteHostInfo object on success.
46 typedef base::Callback<void(const RemoteHostInfo& remote_host_info)>
47 RemoteHostInfoCallback;
49 // Calls the App Remoting service API to request connection info for a remote
50 // host. Destroying the RemoteHostInfoFetcher while a request is outstanding
51 // will cancel the request. It is safe to delete the fetcher from within a
52 // completion callback. Must be used from a thread running an IO message loop.
53 // The public method is virtual to allow for mocking and fakes.
54 class RemoteHostInfoFetcher : public net::URLFetcherDelegate {
55 public:
56 RemoteHostInfoFetcher();
57 ~RemoteHostInfoFetcher() override;
59 // Makes a service call to retrieve the details for a remote host. The
60 // callback will be called once the HTTP request has completed.
61 virtual bool RetrieveRemoteHostInfo(const std::string& application_id,
62 const std::string& access_token,
63 ServiceEnvironment service_environment,
64 const RemoteHostInfoCallback& callback);
66 private:
67 // net::URLFetcherDelegate interface.
68 void OnURLFetchComplete(const net::URLFetcher* source) override;
70 // Holds the URLFetcher for the RemoteHostInfo request.
71 scoped_ptr<net::URLFetcher> request_;
73 // Provides application-specific context for the network request.
74 scoped_refptr<remoting::URLRequestContextGetter> request_context_getter_;
76 // Caller-supplied callback used to return remote host info on success.
77 RemoteHostInfoCallback remote_host_info_callback_;
79 DISALLOW_COPY_AND_ASSIGN(RemoteHostInfoFetcher);
82 } // namespace test
83 } // namespace remoting
85 #endif // REMOTING_TEST_REMOTE_HOST_INFO_FETCHER_H_