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.h" | 10 #include "base/message_loop.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 net::URLRequest request(url, &fetcher_delegate); | 174 net::URLRequest request(url, &fetcher_delegate); |
175 | 175 |
176 request.AppendBytesToUpload(post_body.c_str(), post_body.size()); | 176 request.AppendBytesToUpload(post_body.c_str(), post_body.size()); |
177 request.SetExtraRequestHeaderByName( | 177 request.SetExtraRequestHeaderByName( |
178 "Content-Type", "application/x-www-form-urlencoded", true); | 178 "Content-Type", "application/x-www-form-urlencoded", true); |
179 request.set_context(context.get()); | 179 request.set_context(context.get()); |
180 request.set_method("POST"); | 180 request.set_method("POST"); |
181 request.Start(); | 181 request.Start(); |
182 | 182 |
183 MessageLoop::current()->PostDelayedTask( | 183 MessageLoop::current()->PostDelayedTask( |
184 FROM_HERE, MessageLoop::QuitClosure(), kRequestTimeoutMs); | 184 FROM_HERE, MessageLoop::QuitClosure(), |
| 185 base::TimeDelta::FromMilliseconds(kRequestTimeoutMs)); |
185 | 186 |
186 MessageLoop::current()->Run(); | 187 MessageLoop::current()->Run(); |
187 | 188 |
188 const char kAuthStart[] = "Auth="; | 189 const char kAuthStart[] = "Auth="; |
189 std::vector<std::string> lines; | 190 std::vector<std::string> lines; |
190 Tokenize(fetcher_delegate.data(), "\r\n", &lines); | 191 Tokenize(fetcher_delegate.data(), "\r\n", &lines); |
191 for (size_t i = 0; i < lines.size(); ++i) { | 192 for (size_t i = 0; i < lines.size(); ++i) { |
192 std::vector<std::string> tokens; | 193 std::vector<std::string> tokens; |
193 if (StartsWithASCII(lines[i], kAuthStart, false)) | 194 if (StartsWithASCII(lines[i], kAuthStart, false)) |
194 return lines[i].substr(arraysize(kAuthStart) - 1); | 195 return lines[i].substr(arraysize(kAuthStart) - 1); |
195 } | 196 } |
196 | 197 |
197 return std::string(); | 198 return std::string(); |
198 } | 199 } |
199 | 200 |
200 bool ServiceState::Configure(const std::string& email, | 201 bool ServiceState::Configure(const std::string& email, |
201 const std::string& password, | 202 const std::string& password, |
202 const std::string& proxy_id) { | 203 const std::string& proxy_id) { |
203 robot_token_.clear(); | 204 robot_token_.clear(); |
204 robot_email_.clear(); | 205 robot_email_.clear(); |
205 email_ = email; | 206 email_ = email; |
206 proxy_id_ = proxy_id; | 207 proxy_id_ = proxy_id; |
207 auth_token_ = LoginToGoogle("cloudprint", email_, password); | 208 auth_token_ = LoginToGoogle("cloudprint", email_, password); |
208 xmpp_auth_token_ = LoginToGoogle("chromiumsync", email_, password); | 209 xmpp_auth_token_ = LoginToGoogle("chromiumsync", email_, password); |
209 return IsValid(); | 210 return IsValid(); |
210 } | 211 } |
211 | 212 |
OLD | NEW |