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

Unified Diff: chrome/browser/ui/views/app_list/app_list_controller_win.cc

Issue 11968034: Enable profile switching for standalone App Launcher via the Settings App. (Closed) Base URL: git://nomatter.syd/chromium/src.git@master
Patch Set: respond to comments Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
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..b2f6dab57e1f2984e74e12b202b01913e7f41f7e 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
@@ -7,6 +7,7 @@
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/lazy_instance.h"
+#include "base/memory/weak_ptr.h"
#include "base/path_service.h"
#include "base/time.h"
#include "base/timer.h"
@@ -17,6 +18,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 +29,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 +122,40 @@ 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();
+
+ // Creates the app list view and populates it from |profile|, but doesn't
+ // show it. Does nothing if the view already exists.
+ void InitView(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 SetProfilePath(const FilePath& profile_file_path);
+
void DismissAppList();
void AppListClosing();
void AppListActivationChanged(bool active);
app_list::AppListView* GetView() { return current_view_; }
private:
+ // Loads a profile asynchronously and calls OnProfileLoaded() when done.
+ void LoadProfileAsync(const FilePath& profile_file_path);
+
+ // Callback for asynchronous profile load.
+ void OnProfileLoaded(int profile_load_sequence_id,
+ Profile* profile,
+ Profile::CreateStatus status);
+
+ // Create or recreate, and initialize |current_view_| from |profile_|.
+ void PopulateViewFromProfile();
benwells 2013/01/21 00:36:31 Nit: this could take an input profile and set prof
koz (OOO until 15th September) 2013/01/21 23:23:15 Done.
+
// Utility methods for showing the app list.
bool SnapArrowLocationToTaskbarEdge(
const gfx::Display& display,
@@ -163,6 +184,9 @@ class AppListController {
app_list::PaginationModel pagination_model_;
+ // The profile the AppList is currently displaying.
+ Profile* profile_;
+
// True if the controller can close the app list.
bool can_close_app_list_;
@@ -170,6 +194,11 @@ class AppListController {
// browser process keep-alives active.
bool app_list_is_showing_;
+ // Incremented to indicate that pending profile loads are no longer valid.
+ int profile_load_sequence_id_;
+
+ base::WeakPtrFactory<AppListController> weak_factory_;
+
DISALLOW_COPY_AND_ASSIGN(AppListController);
};
@@ -242,15 +271,95 @@ void AppListControllerDelegateWin::LaunchApp(
profile, extension, NEW_FOREGROUND_TAB));
}
-void AppListController::CreateAppList() {
-#if !defined(USE_AURA)
+AppListController::AppListController()
+ : current_view_(NULL),
+ profile_(NULL),
+ can_close_app_list_(true),
+ app_list_is_showing_(false),
+ profile_load_sequence_id_(0),
+ weak_factory_(this){
tapted 2013/01/21 00:37:02 nit: missing space before '{', and I think convent
koz (OOO until 15th September) 2013/01/21 23:23:15 Done.
+}
+
+void AppListController::SetProfilePath(const FilePath& profile_file_path) {
+ g_browser_process->local_state()->SetString(
+ prefs::kAppListProfile,
+ profile_file_path.BaseName().MaybeAsASCII());
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ Profile* profile = profile_manager->GetProfileByPath(profile_file_path);
+
+
benwells 2013/01/21 00:36:31 Nit: extra blank line.
tapted 2013/01/21 00:37:02 nit: extra line can be removed
koz (OOO until 15th September) 2013/01/21 23:23:15 Done.
koz (OOO until 15th September) 2013/01/21 23:23:15 Done.
+ if (!profile) {
+ LoadProfileAsync(profile_file_path);
+ return;
+ }
+
+ ShowAppList(profile);
+}
+
+void AppListController::LoadProfileAsync(const FilePath& profile_file_path) {
+ // Invalidate any pending profile path loads.
benwells 2013/01/21 00:36:31 Add DCHECK On UI thread.
koz (OOO until 15th September) 2013/01/21 23:23:15 Done.
+ profile_load_sequence_id_++;
+
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ profile_manager->CreateProfileAsync(
+ profile_file_path,
+ base::Bind(&AppListController::OnProfileLoaded,
+ weak_factory_.GetWeakPtr(), profile_load_sequence_id_),
+ string16(), string16(), false);
+}
+
+void AppListController::OnProfileLoaded(int profile_load_sequence_id,
+ Profile* profile,
+ Profile::CreateStatus status) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ // A profile has been shown since last time, so we don't care about this
+ // profile loading anymore.
+ if (profile_load_sequence_id != profile_load_sequence_id_)
+ return;
+
+ if (status == Profile::CREATE_STATUS_INITIALIZED)
+ ShowAppList(profile);
+}
+
+void AppListController::ShowAppList(Profile* profile) {
+ DCHECK(profile);
+
+ // Invalidate any pending profile path loads.
+ profile_load_sequence_id_++;
+
+ // Do nothing if the app list is already displaying |profile|.
+ if (app_list_is_showing_ && (profile == profile_))
+ return;
+
+ DismissAppList();
tapted 2013/01/21 00:37:02 Should the next three lines be only if profile !=
koz (OOO until 15th September) 2013/01/21 23:23:15 Cool, good catch. I've changed PopulateViewFromPro
+ profile_ = profile;
+ PopulateViewFromProfile();
+
+ if (!app_list_is_showing_) {
+ app_list_is_showing_ = true;
+ browser::StartKeepAlive();
+ }
+
+ CHECK(current_view_ && app_list_is_showing_);
benwells 2013/01/21 00:36:31 Just wondering, why not a DCHECK?
koz (OOO until 15th September) 2013/01/21 23:23:15 Not sure; this was inherited from Trent's change.
+ gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
+ UpdateArrowPositionAndAnchorPoint(cursor);
+ current_view_->Show();
+ current_view_->GetWidget()->Activate();
+}
+
+void AppListController::InitView(Profile* profile) {
if (current_view_)
return;
+ profile_ = profile;
+ PopulateViewFromProfile();
+}
+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,22 +381,6 @@ void AppListController::CreateAppList() {
#endif
}
-void AppListController::ShowAppList() {
-#if !defined(USE_AURA)
- if (!current_view_)
- CreateAppList();
-
- if (app_list_is_showing_)
- return;
- app_list_is_showing_ = true;
- browser::StartKeepAlive();
- gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
- UpdateArrowPositionAndAnchorPoint(cursor);
- current_view_->Show();
- current_view_->GetWidget()->Activate();
-#endif
-}
-
void AppListController::DismissAppList() {
if (current_view_ && app_list_is_showing_ && can_close_app_list_) {
current_view_->GetWidget()->Hide();
@@ -556,18 +649,18 @@ void CheckAppListTaskbarShortcutOnFileThread(const FilePath& user_data_dir,
}
}
-void CreateAppList() {
- g_app_list_controller.Get().CreateAppList();
+void InitView(Profile* profile) {
+ g_app_list_controller.Get().InitView(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 +679,38 @@ void InitAppList() {
const int kInitWindowDelay = 5;
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
- base::Bind(&CreateAppList),
+ base::Bind(&InitView, profile),
base::TimeDelta::FromSeconds(kInitWindowDelay));
}
-void ShowAppList() {
+void ShowAppList(Profile* profile) {
// Create the App list.
tapted 2013/01/21 00:37:02 nit (while you're here): this comment is out of da
koz (OOO until 15th September) 2013/01/21 23:23:15 Done.
- g_app_list_controller.Get().ShowAppList();
+ g_app_list_controller.Get().ShowAppList(profile);
+}
+
+void SetAppListProfile(const FilePath& profile_file_path) {
+ g_app_list_controller.Get().SetProfilePath(profile_file_path);
+}
+
+FilePath GetAppListProfilePath(const FilePath& user_data_dir) {
+ PrefService* local_state = g_browser_process->local_state();
+ DCHECK(local_state);
+
+ std::string app_list_profile;
+ if (local_state->HasPrefPath(prefs::kAppListProfile))
+ app_list_profile = local_state->GetString(prefs::kAppListProfile);
+
+ // If the user has no profile preference for the app launcher, default to the
+ // last browser profile used.
benwells 2013/01/21 00:36:31 How does this deal with the profile having been si
koz (OOO until 15th September) 2013/01/21 23:23:15 Currently this will re-create the profile (as per
+ if (app_list_profile.empty() &&
+ local_state->HasPrefPath(prefs::kProfileLastUsed))
+ app_list_profile = local_state->GetString(prefs::kProfileLastUsed);
+
+ std::string profile_path = app_list_profile.empty() ?
+ chrome::kInitialProfile :
+ app_list_profile;
+
+ return user_data_dir.AppendASCII(profile_path);
}
} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698