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 e53fa9bdd092c35d14cd52b1973d63fc9a93da9b..21204b6efca928f035fe0e8bd531639fc9ad71a5 100644 |
| --- a/chrome/browser/ui/app_list/app_list_view_delegate.cc |
| +++ b/chrome/browser/ui/app_list/app_list_view_delegate.cc |
| @@ -6,10 +6,12 @@ |
| #include "base/callback.h" |
| #include "base/files/file_path.h" |
| +#include "base/stl_util.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_info_cache.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
| #include "chrome/browser/ui/app_list/apps_model_builder.h" |
| @@ -27,6 +29,7 @@ |
| #include "content/public/browser/notification_source.h" |
| #include "content/public/browser/page_navigator.h" |
| #include "content/public/browser/user_metrics.h" |
| +#include "ui/app_list/search_box_model.h" |
| #if defined(USE_ASH) |
| #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" |
| @@ -51,6 +54,20 @@ void CreateShortcutInWebAppDir( |
| } |
| #endif |
| +void PopulateUsers(ProfileInfoCache& profile_info, |
|
koz (OOO until 15th September)
2013/09/09 22:58:07
Use a const ref or a pointer, non-const refs are a
calamity
2013/09/10 22:50:46
Done.
|
| + base::FilePath active_profile_path, |
|
tapted
2013/09/10 00:29:26
nit: const-ref for this guy too ;)
calamity
2013/09/10 22:50:46
Done.
|
| + app_list::AppListModel::Users* users) { |
| + const size_t count = profile_info.GetNumberOfProfiles(); |
| + for (size_t i = 0; i < count; ++i) { |
| + app_list::AppListModel::User* user = new app_list::AppListModel::User(); |
|
koz (OOO until 15th September)
2013/09/09 22:58:07
nit: Use a scoped_ptr<> and then .release() it int
calamity
2013/09/10 22:50:46
No longer using pointers.
|
| + user->name = profile_info.GetNameOfProfileAtIndex(i); |
| + user->email = profile_info.GetUserNameOfProfileAtIndex(i); |
| + user->profile_path = profile_info.GetPathOfProfileAtIndex(i); |
| + user->active = active_profile_path == user->profile_path; |
| + users->push_back(user); |
| + } |
| +} |
| + |
| } // namespace |
| AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller, |
| @@ -58,63 +75,85 @@ AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller, |
| : controller_(controller), |
| profile_(profile), |
| model_(NULL) { |
| + RegisterForNotifications(); |
| + g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); |
| +} |
| + |
| +AppListViewDelegate::~AppListViewDelegate() { |
| + g_browser_process-> |
| + profile_manager()->GetProfileInfoCache().RemoveObserver(this); |
| +} |
| + |
| +void AppListViewDelegate::RegisterForNotifications() { |
| + registrar_.RemoveAll(); |
| DCHECK(profile_); |
| + |
| registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
| content::Source<Profile>(profile_)); |
| registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, |
| content::Source<Profile>(profile_)); |
| registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, |
| content::Source<Profile>(profile_)); |
| - g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); |
| -} |
| - |
| -AppListViewDelegate::~AppListViewDelegate() { |
| - g_browser_process-> |
| - profile_manager()->GetProfileInfoCache().RemoveObserver(this); |
| } |
| 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_->SetSignedIn(!GetSigninDelegate()->NeedSignin()); |
| - model_->SetCurrentUser(cache.GetNameOfProfileAtIndex(profile_index), |
| - cache.GetUserNameOfProfileAtIndex(profile_index)); |
| + // Populate the app list users. |
| + app_list::AppListModel::Users users; |
| + PopulateUsers(g_browser_process->profile_manager()->GetProfileInfoCache(), |
| + profile_->GetPath(), &users); |
| + model_->SetUsers(users); |
| } |
| -void AppListViewDelegate::SetModel(app_list::AppListModel* model) { |
| - if (model) { |
| - model_ = model; |
| - apps_builder_.reset(new AppsModelBuilder(profile_, |
| - model->apps(), |
| - controller_.get())); |
| - apps_builder_->Build(); |
| +void AppListViewDelegate::SetProfileByPath(const base::FilePath& profile_path) { |
| + DCHECK(model_); |
| - search_controller_.reset(new app_list::SearchController( |
| - profile_, model->search_box(), model->results(), controller_.get())); |
| + // The profile must be loaded before this is called. |
| + profile_ = |
| + g_browser_process->profile_manager()->GetProfileByPath(profile_path); |
| + DCHECK(profile_); |
| - signin_delegate_.reset(new ChromeSigninDelegate(profile_)); |
| + RegisterForNotifications(); |
| + |
| + apps_builder_->SetProfile(profile_); |
| + |
| + search_controller_.reset(new app_list::SearchController( |
| + profile_, model_->search_box(), model_->results(), controller_.get())); |
| + |
| + signin_delegate_->SetProfile(profile_); |
|
tapted
2013/09/10 00:29:26
Why couldn't this just be signin_delegate_.reset(n
calamity
2013/09/10 22:50:46
SigninView holds onto this delegate when its const
tapted
2013/09/11 05:50:26
Hm - so it does. Mac will fetch a new delegate in
calamity
2013/09/13 18:02:35
Done.
|
| #if defined(USE_ASH) |
| - app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, |
| - model)); |
| + app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, |
| + model_)); |
| #endif |
| - OnProfileChanged(); |
| - } else { |
| - model_ = NULL; |
| - apps_builder_.reset(); |
| - search_controller_.reset(); |
| - signin_delegate_.reset(); |
| + OnProfileChanged(); |
| + if (!model_->search_box()->text().empty()) |
| + StartSearch(); |
|
tapted
2013/09/10 00:29:26
This feels funny here.. it feels like something th
xiyuan
2013/09/10 01:54:33
It does look strange. I would prefer to clear quer
calamity
2013/09/10 22:50:46
Clearing the search box means that if a user start
xiyuan
2013/09/11 05:01:49
Sounds reasonable.
tapted
2013/09/11 05:50:26
I'm leaning slightly towards clearing results and
calamity
2013/09/13 18:02:35
Changed to clear search text on profile change for
|
| +} |
| + |
| +void AppListViewDelegate::InitModel(app_list::AppListModel* model) { |
| + DCHECK(!model_); |
| + DCHECK(model); |
| + model_ = model; |
| + |
| + // Initialize apps model. |
| + apps_builder_.reset(new AppsModelBuilder(profile_, |
| + model->apps(), |
| + controller_.get())); |
| + apps_builder_->Build(); |
| + |
| + search_controller_.reset(new app_list::SearchController( |
| + profile_, model->search_box(), model->results(), controller_.get())); |
| + |
| + signin_delegate_.reset(new ChromeSigninDelegate(profile_)); |
| + |
| #if defined(USE_ASH) |
| - app_sync_ui_state_watcher_.reset(); |
| + app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, |
|
koz (OOO until 15th September)
2013/09/09 22:58:07
What does this do?
xiyuan
2013/09/10 01:54:33
This is for ChromeOS to show pulsing animation whe
koz (OOO until 15th September)
2013/09/10 15:21:36
Cool, thanks for the explanation. Sounds like some
|
| + model)); |
| #endif |
| - } |
| + // Initialize the profile information in the app list menu. |
| + OnProfileChanged(); |
| } |
| app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { |
| @@ -220,6 +259,11 @@ void AppListViewDelegate::OpenFeedback() { |
| chrome::kAppLauncherCategoryTag); |
| } |
| +void AppListViewDelegate::ShowForProfileByPath( |
| + const base::FilePath& profile_path) { |
| + controller_->ShowForProfileByPath(profile_path); |
| +} |
| + |
| void AppListViewDelegate::Observe( |
| int type, |
| const content::NotificationSource& source, |
| @@ -227,11 +271,12 @@ void AppListViewDelegate::Observe( |
| OnProfileChanged(); |
| } |
| +void AppListViewDelegate::OnProfileAdded(const base::FilePath& profile_path) { |
| + OnProfileChanged(); |
| +} |
| + |
| void AppListViewDelegate::OnProfileNameChanged( |
| const base::FilePath& profile_path, |
| const base::string16& old_profile_name) { |
| - if (profile_->GetPath() != profile_path) |
| - return; |
| - |
| OnProfileChanged(); |
| } |