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

Side by Side Diff: chrome/browser/ui/webui/profile_info_watcher.cc

Issue 1723643002: Refactor ProfileInfoCache in c/b/ui/webui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed a signed/unsigned integer conversion, one removed #include Created 4 years, 10 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/profile_info_watcher.h" 5 #include "chrome/browser/ui/webui/profile_info_watcher.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_info_cache.h"
12 #include "chrome/browser/profiles/profile_manager.h" 11 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/signin/signin_manager_factory.h" 12 #include "chrome/browser/signin/signin_manager_factory.h"
14 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
15 #include "components/prefs/pref_service.h" 14 #include "components/prefs/pref_service.h"
16 #include "components/signin/core/browser/signin_manager.h" 15 #include "components/signin/core/browser/signin_manager.h"
17 #include "components/signin/core/common/signin_pref_names.h" 16 #include "components/signin/core/common/signin_pref_names.h"
18 17
19 ProfileInfoWatcher::ProfileInfoWatcher( 18 ProfileInfoWatcher::ProfileInfoWatcher(
20 Profile* profile, const base::Closure& callback) 19 Profile* profile, const base::Closure& callback)
21 : profile_(profile), callback_(callback) { 20 : profile_(profile), callback_(callback) {
22 DCHECK(profile_); 21 DCHECK(profile_);
23 DCHECK(!callback_.is_null()); 22 DCHECK(!callback_.is_null());
24 23
25 ProfileManager* profile_manager = g_browser_process->profile_manager(); 24 ProfileManager* profile_manager = g_browser_process->profile_manager();
26 // The profile_manager might be NULL in testing environments. 25 // The profile_manager might be NULL in testing environments.
27 if (profile_manager) 26 if (profile_manager)
28 profile_manager->GetProfileInfoCache().AddObserver(this); 27 profile_manager->GetProfileAttributesStorage().AddObserver(this);
29 28
30 signin_allowed_pref_.Init(prefs::kSigninAllowed, profile_->GetPrefs(), 29 signin_allowed_pref_.Init(prefs::kSigninAllowed, profile_->GetPrefs(),
31 base::Bind(&ProfileInfoWatcher::RunCallback, base::Unretained(this))); 30 base::Bind(&ProfileInfoWatcher::RunCallback, base::Unretained(this)));
32 } 31 }
33 32
34 ProfileInfoWatcher::~ProfileInfoWatcher() { 33 ProfileInfoWatcher::~ProfileInfoWatcher() {
35 ProfileManager* profile_manager = g_browser_process->profile_manager(); 34 ProfileManager* profile_manager = g_browser_process->profile_manager();
36 // The profile_manager might be NULL in testing environments. 35 // The profile_manager might be NULL in testing environments.
37 if (profile_manager) 36 if (profile_manager)
38 profile_manager->GetProfileInfoCache().RemoveObserver(this); 37 profile_manager->GetProfileAttributesStorage().RemoveObserver(this);
39 } 38 }
40 39
41 void ProfileInfoWatcher::OnProfileAuthInfoChanged( 40 void ProfileInfoWatcher::OnProfileAuthInfoChanged(
42 const base::FilePath& profile_path) { 41 const base::FilePath& profile_path) {
43 RunCallback(); 42 RunCallback();
44 } 43 }
45 44
46 std::string ProfileInfoWatcher::GetAuthenticatedUsername() const { 45 std::string ProfileInfoWatcher::GetAuthenticatedUsername() const {
47 std::string username; 46 std::string username;
48 SigninManagerBase* signin_manager = GetSigninManager(); 47 SigninManagerBase* signin_manager = GetSigninManager();
49 if (signin_manager) 48 if (signin_manager)
50 username = signin_manager->GetAuthenticatedAccountInfo().email; 49 username = signin_manager->GetAuthenticatedAccountInfo().email;
51 return username; 50 return username;
52 } 51 }
53 52
54 SigninManagerBase* ProfileInfoWatcher::GetSigninManager() const { 53 SigninManagerBase* ProfileInfoWatcher::GetSigninManager() const {
55 return SigninManagerFactory::GetForProfile(profile_); 54 return SigninManagerFactory::GetForProfile(profile_);
56 } 55 }
57 56
58 void ProfileInfoWatcher::RunCallback() { 57 void ProfileInfoWatcher::RunCallback() {
59 if (GetSigninManager()) 58 if (GetSigninManager())
60 callback_.Run(); 59 callback_.Run();
61 } 60 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/profile_info_watcher.h ('k') | chrome/browser/ui/webui/settings/people_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698