Chromium Code Reviews| 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::DeleteUserContext, | |
| 34 weak_ptr_factory_.GetWeakPtr()), | |
| 35 base::TimeDelta::FromMinutes(kUserContextTimeToLiveMinutes)); | |
| 36 } | |
| 37 | |
| 38 ShortLivedUserContext::~ShortLivedUserContext() { | |
| 39 DeleteUserContext(); | |
| 40 } | |
| 41 | |
| 42 void ShortLivedUserContext::DeleteUserContext() { | |
| 43 if (user_context_.get()) { | |
| 44 user_context_->ClearSecrets(); | |
| 45 user_context_.reset(); | |
| 46 app_lifetime_monitor_->RemoveObserver(this); | |
|
tbarzic
2014/11/01 23:21:45
this doesn't really belong in "DeleteUserContext"
Tim Song
2014/11/03 19:10:43
Done. Renamed to Reset().
| |
| 47 } | |
| 48 } | |
| 49 | |
| 50 void ShortLivedUserContext::OnAppDeactivated(Profile* profile, | |
| 51 const std::string& app_id) { | |
| 52 if (app_id == extension_misc::kEasyUnlockAppId) | |
| 53 DeleteUserContext(); | |
| 54 } | |
| 55 | |
| 56 } // namespace chromeos | |
| OLD | NEW |