Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "base/strings/string16.h" | |
|
MAD
2015/05/20 19:33:02
Not needed.
Dan Beam
2015/05/20 21:53:23
Done.
| |
| 11 #include "chrome/browser/browser_process.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | |
| 13 #include "chrome/browser/profiles/profile_info_cache.h" | |
| 14 #include "chrome/browser/profiles/profile_manager.h" | |
| 15 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 16 #include "chrome/common/pref_names.h" | |
| 17 #include "components/signin/core/browser/signin_manager.h" | |
| 18 #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.
| |
| 19 | |
| 20 ProfileInfoWatcher::ProfileInfoWatcher( | |
| 21 Profile* profile, const base::Closure& callback) | |
| 22 : profile_(profile), callback_(callback) { | |
| 23 DCHECK(profile_); | |
| 24 DCHECK(!callback_.is_null()); | |
| 25 | |
| 26 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 27 // The profile_manager might be NULL in testing environments. | |
| 28 if (profile_manager) | |
| 29 profile_manager->GetProfileInfoCache().AddObserver(this); | |
| 30 | |
| 31 signin_allowed_pref_.Init(prefs::kSigninAllowed, profile_->GetPrefs(), | |
| 32 base::Bind(&ProfileInfoWatcher::RunCallback, base::Unretained(this))); | |
| 33 } | |
| 34 | |
| 35 ProfileInfoWatcher::~ProfileInfoWatcher() { | |
| 36 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 37 // The profile_manager might be NULL in testing environments. | |
| 38 if (profile_manager) | |
| 39 profile_manager->GetProfileInfoCache().RemoveObserver(this); | |
| 40 } | |
| 41 | |
| 42 void ProfileInfoWatcher::OnProfileAuthInfoChanged( | |
| 43 const base::FilePath& profile_path) { | |
| 44 RunCallback(); | |
| 45 } | |
| 46 | |
| 47 std::string ProfileInfoWatcher::GetAuthenticatedUsername() const { | |
| 48 std::string username; | |
| 49 SigninManagerBase* signin_manager = GetSigninManager(); | |
| 50 if (signin_manager) | |
| 51 username = signin_manager->GetAuthenticatedUsername(); | |
| 52 return username; | |
| 53 } | |
| 54 | |
| 55 SigninManagerBase* ProfileInfoWatcher::GetSigninManager() const { | |
| 56 return SigninManagerFactory::GetForProfile(profile_); | |
| 57 } | |
| 58 | |
| 59 void ProfileInfoWatcher::RunCallback() { | |
| 60 if (GetSigninManager()) | |
| 61 callback_.Run(); | |
| 62 } | |
| OLD | NEW |