OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/sync/notifier/communicator/talk_auth_task.h" |
| 6 |
| 7 #include "chrome/browser/sync/notifier/communicator/login.h" |
| 8 #include "chrome/browser/sync/notifier/communicator/login_settings.h" |
| 9 #include "chrome/browser/sync/notifier/communicator/product_info.h" |
| 10 #include "chrome/browser/sync/notifier/gaia_auth/gaiaauth.h" |
| 11 #include "talk/base/common.h" |
| 12 #include "talk/base/urlencode.h" |
| 13 #include "talk/xmpp/xmppclient.h" |
| 14 |
| 15 namespace notifier { |
| 16 const char kTalkGadgetAuthPath[] = "/auth"; |
| 17 |
| 18 TalkAuthTask::TalkAuthTask(talk_base::Task* parent, |
| 19 Login* login, |
| 20 const char* url) |
| 21 : talk_base::Task(parent), |
| 22 login_(login), |
| 23 url_(url) { |
| 24 ASSERT(login && !url_.empty()); |
| 25 } |
| 26 |
| 27 int TalkAuthTask::ProcessStart() { |
| 28 auth_.reset(new buzz::GaiaAuth(GetUserAgentString(), |
| 29 GetProductSignature())); |
| 30 auth_->SignalAuthDone.connect( |
| 31 this, |
| 32 &TalkAuthTask::OnAuthDone); |
| 33 auth_->StartAuth(login_->xmpp_client()->jid().BareJid(), |
| 34 login_->login_settings().user_settings().pass(), |
| 35 "talk"); |
| 36 return STATE_RESPONSE; |
| 37 } |
| 38 |
| 39 int TalkAuthTask::ProcessResponse() { |
| 40 ASSERT(auth_.get()); |
| 41 if (!auth_->IsAuthDone()) { |
| 42 return STATE_BLOCKED; |
| 43 } |
| 44 SignalAuthDone(*this); |
| 45 return STATE_DONE; |
| 46 } |
| 47 |
| 48 |
| 49 void TalkAuthTask::OnAuthDone() { |
| 50 Wake(); |
| 51 } |
| 52 |
| 53 bool TalkAuthTask::HadError() const { |
| 54 return auth_->HadError(); |
| 55 } |
| 56 |
| 57 std::string TalkAuthTask::GetAuthenticatedUrl( |
| 58 const char* talk_base_url) const { |
| 59 ASSERT(talk_base_url && *talk_base_url && !auth_->HadError()); |
| 60 |
| 61 std::string auth_url(talk_base_url); |
| 62 auth_url.append(kTalkGadgetAuthPath); |
| 63 auth_url.append("?silent=true&redirect=true&host="); |
| 64 auth_url.append(UrlEncodeString(url_)); |
| 65 auth_url.append("&auth="); |
| 66 auth_url.append(auth_->GetAuth()); |
| 67 return auth_url; |
| 68 } |
| 69 |
| 70 std::string TalkAuthTask::GetSID() const { |
| 71 return auth_->GetSID(); |
| 72 } |
| 73 } // namespace notifier |
OLD | NEW |