Chromium Code Reviews| Index: chrome/browser/ui/app_list/app_list_view_delegate.cc |
| diff --git a/chrome/browser/ui/app_list/app_list_view_delegate.cc b/chrome/browser/ui/app_list/app_list_view_delegate.cc |
| index ee4769fc650c333695c975dc3b291ad0fd8c40c5..e8145e8c790a64c6c20ede23ea99423cd7d66b80 100644 |
| --- a/chrome/browser/ui/app_list/app_list_view_delegate.cc |
| +++ b/chrome/browser/ui/app_list/app_list_view_delegate.cc |
| @@ -7,6 +7,7 @@ |
| #include "base/callback.h" |
| #include "base/files/file_path.h" |
| #include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| #include "chrome/browser/feedback/feedback_util.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| @@ -23,6 +24,9 @@ |
| #include "chrome/common/extensions/extension_constants.h" |
| #include "chrome/common/url_constants.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/notification_details.h" |
|
tapted
2013/08/14 03:53:11
nit: content::NotificationSource and content::Noti
calamity
2013/08/14 09:19:00
Done. notification_source.h is needed for content:
|
| +#include "content/public/browser/notification_service.h" |
| +#include "content/public/browser/notification_source.h" |
| #include "content/public/browser/page_navigator.h" |
| #include "content/public/browser/user_metrics.h" |
| @@ -54,12 +58,40 @@ void CreateShortcutInWebAppDir( |
| AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller, |
| Profile* profile) |
| : controller_(controller), |
| - profile_(profile) {} |
| + profile_(profile), |
| + model_(NULL) { |
| + DCHECK(profile_); |
| + registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
|
tfarina
2013/08/14 03:57:00
do you need to use notifications? we are moving aw
calamity
2013/08/14 09:19:00
I'll split out the NOTIFICATION_PROFILE_CACHED_INF
|
| + content::NotificationService::AllSources()); |
| + registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, |
| + content::Source<Profile>(profile_)); |
| +} |
| + |
| +AppListViewDelegate::~AppListViewDelegate() { |
| + if (signin_delegate_.get()) |
|
tapted
2013/08/14 03:53:11
nit: the `.get()` is usually dropped when used as
calamity
2013/08/14 09:19:00
Done.
|
| + signin_delegate_->RemoveObserver(this); |
| +} |
| -AppListViewDelegate::~AppListViewDelegate() {} |
| +void AppListViewDelegate::OnProfileChanged() { |
| + model_->SetSignedIn(!signin_delegate_->NeedSignin()); |
| + ProfileInfoCache& cache = |
| + g_browser_process->profile_manager()->GetProfileInfoCache(); |
| + // Populate the current user details. |
| + size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
| + // The profile won't exist in the cache if the current app list profile is |
| + // being deleted. |
| + if (profile_index == std::string::npos) |
| + return; |
| + |
| + model_->SetCurrentUser(cache.GetNameOfProfileAtIndex(profile_index), |
| + cache.GetUserNameOfProfileAtIndex(profile_index)); |
| +} |
| void AppListViewDelegate::SetModel(app_list::AppListModel* model) { |
| + if (signin_delegate_.get()) |
| + signin_delegate_->RemoveObserver(this); |
| if (model) { |
| + model_ = model; |
| apps_builder_.reset(new AppsModelBuilder(profile_, |
| model->apps(), |
| controller_.get())); |
| @@ -69,12 +101,15 @@ void AppListViewDelegate::SetModel(app_list::AppListModel* model) { |
| profile_, model->search_box(), model->results(), controller_.get())); |
| signin_delegate_.reset(new ChromeSigninDelegate(profile_)); |
| + signin_delegate_->AddObserver(this); |
| #if defined(USE_ASH) |
| app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, |
| model)); |
| #endif |
| + OnProfileChanged(); |
| } else { |
|
tapted
2013/08/14 03:53:11
I think while this else is still around, it also n
calamity
2013/08/14 09:19:00
Done.
|
| + model_ = NULL; |
| apps_builder_.reset(); |
| search_controller_.reset(); |
| #if defined(USE_ASH) |
| @@ -160,26 +195,6 @@ gfx::ImageSkia AppListViewDelegate::GetWindowIcon() { |
| return controller_->GetWindowIcon(); |
| } |
| -string16 AppListViewDelegate::GetCurrentUserName() { |
| - ProfileInfoCache& cache = |
| - g_browser_process->profile_manager()->GetProfileInfoCache(); |
| - size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
| - if (profile_index != std::string::npos) |
| - return cache.GetNameOfProfileAtIndex(profile_index); |
| - |
| - return string16(); |
| -} |
| - |
| -string16 AppListViewDelegate::GetCurrentUserEmail() { |
| - ProfileInfoCache& cache = |
| - g_browser_process->profile_manager()->GetProfileInfoCache(); |
| - size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
| - if (profile_index != std::string::npos) |
| - return cache.GetUserNameOfProfileAtIndex(profile_index); |
| - |
| - return string16(); |
| -} |
| - |
| void AppListViewDelegate::OpenSettings() { |
| ExtensionService* service = profile_->GetExtensionService(); |
| DCHECK(service); |
| @@ -209,3 +224,14 @@ void AppListViewDelegate::OpenFeedback() { |
| chrome::ShowFeedbackPage(browser, std::string(), |
| chrome::kAppLauncherCategoryTag); |
| } |
| + |
| +void AppListViewDelegate::OnSigninSuccess() { |
| + OnProfileChanged(); |
| +} |
| + |
| +void AppListViewDelegate::Observe( |
| + int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + OnProfileChanged(); |
| +} |