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/auth_task.h" |
| 6 |
| 7 #include "chrome/browser/sync/notifier/gaia_auth/gaiaauth.h" |
| 8 #include "chrome/browser/sync/notifier/communicator/login.h" |
| 9 #include "chrome/browser/sync/notifier/communicator/login_settings.h" |
| 10 #include "chrome/browser/sync/notifier/communicator/product_info.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 AuthTask::AuthTask(talk_base::Task* parent, Login* login, const char* url) |
| 19 : talk_base::Task(parent), |
| 20 login_(login), |
| 21 url_(url), |
| 22 use_gaia_redirect_(true) { |
| 23 ASSERT(login && !url_.empty()); |
| 24 } |
| 25 |
| 26 int AuthTask::ProcessStart() { |
| 27 auth_.reset(new buzz::GaiaAuth(GetUserAgentString(), |
| 28 GetProductSignature())); |
| 29 auth_->SignalAuthDone.connect(this, &AuthTask::OnAuthDone); |
| 30 auth_->StartTokenAuth(login_->xmpp_client()->jid().BareJid(), |
| 31 login_->login_settings().user_settings().pass(), |
| 32 use_gaia_redirect_ ? "gaia" : service_); |
| 33 return STATE_RESPONSE; |
| 34 } |
| 35 |
| 36 int AuthTask::ProcessResponse() { |
| 37 ASSERT(auth_.get()); |
| 38 if (!auth_->IsAuthDone()) { |
| 39 return STATE_BLOCKED; |
| 40 } |
| 41 if (!auth_->IsAuthorized()) { |
| 42 SignalAuthError(!auth_->HadError()); |
| 43 return STATE_ERROR; |
| 44 } |
| 45 |
| 46 std::string uber_url; |
| 47 if (use_gaia_redirect_) { |
| 48 uber_url = auth_->CreateAuthenticatedUrl(url_, service_); |
| 49 } else { |
| 50 uber_url = redir_auth_prefix_ + auth_->GetAuthCookie(); |
| 51 uber_url += redir_continue_; |
| 52 uber_url += UrlEncodeString(url_); |
| 53 } |
| 54 |
| 55 if (uber_url == "") { |
| 56 SignalAuthError(true); |
| 57 return STATE_ERROR; |
| 58 } |
| 59 |
| 60 SignalAuthDone(uber_url); |
| 61 return STATE_DONE; |
| 62 } |
| 63 |
| 64 |
| 65 void AuthTask::OnAuthDone() { |
| 66 Wake(); |
| 67 } |
| 68 |
| 69 } // namespace notifier |
OLD | NEW |