| 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" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/threading/worker_pool.h" |
| 13 #include "net/base/escape.h" | 14 #include "net/base/escape.h" |
| 14 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
| 15 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
| 16 #include "net/base/upload_bytes_element_reader.h" | 17 #include "net/base/upload_bytes_element_reader.h" |
| 17 #include "net/base/upload_data_stream.h" | 18 #include "net/base/upload_data_stream.h" |
| 18 #include "net/url_request/url_request.h" | 19 #include "net/url_request/url_request.h" |
| 19 #include "net/url_request/url_request_context.h" | 20 #include "net/url_request/url_request_context.h" |
| 20 #include "net/url_request/url_request_context_builder.h" | 21 #include "net/url_request/url_request_context_builder.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 156 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 156 &json); | 157 &json); |
| 157 return json; | 158 return json; |
| 158 } | 159 } |
| 159 | 160 |
| 160 std::string ServiceState::LoginToGoogle(const std::string& service, | 161 std::string ServiceState::LoginToGoogle(const std::string& service, |
| 161 const std::string& email, | 162 const std::string& email, |
| 162 const std::string& password) { | 163 const std::string& password) { |
| 163 base::MessageLoop loop(base::MessageLoop::TYPE_IO); | 164 base::MessageLoop loop(base::MessageLoop::TYPE_IO); |
| 164 | 165 |
| 165 net::URLRequestContextBuilder builder; | 166 net::URLRequestContextBuilder builder( |
| 167 base::WorkerPool::GetTaskRunner(true /* task_is_slow */)); |
| 166 scoped_ptr<net::URLRequestContext> context(builder.Build()); | 168 scoped_ptr<net::URLRequestContext> context(builder.Build()); |
| 167 | 169 |
| 168 ServiceStateURLRequestDelegate fetcher_delegate; | 170 ServiceStateURLRequestDelegate fetcher_delegate; |
| 169 GURL url(kClientLoginUrl); | 171 GURL url(kClientLoginUrl); |
| 170 | 172 |
| 171 std::string post_body; | 173 std::string post_body; |
| 172 post_body += "accountType=GOOGLE"; | 174 post_body += "accountType=GOOGLE"; |
| 173 post_body += "&Email=" + net::EscapeUrlEncodedData(email, true); | 175 post_body += "&Email=" + net::EscapeUrlEncodedData(email, true); |
| 174 post_body += "&Passwd=" + net::EscapeUrlEncodedData(password, true); | 176 post_body += "&Passwd=" + net::EscapeUrlEncodedData(password, true); |
| 175 post_body += "&source=" + net::EscapeUrlEncodedData("CP-Service", true); | 177 post_body += "&source=" + net::EscapeUrlEncodedData("CP-Service", true); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 const std::string& password, | 215 const std::string& password, |
| 214 const std::string& proxy_id) { | 216 const std::string& proxy_id) { |
| 215 robot_token_.clear(); | 217 robot_token_.clear(); |
| 216 robot_email_.clear(); | 218 robot_email_.clear(); |
| 217 email_ = email; | 219 email_ = email; |
| 218 proxy_id_ = proxy_id; | 220 proxy_id_ = proxy_id; |
| 219 auth_token_ = LoginToGoogle("cloudprint", email_, password); | 221 auth_token_ = LoginToGoogle("cloudprint", email_, password); |
| 220 xmpp_auth_token_ = LoginToGoogle("chromiumsync", email_, password); | 222 xmpp_auth_token_ = LoginToGoogle("chromiumsync", email_, password); |
| 221 return IsValid(); | 223 return IsValid(); |
| 222 } | 224 } |
| OLD | NEW |