Roll src/third_party/WebKit 2dc4bc6:34469ea (svn 182261:182277)
[chromium-blink-merge.git] / remoting / protocol / negotiating_client_authenticator.h
blob05a8b174027d599b406dad1b75ddf45be5937ece
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 #ifndef REMOTING_PROTOCOL_NEGOTIATING_CLIENT_AUTHENTICATOR_H_
6 #define REMOTING_PROTOCOL_NEGOTIATING_CLIENT_AUTHENTICATOR_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "remoting/protocol/authentication_method.h"
15 #include "remoting/protocol/authenticator.h"
16 #include "remoting/protocol/negotiating_authenticator_base.h"
17 #include "remoting/protocol/third_party_client_authenticator.h"
19 namespace remoting {
20 namespace protocol {
22 // Client-side implementation of NegotiatingAuthenticatorBase.
23 // See comments in negotiating_authenticator_base.h for a general explanation.
24 class NegotiatingClientAuthenticator : public NegotiatingAuthenticatorBase {
25 public:
26 // TODO(jamiewalch): Pass ClientConfig instead of separate parameters.
27 NegotiatingClientAuthenticator(
28 const std::string& client_pairing_id,
29 const std::string& shared_secret,
30 const std::string& authentication_tag,
31 const FetchSecretCallback& fetch_secret_callback,
32 scoped_ptr<ThirdPartyClientAuthenticator::TokenFetcher> token_fetcher_,
33 const std::vector<AuthenticationMethod>& methods);
35 virtual ~NegotiatingClientAuthenticator();
37 // Overriden from Authenticator.
38 virtual void ProcessMessage(const buzz::XmlElement* message,
39 const base::Closure& resume_callback) OVERRIDE;
40 virtual scoped_ptr<buzz::XmlElement> GetNextMessage() OVERRIDE;
42 private:
43 // (Asynchronously) creates an authenticator, and stores it in
44 // |current_authenticator_|. Authenticators that can be started in either
45 // state will be created in |preferred_initial_state|.
46 // |resume_callback| is called after |current_authenticator_| is set.
47 void CreateAuthenticatorForCurrentMethod(
48 Authenticator::State preferred_initial_state,
49 const base::Closure& resume_callback);
51 // If possible, create a preferred authenticator ready to send an
52 // initial message optimistically to the host. The host is free to
53 // ignore the client's preferred authenticator and initial message
54 // and to instead reply with an alternative method. See the comments
55 // in negotiating_authenticator_base.h for more details.
57 // Sets |current_authenticator_| and |current_method_| iff the client
58 // has a preferred authenticator that can optimistically send an initial
59 // message.
60 void CreatePreferredAuthenticator();
62 // Creates a V2Authenticator in state |initial_state| with the given
63 // |shared_secret|, then runs |resume_callback|.
64 void CreateV2AuthenticatorWithSecret(
65 Authenticator::State initial_state,
66 const base::Closure& resume_callback,
67 const std::string& shared_secret);
69 // Used for pairing authenticators
70 std::string client_pairing_id_;
71 std::string shared_secret_;
73 // Used for all authenticators.
74 std::string authentication_tag_;
76 // Used for shared secret authenticators.
77 FetchSecretCallback fetch_secret_callback_;
79 // Used for third party authenticators.
80 scoped_ptr<ThirdPartyClientAuthenticator::TokenFetcher> token_fetcher_;
82 // Internal NegotiatingClientAuthenticator data.
83 bool method_set_by_host_;
84 base::WeakPtrFactory<NegotiatingClientAuthenticator> weak_factory_;
86 DISALLOW_COPY_AND_ASSIGN(NegotiatingClientAuthenticator);
89 } // namespace protocol
90 } // namespace remoting
92 #endif // REMOTING_PROTOCOL_NEGOTIATING_CLIENT_AUTHENTICATOR_H_