• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_ONLINE_ATTEMPT_HOST_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_ONLINE_ATTEMPT_HOST_H_
7 
8 #include <string>
9 
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/chromeos/login/auth_attempt_state_resolver.h"
14 
15 class Profile;
16 
17 namespace chromeos {
18 
19 class AuthAttemptState;
20 class OnlineAttempt;
21 struct UserContext;
22 
23 // Helper class which hosts OnlineAttempt for online credentials checking.
24 class OnlineAttemptHost : public AuthAttemptStateResolver {
25  public:
26   class Delegate {
27     public:
28      // Called after user_context were checked online.
29      virtual void OnChecked(const std::string &username, bool success) = 0;
30   };
31 
32   explicit OnlineAttemptHost(Delegate *delegate);
33   virtual ~OnlineAttemptHost();
34 
35   // Checks user credentials using an online attempt. Calls callback with the
36   // check result (whether authentication was successful). Note, only one
37   // checking at a time (the newest call stops the old one, if called with
38   // another username and password combination).
39   void Check(Profile* profile,
40              const UserContext& user_context);
41 
42   // Resets the checking process.
43   void Reset();
44 
45   // AuthAttemptStateResolver overrides.
46   // Executed on IO thread.
47   virtual void Resolve() OVERRIDE;
48 
49   // Does an actual resolve on UI thread.
50   void ResolveOnUIThread(bool success);
51 
52  private:
53   Delegate* delegate_;
54   std::string current_attempt_hash_;
55   std::string current_username_;
56   scoped_ptr<OnlineAttempt> online_attempt_;
57   scoped_ptr<AuthAttemptState> state_;
58   base::WeakPtrFactory<OnlineAttemptHost> weak_ptr_factory_;
59 
60   DISALLOW_COPY_AND_ASSIGN(OnlineAttemptHost);
61 };
62 
63 }  // namespace chromeos
64 
65 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_ONLINE_ATTEMPT_HOST_H_
66 
67