Fix mouse warp with 2x displays
[chromium-blink-merge.git] / remoting / host / gcd_rest_client.h
blobe83b1fd19037b2759e20e40bccfcdfee15be781f
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_HOST_GCD_REST_CLIENT_H_
6 #define REMOTING_HOST_GCD_REST_CLIENT_H_
8 #include <queue>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time/clock.h"
14 #include "net/url_request/url_fetcher_delegate.h"
15 #include "remoting/base/url_request_context_getter.h"
16 #include "remoting/host/oauth_token_getter.h"
18 namespace base {
19 class DictionaryValue;
20 } // namespace base
22 namespace remoting {
24 // A client for calls to the GCD REST API.
25 class GcdRestClient : public net::URLFetcherDelegate {
26 public:
27 // Result of a GCD call.
28 enum Result {
29 SUCCESS,
30 NETWORK_ERROR,
31 NO_SUCH_HOST,
32 OTHER_ERROR,
35 typedef base::Callback<void(Result result)> ResultCallback;
37 // Note: |token_getter| must outlive this object.
38 GcdRestClient(const std::string& gcd_base_url,
39 const std::string& gcd_device_id,
40 const scoped_refptr<net::URLRequestContextGetter>&
41 url_request_context_getter,
42 OAuthTokenGetter* token_getter);
44 ~GcdRestClient() override;
46 // Tests whether is object is currently running a request. Only one
47 // request at a time may be pending.
48 bool HasPendingRequest() { return url_fetcher_; }
50 // Sends a 'patchState' request to the GCD API. Constructs and
51 // sends an appropriate JSON message M where |patch_details| becomes
52 // the value of M.patches[0].patch.
53 void PatchState(scoped_ptr<base::DictionaryValue> patch_details,
54 const GcdRestClient::ResultCallback& callback);
56 void SetClockForTest(scoped_ptr<base::Clock> clock) { clock_ = clock.Pass(); }
58 private:
59 void OnTokenReceived(OAuthTokenGetter::Status status,
60 const std::string& user_email,
61 const std::string& access_token);
62 void FinishCurrentRequest(Result result);
64 // URLFetcherDelegate interface.
65 void OnURLFetchComplete(const net::URLFetcher* source) override;
67 std::string gcd_base_url_;
68 std::string gcd_device_id_;
69 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
70 OAuthTokenGetter* token_getter_;
71 scoped_ptr<base::Clock> clock_;
72 scoped_ptr<net::URLFetcher> url_fetcher_;
73 ResultCallback callback_;
75 DISALLOW_COPY_AND_ASSIGN(GcdRestClient);
78 } // namespace remoting
80 #endif // REMOTING_HOST_GCD_REST_CLIENT_H_