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

Side by Side Diff: cloud_print/service/service_state.cc

Issue 1131113004: Convert JsonWriter::Write to taking a const ref for the in-param (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another rebase Created 5 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "cloud_print/service/service_state.h" 5 #include "cloud_print/service/service_state.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 127
128 bool ServiceState::IsValid() const { 128 bool ServiceState::IsValid() const {
129 if (email_.empty() || proxy_id_.empty()) 129 if (email_.empty() || proxy_id_.empty())
130 return false; 130 return false;
131 bool valid_robot = !robot_email_.empty() && !robot_token_.empty(); 131 bool valid_robot = !robot_email_.empty() && !robot_token_.empty();
132 bool valid_auth = !auth_token_.empty() && !xmpp_auth_token_.empty(); 132 bool valid_auth = !auth_token_.empty() && !xmpp_auth_token_.empty();
133 return valid_robot || valid_auth; 133 return valid_robot || valid_auth;
134 } 134 }
135 135
136 std::string ServiceState::ToString() { 136 std::string ServiceState::ToString() {
137 scoped_ptr<base::DictionaryValue> services(new base::DictionaryValue());
138
139 scoped_ptr<base::DictionaryValue> cloud_print(new base::DictionaryValue()); 137 scoped_ptr<base::DictionaryValue> cloud_print(new base::DictionaryValue());
140 cloud_print->SetBoolean(kEnabledOptionName, true); 138 cloud_print->SetBoolean(kEnabledOptionName, true);
141 139
142 SetNotEmptyJsonString(cloud_print.get(), kEmailOptionName, email_); 140 SetNotEmptyJsonString(cloud_print.get(), kEmailOptionName, email_);
143 SetNotEmptyJsonString(cloud_print.get(), kProxyIdOptionName, proxy_id_); 141 SetNotEmptyJsonString(cloud_print.get(), kProxyIdOptionName, proxy_id_);
144 SetNotEmptyJsonString(cloud_print.get(), kRobotEmailOptionName, robot_email_); 142 SetNotEmptyJsonString(cloud_print.get(), kRobotEmailOptionName, robot_email_);
145 SetNotEmptyJsonString(cloud_print.get(), kRobotTokenOptionName, robot_token_); 143 SetNotEmptyJsonString(cloud_print.get(), kRobotTokenOptionName, robot_token_);
146 SetNotEmptyJsonString(cloud_print.get(), kAuthTokenOptionName, auth_token_); 144 SetNotEmptyJsonString(cloud_print.get(), kAuthTokenOptionName, auth_token_);
147 SetNotEmptyJsonString(cloud_print.get(), kXmppAuthTokenOptionName, 145 SetNotEmptyJsonString(cloud_print.get(), kXmppAuthTokenOptionName,
148 xmpp_auth_token_); 146 xmpp_auth_token_);
149 147
150 services->Set(kCloudPrintJsonName, cloud_print.release()); 148 base::DictionaryValue services;
149 services.Set(kCloudPrintJsonName, cloud_print.Pass());
151 150
152 std::string json; 151 std::string json;
153 base::JSONWriter::WriteWithOptions(services.get(), 152 base::JSONWriter::WriteWithOptions(
154 base::JSONWriter::OPTIONS_PRETTY_PRINT, 153 services, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
155 &json);
156 return json; 154 return json;
157 } 155 }
158 156
159 std::string ServiceState::LoginToGoogle(const std::string& service, 157 std::string ServiceState::LoginToGoogle(const std::string& service,
160 const std::string& email, 158 const std::string& email,
161 const std::string& password) { 159 const std::string& password) {
162 base::MessageLoopForIO loop; 160 base::MessageLoopForIO loop;
163 161
164 net::URLRequestContextBuilder builder; 162 net::URLRequestContextBuilder builder;
165 scoped_ptr<net::URLRequestContext> context(builder.Build()); 163 scoped_ptr<net::URLRequestContext> context(builder.Build());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 const std::string& password, 210 const std::string& password,
213 const std::string& proxy_id) { 211 const std::string& proxy_id) {
214 robot_token_.clear(); 212 robot_token_.clear();
215 robot_email_.clear(); 213 robot_email_.clear();
216 email_ = email; 214 email_ = email;
217 proxy_id_ = proxy_id; 215 proxy_id_ = proxy_id;
218 auth_token_ = LoginToGoogle("cloudprint", email_, password); 216 auth_token_ = LoginToGoogle("cloudprint", email_, password);
219 xmpp_auth_token_ = LoginToGoogle("chromiumsync", email_, password); 217 xmpp_auth_token_ = LoginToGoogle("chromiumsync", email_, password);
220 return IsValid(); 218 return IsValid();
221 } 219 }
OLDNEW
« no previous file with comments | « cloud_print/gcp20/prototype/privet_http_server.cc ('k') | cloud_print/service/win/chrome_launcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698