Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Unified Diff: chrome/browser/chromeos/login/easy_unlock/short_lived_user_context.cc

Issue 668213003: Reauthenticate the user before launching Smart Lock setup app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change dcheck to log Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/easy_unlock/short_lived_user_context.cc
diff --git a/chrome/browser/chromeos/login/easy_unlock/short_lived_user_context.cc b/chrome/browser/chromeos/login/easy_unlock/short_lived_user_context.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a0d7fafd2cb7784031999b4c78737e8ac2d038f9
--- /dev/null
+++ b/chrome/browser/chromeos/login/easy_unlock/short_lived_user_context.cc
@@ -0,0 +1,56 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/login/easy_unlock/short_lived_user_context.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/task_runner.h"
+#include "chrome/common/extensions/extension_constants.h"
+#include "chromeos/login/auth/user_context.h"
+
+namespace chromeos {
+
+namespace {
+
+// The number of minutes that the user context will be stored.
+const int64 kUserContextTimeToLiveMinutes = 10;
+
+} // namespace
+
+ShortLivedUserContext::ShortLivedUserContext(
+ const UserContext& user_context,
+ apps::AppLifetimeMonitor* app_lifetime_monitor,
+ base::TaskRunner* task_runner)
+ : user_context_(new UserContext(user_context)),
+ app_lifetime_monitor_(app_lifetime_monitor),
+ weak_ptr_factory_(this) {
+ app_lifetime_monitor_->AddObserver(this);
+
+ task_runner->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&ShortLivedUserContext::DeleteUserContext,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::TimeDelta::FromMinutes(kUserContextTimeToLiveMinutes));
+}
+
+ShortLivedUserContext::~ShortLivedUserContext() {
+ DeleteUserContext();
+}
+
+void ShortLivedUserContext::DeleteUserContext() {
+ if (user_context_.get()) {
+ user_context_->ClearSecrets();
+ user_context_.reset();
+ 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().
+ }
+}
+
+void ShortLivedUserContext::OnAppDeactivated(Profile* profile,
+ const std::string& app_id) {
+ if (app_id == extension_misc::kEasyUnlockAppId)
+ DeleteUserContext();
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698