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

Side by Side 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: gyp fixes 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/webui/profile_info_watcher.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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/ui/webui/profile_info_watcher.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/profiles/profile_info_cache.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/signin/signin_manager_factory.h"
15 #include "chrome/common/pref_names.h"
16 #include "components/signin/core/browser/signin_manager.h"
17
18 ProfileInfoWatcher::ProfileInfoWatcher(
19 Profile* profile, const base::Closure& callback)
20 : profile_(profile), callback_(callback) {
21 DCHECK(profile_);
22 DCHECK(!callback_.is_null());
23
24 ProfileManager* profile_manager = g_browser_process->profile_manager();
25 // The profile_manager might be NULL in testing environments.
26 if (profile_manager)
27 profile_manager->GetProfileInfoCache().AddObserver(this);
28
29 signin_allowed_pref_.Init(prefs::kSigninAllowed, profile_->GetPrefs(),
30 base::Bind(&ProfileInfoWatcher::RunCallback, base::Unretained(this)));
31 }
32
33 ProfileInfoWatcher::~ProfileInfoWatcher() {
34 ProfileManager* profile_manager = g_browser_process->profile_manager();
35 // The profile_manager might be NULL in testing environments.
36 if (profile_manager)
37 profile_manager->GetProfileInfoCache().RemoveObserver(this);
38 }
39
40 void ProfileInfoWatcher::OnProfileAuthInfoChanged(
41 const base::FilePath& profile_path) {
42 RunCallback();
43 }
44
45 std::string ProfileInfoWatcher::GetAuthenticatedUsername() const {
46 std::string username;
47 SigninManagerBase* signin_manager = GetSigninManager();
48 if (signin_manager)
49 username = signin_manager->GetAuthenticatedUsername();
50 return username;
51 }
52
53 SigninManagerBase* ProfileInfoWatcher::GetSigninManager() const {
54 return SigninManagerFactory::GetForProfile(profile_);
55 }
56
57 void ProfileInfoWatcher::RunCallback() {
58 if (GetSigninManager())
59 callback_.Run();
60 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/profile_info_watcher.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698