Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / login / easy_unlock / short_lived_user_context.h
bloba97d11068dfeaa5b679af4c2a5ee3e9c7a812855
1 // Copyright 2014 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 CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_SHORT_LIVED_USER_CONTEXT_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_SHORT_LIVED_USER_CONTEXT_H_
8 #include "apps/app_lifetime_monitor.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
12 namespace base {
13 class TaskRunner;
16 namespace chromeos {
18 class UserContext;
20 // Stores the UserContext of an authentication operation on the sign-in/lock
21 // screen, which is used to generate the keys for Easy Sign-in.
22 // The lifetime of the user context is bound the the setup app window. As a
23 // fail-safe, the user context will also be deleted after a set period of time
24 // in case the app is left open indefintely.
25 class ShortLivedUserContext : public apps::AppLifetimeMonitor::Observer {
26 public:
27 ShortLivedUserContext(const UserContext& user_context,
28 apps::AppLifetimeMonitor* app_lifetime_monitor,
29 base::TaskRunner* task_runner);
30 ~ShortLivedUserContext() override;
32 // The UserContext returned here can be NULL if its time-to-live has expired.
33 UserContext* user_context() { return user_context_.get(); }
35 private:
36 void Reset();
38 // apps::AppLifetimeMonitor::Observer:
39 void OnAppDeactivated(Profile* profile, const std::string& app_id) override;
41 scoped_ptr<UserContext> user_context_;
43 apps::AppLifetimeMonitor* app_lifetime_monitor_;
45 base::WeakPtrFactory<ShortLivedUserContext> weak_ptr_factory_;
47 DISALLOW_COPY_AND_ASSIGN(ShortLivedUserContext);
50 } // namespace chromeos
52 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_SHORT_LIVED_USER_CONTEXT_H_