Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: remoting/host/gcd_rest_client.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/host/gcd_rest_client.h ('k') | remoting/host/gcd_rest_client_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
OLDNEW
« no previous file with comments | « remoting/host/gcd_rest_client.h ('k') | remoting/host/gcd_rest_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698