Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / login / easy_unlock / short_lived_user_context.cc
blob41283cce8a51cce6b40e085db7e0f0680790ff16
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 #include "chrome/browser/chromeos/login/easy_unlock/short_lived_user_context.h"
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/task_runner.h"
10 #include "chrome/common/extensions/extension_constants.h"
11 #include "chromeos/login/auth/user_context.h"
13 namespace chromeos {
15 namespace {
17 // The number of minutes that the user context will be stored.
18 const int64 kUserContextTimeToLiveMinutes = 10;
20 } // namespace
22 ShortLivedUserContext::ShortLivedUserContext(
23 const UserContext& user_context,
24 apps::AppLifetimeMonitor* app_lifetime_monitor,
25 base::TaskRunner* task_runner)
26 : user_context_(new UserContext(user_context)),
27 app_lifetime_monitor_(app_lifetime_monitor),
28 weak_ptr_factory_(this) {
29 app_lifetime_monitor_->AddObserver(this);
31 task_runner->PostDelayedTask(
32 FROM_HERE,
33 base::Bind(&ShortLivedUserContext::Reset, weak_ptr_factory_.GetWeakPtr()),
34 base::TimeDelta::FromMinutes(kUserContextTimeToLiveMinutes));
37 ShortLivedUserContext::~ShortLivedUserContext() {
38 Reset();
41 void ShortLivedUserContext::Reset() {
42 if (user_context_.get()) {
43 user_context_->ClearSecrets();
44 user_context_.reset();
45 app_lifetime_monitor_->RemoveObserver(this);
49 void ShortLivedUserContext::OnAppDeactivated(Profile* profile,
50 const std::string& app_id) {
51 if (app_id == extension_misc::kEasyUnlockAppId)
52 Reset();
55 } // namespace chromeos