OLD | NEW |
(Empty) | |
| 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 #include "chrome/browser/chromeos/login/easy_unlock/short_lived_user_context.h" |
| 6 |
| 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" |
| 12 |
| 13 namespace chromeos { |
| 14 |
| 15 namespace { |
| 16 |
| 17 // The number of minutes that the user context will be stored. |
| 18 const int64 kUserContextTimeToLiveMinutes = 10; |
| 19 |
| 20 } // namespace |
| 21 |
| 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); |
| 30 |
| 31 task_runner->PostDelayedTask( |
| 32 FROM_HERE, |
| 33 base::Bind(&ShortLivedUserContext::Reset, weak_ptr_factory_.GetWeakPtr()), |
| 34 base::TimeDelta::FromMinutes(kUserContextTimeToLiveMinutes)); |
| 35 } |
| 36 |
| 37 ShortLivedUserContext::~ShortLivedUserContext() { |
| 38 Reset(); |
| 39 } |
| 40 |
| 41 void ShortLivedUserContext::Reset() { |
| 42 if (user_context_.get()) { |
| 43 user_context_->ClearSecrets(); |
| 44 user_context_.reset(); |
| 45 app_lifetime_monitor_->RemoveObserver(this); |
| 46 } |
| 47 } |
| 48 |
| 49 void ShortLivedUserContext::OnAppDeactivated(Profile* profile, |
| 50 const std::string& app_id) { |
| 51 if (app_id == extension_misc::kEasyUnlockAppId) |
| 52 Reset(); |
| 53 } |
| 54 |
| 55 } // namespace chromeos |
OLD | NEW |