| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |