Disable SourceDir.ResolveRelativeFile and SourceDir.ResolveRelativeDir on win
[chromium-blink-merge.git] / jingle / notifier / communicator / single_login_attempt.h
blob3b7f89a3d90cc34b62e98c011563057bde36f0e5
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
3 // found in the LICENSE file.
5 #ifndef JINGLE_NOTIFIER_COMMUNICATOR_SINGLE_LOGIN_ATTEMPT_H_
6 #define JINGLE_NOTIFIER_COMMUNICATOR_SINGLE_LOGIN_ATTEMPT_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "jingle/notifier/base/xmpp_connection.h"
11 #include "jingle/notifier/communicator/connection_settings.h"
12 #include "jingle/notifier/communicator/login_settings.h"
13 #include "webrtc/libjingle/xmpp/xmppengine.h"
15 namespace buzz {
16 class XmppTaskParentInterface;
17 } // namespace buzz
19 namespace notifier {
21 struct ServerInformation;
23 // Handles all of the aspects of a single login attempt. By
24 // containing this within one class, when another login attempt is
25 // made, this class can be destroyed to immediately stop the previous
26 // login attempt.
27 class SingleLoginAttempt : public XmppConnection::Delegate {
28 public:
29 // At most one delegate method will be called, depending on the
30 // result of the login attempt. After the delegate method is
31 // called, this class won't do anything anymore until it is
32 // destroyed, at which point it will disconnect if necessary.
33 class Delegate {
34 public:
35 // Called when the login attempt is successful.
36 virtual void OnConnect(
37 base::WeakPtr<buzz::XmppTaskParentInterface> base_task) = 0;
39 // Called when the server responds with a redirect. A new login
40 // attempt should be made to the given redirect server.
41 virtual void OnRedirect(const ServerInformation& redirect_server) = 0;
43 // Called when a server rejects the client's login credentials. A
44 // new login attempt should be made once the client provides new
45 // credentials.
46 virtual void OnCredentialsRejected() = 0;
48 // Called when no server could be logged into for reasons other
49 // than redirection or rejected credentials. A new login attempt
50 // may be created, but it should be done with exponential backoff.
51 virtual void OnSettingsExhausted() = 0;
53 protected:
54 virtual ~Delegate();
57 // Does not take ownership of |delegate|, which must not be NULL.
58 SingleLoginAttempt(const LoginSettings& login_settings, Delegate* delegate);
60 ~SingleLoginAttempt() override;
62 // XmppConnection::Delegate implementation.
63 void OnConnect(base::WeakPtr<buzz::XmppTaskParentInterface> parent) override;
64 void OnError(buzz::XmppEngine::Error error,
65 int error_subcode,
66 const buzz::XmlElement* stream_error) override;
68 private:
69 void TryConnect(const ConnectionSettings& new_settings);
71 const LoginSettings login_settings_;
72 Delegate* const delegate_;
73 const ConnectionSettingsList settings_list_;
74 ConnectionSettingsList::const_iterator current_settings_;
75 scoped_ptr<XmppConnection> xmpp_connection_;
77 DISALLOW_COPY_AND_ASSIGN(SingleLoginAttempt);
80 } // namespace notifier
82 #endif // JINGLE_NOTIFIER_COMMUNICATOR_SINGLE_LOGIN_ATTEMPT_H_