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. 4 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_ 7 8#include "apps/app_lifetime_monitor.h" 9#include "base/memory/scoped_ptr.h" 10#include "base/memory/weak_ptr.h" 11 12namespace base { 13class TaskRunner; 14} 15 16namespace chromeos { 17 18class UserContext; 19 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. 25class 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 virtual ~ShortLivedUserContext(); 31 32 // The UserContext returned here can be NULL if its time-to-live has expired. 33 UserContext* user_context() { return user_context_.get(); } 34 35 private: 36 void Reset(); 37 38 // apps::AppLifetimeMonitor::Observer: 39 virtual void OnAppDeactivated(Profile* profile, 40 const std::string& app_id) override; 41 42 scoped_ptr<UserContext> user_context_; 43 44 apps::AppLifetimeMonitor* app_lifetime_monitor_; 45 46 base::WeakPtrFactory<ShortLivedUserContext> weak_ptr_factory_; 47 48 DISALLOW_COPY_AND_ASSIGN(ShortLivedUserContext); 49}; 50 51} // namespace chromeos 52 53#endif // CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_SHORT_LIVED_USER_CONTEXT_H_ 54