OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/host/gcd_rest_client.h" | 5 #include "remoting/host/gcd_rest_client.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 OAuthTokenGetter* token_getter) | 27 OAuthTokenGetter* token_getter) |
28 : gcd_base_url_(gcd_base_url), | 28 : gcd_base_url_(gcd_base_url), |
29 gcd_device_id_(gcd_device_id), | 29 gcd_device_id_(gcd_device_id), |
30 url_request_context_getter_(url_request_context_getter), | 30 url_request_context_getter_(url_request_context_getter), |
31 token_getter_(token_getter), | 31 token_getter_(token_getter), |
32 clock_(new base::DefaultClock) {} | 32 clock_(new base::DefaultClock) {} |
33 | 33 |
34 GcdRestClient::~GcdRestClient() {} | 34 GcdRestClient::~GcdRestClient() {} |
35 | 35 |
36 void GcdRestClient::PatchState( | 36 void GcdRestClient::PatchState( |
37 scoped_ptr<base::DictionaryValue> patch_details, | 37 std::unique_ptr<base::DictionaryValue> patch_details, |
38 const GcdRestClient::ResultCallback& callback) { | 38 const GcdRestClient::ResultCallback& callback) { |
39 DCHECK(!HasPendingRequest()); | 39 DCHECK(!HasPendingRequest()); |
40 | 40 |
41 // Construct a status update message in the format GCD expects. The | 41 // Construct a status update message in the format GCD expects. The |
42 // message looks like this, where "..." is filled in from | 42 // message looks like this, where "..." is filled in from |
43 // |patch_details|: | 43 // |patch_details|: |
44 // | 44 // |
45 // { | 45 // { |
46 // requestTimeMs: T, | 46 // requestTimeMs: T, |
47 // patches: [{ | 47 // patches: [{ |
48 // timeMs: T, | 48 // timeMs: T, |
49 // patch: {...} | 49 // patch: {...} |
50 // }] | 50 // }] |
51 // } | 51 // } |
52 // | 52 // |
53 // Note that |now| is deliberately using a double to hold an integer | 53 // Note that |now| is deliberately using a double to hold an integer |
54 // value because |DictionaryValue| doesn't support int64_t values, and | 54 // value because |DictionaryValue| doesn't support int64_t values, and |
55 // GCD doesn't accept fractional values. | 55 // GCD doesn't accept fractional values. |
56 double now = clock_->Now().ToJavaTime(); | 56 double now = clock_->Now().ToJavaTime(); |
57 scoped_ptr<base::DictionaryValue> patch_dict(new base::DictionaryValue); | 57 std::unique_ptr<base::DictionaryValue> patch_dict(new base::DictionaryValue); |
58 patch_dict->SetDouble("requestTimeMs", now); | 58 patch_dict->SetDouble("requestTimeMs", now); |
59 scoped_ptr<base::ListValue> patch_list(new base::ListValue); | 59 std::unique_ptr<base::ListValue> patch_list(new base::ListValue); |
60 base::DictionaryValue* patch_item = new base::DictionaryValue; | 60 base::DictionaryValue* patch_item = new base::DictionaryValue; |
61 patch_list->Append(patch_item); | 61 patch_list->Append(patch_item); |
62 patch_item->Set("patch", std::move(patch_details)); | 62 patch_item->Set("patch", std::move(patch_details)); |
63 patch_item->SetDouble("timeMs", now); | 63 patch_item->SetDouble("timeMs", now); |
64 patch_dict->Set("patches", std::move(patch_list)); | 64 patch_dict->Set("patches", std::move(patch_list)); |
65 | 65 |
66 // Stringify the message. | 66 // Stringify the message. |
67 std::string patch_string; | 67 std::string patch_string; |
68 if (!base::JSONWriter::Write(*patch_dict, &patch_string)) { | 68 if (!base::JSONWriter::Write(*patch_dict, &patch_string)) { |
69 LOG(ERROR) << "Error building GCD device state patch."; | 69 LOG(ERROR) << "Error building GCD device state patch."; |
(...skipping 11 matching lines...) Expand all Loading... |
81 net::URLFetcher::Create(GURL(url), net::URLFetcher::POST, this); | 81 net::URLFetcher::Create(GURL(url), net::URLFetcher::POST, this); |
82 url_fetcher_->SetUploadData("application/json", patch_string); | 82 url_fetcher_->SetUploadData("application/json", patch_string); |
83 if (url_request_context_getter_) { | 83 if (url_request_context_getter_) { |
84 url_fetcher_->SetRequestContext(url_request_context_getter_.get()); | 84 url_fetcher_->SetRequestContext(url_request_context_getter_.get()); |
85 } | 85 } |
86 | 86 |
87 token_getter_->CallWithToken( | 87 token_getter_->CallWithToken( |
88 base::Bind(&GcdRestClient::OnTokenReceived, base::Unretained(this))); | 88 base::Bind(&GcdRestClient::OnTokenReceived, base::Unretained(this))); |
89 } | 89 } |
90 | 90 |
91 void GcdRestClient::SetClockForTest(scoped_ptr<base::Clock> clock) { | 91 void GcdRestClient::SetClockForTest(std::unique_ptr<base::Clock> clock) { |
92 clock_ = std::move(clock); | 92 clock_ = std::move(clock); |
93 } | 93 } |
94 | 94 |
95 void GcdRestClient::OnTokenReceived(OAuthTokenGetter::Status status, | 95 void GcdRestClient::OnTokenReceived(OAuthTokenGetter::Status status, |
96 const std::string& user_email, | 96 const std::string& user_email, |
97 const std::string& access_token) { | 97 const std::string& access_token) { |
98 DCHECK(HasPendingRequest()); | 98 DCHECK(HasPendingRequest()); |
99 | 99 |
100 if (status != OAuthTokenGetter::SUCCESS) { | 100 if (status != OAuthTokenGetter::SUCCESS) { |
101 LOG(ERROR) << "Error getting OAuth token for GCD request: " | 101 LOG(ERROR) << "Error getting OAuth token for GCD request: " |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 << ") fetching URL: " << request_url; | 137 << ") fetching URL: " << request_url; |
138 status = NETWORK_ERROR; | 138 status = NETWORK_ERROR; |
139 } else { | 139 } else { |
140 LOG(ERROR) << "Error (" << response << ") fetching URL: " << request_url; | 140 LOG(ERROR) << "Error (" << response << ") fetching URL: " << request_url; |
141 } | 141 } |
142 | 142 |
143 FinishCurrentRequest(status); | 143 FinishCurrentRequest(status); |
144 } | 144 } |
145 | 145 |
146 } // namespace remoting | 146 } // namespace remoting |
OLD | NEW |