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_
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"
20 class URLRequestContextGetter
;
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";
34 const char kStagingServiceEnvironmentUrlFormat
[] =
35 "https://www-googleapis-test.sandbox.google.com/appremoting/"
36 "v1beta1_staging/applications/%s/run";
38 // Specifies the service API to call for app remoting host information.
39 // Note: When adding new environments, add them before kUnknownEnvironment as
40 // the last entry is used for bounds checking.
41 enum ServiceEnvironment
{
42 kDeveloperEnvironment
,
48 // Supplied by the client for each remote host info request and returns a valid,
49 // initialized RemoteHostInfo object on success.
50 typedef base::Callback
<void(const RemoteHostInfo
& remote_host_info
)>
51 RemoteHostInfoCallback
;
53 // Calls the App Remoting service API to request connection info for a remote
54 // host. Destroying the RemoteHostInfoFetcher while a request is outstanding
55 // will cancel the request. It is safe to delete the fetcher from within a
56 // completion callback. Must be used from a thread running an IO message loop.
57 // The public method is virtual to allow for mocking and fakes.
58 class RemoteHostInfoFetcher
: public net::URLFetcherDelegate
{
60 RemoteHostInfoFetcher();
61 ~RemoteHostInfoFetcher() override
;
63 // Makes a service call to retrieve the details for a remote host. The
64 // callback will be called once the HTTP request has completed.
65 virtual bool RetrieveRemoteHostInfo(const std::string
& application_id
,
66 const std::string
& access_token
,
67 ServiceEnvironment service_environment
,
68 const RemoteHostInfoCallback
& callback
);
71 // net::URLFetcherDelegate interface.
72 void OnURLFetchComplete(const net::URLFetcher
* source
) override
;
74 // Holds the URLFetcher for the RemoteHostInfo request.
75 scoped_ptr
<net::URLFetcher
> request_
;
77 // Provides application-specific context for the network request.
78 scoped_refptr
<remoting::URLRequestContextGetter
> request_context_getter_
;
80 // Caller-supplied callback used to return remote host info on success.
81 RemoteHostInfoCallback remote_host_info_callback_
;
83 DISALLOW_COPY_AND_ASSIGN(RemoteHostInfoFetcher
);
87 } // namespace remoting
89 #endif // REMOTING_TEST_REMOTE_HOST_INFO_FETCHER_H_