| Index: chrome/browser/ui/views/app_list/app_list_controller_win.cc
|
| diff --git a/chrome/browser/ui/views/app_list/app_list_controller_win.cc b/chrome/browser/ui/views/app_list/app_list_controller_win.cc
|
| index 5765389da53f8441e08333aecb1631008f18d858..8fa686c7cf5a842c866d2fdac49f4262328dd1b0 100644
|
| --- a/chrome/browser/ui/views/app_list/app_list_controller_win.cc
|
| +++ b/chrome/browser/ui/views/app_list/app_list_controller_win.cc
|
| @@ -17,6 +17,7 @@
|
| #include "chrome/browser/extensions/extension_prefs.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/lifetime/application_lifetime.h"
|
| +#include "chrome/browser/prefs/pref_service.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/profiles/profile_manager.h"
|
| #include "chrome/browser/shell_integration.h"
|
| @@ -27,6 +28,7 @@
|
| #include "chrome/browser/ui/views/browser_dialogs.h"
|
| #include "chrome/common/chrome_constants.h"
|
| #include "chrome/common/chrome_switches.h"
|
| +#include "chrome/common/pref_names.h"
|
| #include "chrome/installer/launcher_support/chrome_launcher_support.h"
|
| #include "chrome/installer/util/util_constants.h"
|
| #include "content/public/browser/browser_thread.h"
|
| @@ -119,22 +121,39 @@ class AppListControllerDelegateWin : public AppListControllerDelegate {
|
| // list to operate, and controls when the app list is opened and closed.
|
| class AppListController {
|
| public:
|
| - AppListController()
|
| - : current_view_(NULL),
|
| - can_close_app_list_(true),
|
| - app_list_is_showing_(false) {}
|
| - ~AppListController() {}
|
| + AppListController();
|
|
|
| void set_can_close(bool can_close) { can_close_app_list_ = can_close; }
|
| bool can_close() { return can_close_app_list_; }
|
| - void CreateAppList();
|
| - void ShowAppList();
|
| +
|
| + // Create the toolkit view hierarchy.
|
| + void CreateAppList(Profile* profile);
|
| +
|
| + // Activates the app list at the current mouse cursor location, creating the
|
| + // app list if necessary.
|
| + void ShowAppList(Profile* profile);
|
| +
|
| + // Update the profile path stored in local prefs, load it (if not already
|
| + // loaded), and show the app list.
|
| + void UpdateProfilePath(const FilePath& profile_file_path);
|
| +
|
| void DismissAppList();
|
| void AppListClosing();
|
| void AppListActivationChanged(bool active);
|
| app_list::AppListView* GetView() { return current_view_; }
|
|
|
| private:
|
| + // Updates the view from |profile_|.
|
| + void UpdateFromProfile();
|
| + // Load a profile, possibly asynchronously, updating |profile_| if/when ready.
|
| + void LoadProfile(const FilePath& profile_file_path);
|
| + // Callback for asynchronous profile load.
|
| + void OnProfileLoaded(Profile* profile, Profile::CreateStatus status);
|
| + // Create or recreate, and initialize |current_view_| from |profile_|.
|
| + void PopulateViewFromProfile();
|
| + // Activate the app list at the the current on-screen cursor location.
|
| + void ActivateAppList();
|
| +
|
| // Utility methods for showing the app list.
|
| bool SnapArrowLocationToTaskbarEdge(
|
| const gfx::Display& display,
|
| @@ -163,6 +182,8 @@ class AppListController {
|
|
|
| app_list::PaginationModel pagination_model_;
|
|
|
| + Profile* profile_;
|
| +
|
| // True if the controller can close the app list.
|
| bool can_close_app_list_;
|
|
|
| @@ -242,15 +263,81 @@ void AppListControllerDelegateWin::LaunchApp(
|
| profile, extension, NEW_FOREGROUND_TAB));
|
| }
|
|
|
| -void AppListController::CreateAppList() {
|
| +AppListController::AppListController()
|
| + : current_view_(NULL),
|
| + profile_(NULL),
|
| + can_close_app_list_(true),
|
| + app_list_is_showing_(false) {
|
| +}
|
| +
|
| +void AppListController::UpdateProfilePath(const FilePath& profile_file_path) {
|
| + g_browser_process->local_state()->SetString(
|
| + prefs::kAppListProfile,
|
| + profile_file_path.BaseName().MaybeAsASCII());
|
| + LoadProfile(profile_file_path);
|
| + ShowAppList(profile_);
|
| +}
|
| +
|
| +void AppListController::LoadProfile(const FilePath& profile_file_path) {
|
| + ProfileManager* profile_manager = g_browser_process->profile_manager();
|
| + Profile* old_profile = profile_;
|
| + profile_ = profile_manager->GetProfileByPath(profile_file_path);
|
| + if (!profile_) {
|
| + // Profile not yet loaded from disk.
|
| + // The following doesn't actually create a profile, since only created
|
| + // profiles are passed in here, but instructs the ProfileManager to load the
|
| + // profile asynchronously.
|
| + // TODO(koz): Make this LoadProfileAsync(), where it reports error in the
|
| + // case where the profile is not initialized, deleted off the disk or
|
| + // scheduled for deletion.
|
| + profile_manager->CreateProfileAsync(
|
| + profile_file_path,
|
| + base::Bind(&AppListController::OnProfileLoaded,
|
| + base::Unretained(this)),
|
| + string16(), string16(), false);
|
| + }
|
| +
|
| + if (current_view_ && (!profile_ || old_profile != profile_)) {
|
| + DismissAppList();
|
| + current_view_->Close();
|
| + current_view_ = NULL;
|
| + }
|
| +}
|
| +
|
| +void AppListController::OnProfileLoaded(Profile* profile,
|
| + Profile::CreateStatus status) {
|
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
| + if (status == Profile::CREATE_STATUS_INITIALIZED) {
|
| + profile_ = profile;
|
| + UpdateFromProfile();
|
| + }
|
| +}
|
| +
|
| +void AppListController::UpdateFromProfile() {
|
| + PopulateViewFromProfile();
|
| + if (app_list_is_showing_)
|
| + ActivateAppList();
|
| +}
|
| +
|
| +void AppListController::CreateAppList(Profile* profile) {
|
| #if !defined(USE_AURA)
|
| + DCHECK(profile);
|
| if (current_view_)
|
| return;
|
|
|
| + if (!profile_)
|
| + profile_ = profile;
|
| +
|
| + UpdateFromProfile();
|
| +#endif
|
| +}
|
| +
|
| +void AppListController::PopulateViewFromProfile() {
|
| +#if !defined(USE_AURA)
|
| // The controller will be owned by the view delegate, and the delegate is
|
| // owned by the app list view. The app list view manages it's own lifetime.
|
| current_view_ = new app_list::AppListView(
|
| - new AppListViewDelegate(new AppListControllerDelegateWin()));
|
| + new AppListViewDelegate(new AppListControllerDelegateWin(), profile_));
|
| gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
|
| current_view_->InitAsBubble(GetDesktopWindow(),
|
| &pagination_model_,
|
| @@ -272,20 +359,29 @@ void AppListController::CreateAppList() {
|
| #endif
|
| }
|
|
|
| -void AppListController::ShowAppList() {
|
| +void AppListController::ShowAppList(Profile* profile) {
|
| #if !defined(USE_AURA)
|
| - if (!current_view_)
|
| - CreateAppList();
|
| -
|
| if (app_list_is_showing_)
|
| return;
|
| +
|
| app_list_is_showing_ = true;
|
| browser::StartKeepAlive();
|
| + if (current_view_) {
|
| + ActivateAppList();
|
| + return;
|
| + }
|
| +
|
| + if (profile)
|
| + CreateAppList(profile);
|
| +#endif
|
| +}
|
| +
|
| +void AppListController::ActivateAppList() {
|
| + CHECK(current_view_ && app_list_is_showing_);
|
| gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
|
| UpdateArrowPositionAndAnchorPoint(cursor);
|
| current_view_->Show();
|
| current_view_->GetWidget()->Activate();
|
| -#endif
|
| }
|
|
|
| void AppListController::DismissAppList() {
|
| @@ -556,18 +652,18 @@ void CheckAppListTaskbarShortcutOnFileThread(const FilePath& user_data_dir,
|
| }
|
| }
|
|
|
| -void CreateAppList() {
|
| - g_app_list_controller.Get().CreateAppList();
|
| +void CreateAppList(Profile* profile) {
|
| + g_app_list_controller.Get().CreateAppList(profile);
|
| }
|
|
|
| } // namespace
|
|
|
| namespace chrome {
|
|
|
| -void InitAppList() {
|
| - // Check that the presence of the app list shortcut matches the flag
|
| - // kShowAppListShortcut. This will either create or delete a shortcut
|
| - // file in the user data directory.
|
| +void InitAppList(Profile* profile) {
|
| + // Check that the app list shortcut matches the flag kShowAppListShortcut.
|
| + // This will either create or delete a shortcut file in the user data
|
| + // directory.
|
| // TODO(benwells): Remove this and the flag once the app list installation
|
| // is implemented.
|
| static bool checked_shortcut = false;
|
| @@ -586,13 +682,17 @@ void InitAppList() {
|
| const int kInitWindowDelay = 5;
|
| MessageLoop::current()->PostDelayedTask(
|
| FROM_HERE,
|
| - base::Bind(&CreateAppList),
|
| + base::Bind(&CreateAppList, profile),
|
| base::TimeDelta::FromSeconds(kInitWindowDelay));
|
| }
|
|
|
| -void ShowAppList() {
|
| +void ShowAppList(Profile* profile) {
|
| // Create the App list.
|
| - g_app_list_controller.Get().ShowAppList();
|
| + g_app_list_controller.Get().ShowAppList(profile);
|
| +}
|
| +
|
| +void UpdateProfilePath(const FilePath& profile_file_path) {
|
| + g_app_list_controller.Get().UpdateProfilePath(profile_file_path);
|
| }
|
|
|
| } // namespace chrome
|
|
|