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

Unified Diff: chrome/browser/ui/webui/profile_info_watcher.cc

Issue 1143963002: Split NTPLoginHandler across chrome://apps and chrome://history. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lower Created 5 years, 7 months 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/ui/webui/profile_info_watcher.cc
diff --git a/chrome/browser/ui/webui/profile_info_watcher.cc b/chrome/browser/ui/webui/profile_info_watcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0e3357253da08b2f0ac398848779c50ac28b4eca
--- /dev/null
+++ b/chrome/browser/ui/webui/profile_info_watcher.cc
@@ -0,0 +1,62 @@
+// Copyright 2015 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/ui/webui/profile_info_watcher.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/prefs/pref_service.h"
+#include "base/strings/string16.h"
MAD 2015/05/20 19:33:02 Not needed.
Dan Beam 2015/05/20 21:53:23 Done.
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_info_cache.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
+#include "chrome/common/pref_names.h"
+#include "components/signin/core/browser/signin_manager.h"
+#include "content/public/browser/web_ui.h"
MAD 2015/05/20 19:33:02 Not needed?
Dan Beam 2015/05/20 21:53:23 Done.
+
+ProfileInfoWatcher::ProfileInfoWatcher(
+ Profile* profile, const base::Closure& callback)
+ : profile_(profile), callback_(callback) {
+ DCHECK(profile_);
+ DCHECK(!callback_.is_null());
+
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ // The profile_manager might be NULL in testing environments.
+ if (profile_manager)
+ profile_manager->GetProfileInfoCache().AddObserver(this);
+
+ signin_allowed_pref_.Init(prefs::kSigninAllowed, profile_->GetPrefs(),
+ base::Bind(&ProfileInfoWatcher::RunCallback, base::Unretained(this)));
+}
+
+ProfileInfoWatcher::~ProfileInfoWatcher() {
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ // The profile_manager might be NULL in testing environments.
+ if (profile_manager)
+ profile_manager->GetProfileInfoCache().RemoveObserver(this);
+}
+
+void ProfileInfoWatcher::OnProfileAuthInfoChanged(
+ const base::FilePath& profile_path) {
+ RunCallback();
+}
+
+std::string ProfileInfoWatcher::GetAuthenticatedUsername() const {
+ std::string username;
+ SigninManagerBase* signin_manager = GetSigninManager();
+ if (signin_manager)
+ username = signin_manager->GetAuthenticatedUsername();
+ return username;
+}
+
+SigninManagerBase* ProfileInfoWatcher::GetSigninManager() const {
+ return SigninManagerFactory::GetForProfile(profile_);
+}
+
+void ProfileInfoWatcher::RunCallback() {
+ if (GetSigninManager())
+ callback_.Run();
+}

Powered by Google App Engine
This is Rietveld 408576698