DCHECK that ProfileSyncService is created on the UI thread.
[chromium-blink-merge.git] / remoting / protocol / third_party_authenticator_base.cc
blobccb03a4887c6a49c043c4867bb4664850e5751ba
1 // Copyright 2013 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.
5 #include "remoting/protocol/third_party_authenticator_base.h"
7 #include "base/base64.h"
8 #include "base/bind.h"
9 #include "base/callback.h"
10 #include "base/logging.h"
11 #include "remoting/base/constants.h"
12 #include "remoting/base/rsa_key_pair.h"
13 #include "remoting/protocol/channel_authenticator.h"
14 #include "remoting/protocol/v2_authenticator.h"
15 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
17 namespace remoting {
18 namespace protocol {
20 // static
21 const buzz::StaticQName ThirdPartyAuthenticatorBase::kTokenUrlTag =
22 { remoting::kChromotingXmlNamespace, "third-party-token-url" };
23 const buzz::StaticQName ThirdPartyAuthenticatorBase::kTokenScopeTag =
24 { remoting::kChromotingXmlNamespace, "third-party-token-scope" };
25 const buzz::StaticQName ThirdPartyAuthenticatorBase::kTokenTag =
26 { remoting::kChromotingXmlNamespace, "third-party-token" };
28 ThirdPartyAuthenticatorBase::ThirdPartyAuthenticatorBase(
29 Authenticator::State initial_state)
30 : token_state_(initial_state),
31 started_(false),
32 rejection_reason_(INVALID_CREDENTIALS) {
35 ThirdPartyAuthenticatorBase::~ThirdPartyAuthenticatorBase() {
38 bool ThirdPartyAuthenticatorBase::started() const {
39 return started_;
42 Authenticator::State ThirdPartyAuthenticatorBase::state() const {
43 if (token_state_ == ACCEPTED)
44 return underlying_->state();
45 return token_state_;
48 Authenticator::RejectionReason
49 ThirdPartyAuthenticatorBase::rejection_reason() const {
50 DCHECK_EQ(state(), REJECTED);
52 if (token_state_ == REJECTED)
53 return rejection_reason_;
54 return underlying_->rejection_reason();
57 void ThirdPartyAuthenticatorBase::ProcessMessage(
58 const buzz::XmlElement* message,
59 const base::Closure& resume_callback) {
60 DCHECK_EQ(state(), WAITING_MESSAGE);
62 if (token_state_ == WAITING_MESSAGE) {
63 ProcessTokenMessage(message, resume_callback);
64 } else {
65 DCHECK_EQ(token_state_, ACCEPTED);
66 DCHECK(underlying_);
67 DCHECK_EQ(underlying_->state(), WAITING_MESSAGE);
68 underlying_->ProcessMessage(message, resume_callback);
72 scoped_ptr<buzz::XmlElement> ThirdPartyAuthenticatorBase::GetNextMessage() {
73 DCHECK_EQ(state(), MESSAGE_READY);
75 scoped_ptr<buzz::XmlElement> message;
76 if (underlying_ && underlying_->state() == MESSAGE_READY) {
77 message = underlying_->GetNextMessage().Pass();
78 } else {
79 message = CreateEmptyAuthenticatorMessage();
82 if (token_state_ == MESSAGE_READY) {
83 AddTokenElements(message.get());
84 started_ = true;
86 return message.Pass();
89 scoped_ptr<ChannelAuthenticator>
90 ThirdPartyAuthenticatorBase::CreateChannelAuthenticator() const {
91 DCHECK_EQ(state(), ACCEPTED);
93 return underlying_->CreateChannelAuthenticator();
96 } // namespace protocol
97 } // namespace remoting