Compute can_use_lcd_text using property trees.
[chromium-blink-merge.git] / remoting / host / gcd_rest_client.h
blobaf83f057e95a470457d159d77472d966658a6be7
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/memory/weak_ptr.h"
14 #include "base/time/clock.h"
15 #include "net/url_request/url_fetcher_delegate.h"
16 #include "net/url_request/url_fetcher_factory.h"
17 #include "remoting/base/url_request_context_getter.h"
18 #include "remoting/host/oauth_token_getter.h"
20 namespace base {
21 class DictionaryValue;
22 } // namespace base
24 namespace remoting {
26 // A client for calls to the GCD REST API.
27 class GcdRestClient : public net::URLFetcherDelegate {
28 public:
29 // Result of a GCD call.
30 enum Status {
31 SUCCESS,
32 NETWORK_ERROR,
33 NO_SUCH_HOST,
34 OTHER_ERROR,
37 typedef base::Callback<void(Status status)> PatchStateCallback;
39 // Note: |token_getter|, |url_fetcher_factory|, and |clock| must
40 // outlive this object.
41 GcdRestClient(const std::string& gcd_base_url,
42 const std::string& gcd_device_id,
43 const scoped_refptr<net::URLRequestContextGetter>&
44 url_request_context_getter,
45 OAuthTokenGetter* token_getter);
47 ~GcdRestClient() override;
49 // Sends a 'patchState' request to the GCD API. Constructs and
50 // sends an appropriate JSON message M where |patch_details| becomes
51 // the value of M.patches[0].patch.
52 void PatchState(scoped_ptr<base::DictionaryValue> patch_details,
53 const GcdRestClient::PatchStateCallback& callback);
55 void SetClockForTest(scoped_ptr<base::Clock> clock) { clock_ = clock.Pass(); }
57 private:
58 struct PatchStateRequest;
60 void StartNextRequest();
61 void OnTokenReceived(OAuthTokenGetter::Status status,
62 const std::string& user_email,
63 const std::string& access_token);
64 void FinishCurrentRequest(Status result);
66 // URLFetcherDelegate interface.
67 void OnURLFetchComplete(const net::URLFetcher* source) override;
69 std::string gcd_base_url_;
70 std::string gcd_device_id_;
71 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
72 OAuthTokenGetter* token_getter_;
73 scoped_ptr<base::Clock> clock_;
74 scoped_ptr<PatchStateRequest> current_request_;
76 // Ideally this queue would contain instances of scoped_ptr, but the
77 // Mac C++ compiler doesn't like that.
78 std::queue<PatchStateRequest*> pending_requests_;
80 base::WeakPtrFactory<GcdRestClient> weak_factory_;
82 DISALLOW_COPY_AND_ASSIGN(GcdRestClient);
85 } // namespace remoting
87 #endif // REMOTING_HOST_GCD_REST_CLIENT_H_