#include "base/bind.h"
#include "base/message_loop/message_loop.h"
+#include "chrome/browser/apps/scoped_keep_alive.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_shower_delegate.h"
#include "chrome/browser/ui/app_list/app_list_view_delegate.h"
-#include "chrome/browser/ui/app_list/scoped_keep_alive.h"
#include "ui/app_list/views/app_list_view.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/screen.h"
AppListShower::~AppListShower() {
}
-void AppListShower::ShowForProfile(Profile* requested_profile) {
+void AppListShower::ShowForCurrentProfile() {
+ DCHECK(HasView());
+ keep_alive_.reset(new ScopedKeepAlive);
+
// If the app list is already displaying |profile| just activate it (in case
// we have lost focus).
- if (IsAppListVisible() && (requested_profile == profile_)) {
- Show();
- return;
- }
-
- if (!HasView()) {
- CreateViewForProfile(requested_profile);
- } else if (requested_profile != profile_) {
- profile_ = requested_profile;
- UpdateViewForNewProfile();
- }
-
- keep_alive_.reset(new ScopedKeepAlive);
if (!IsAppListVisible())
delegate_->MoveNearCursor(app_list_);
+
Show();
}
}
void AppListShower::CreateViewForProfile(Profile* requested_profile) {
- profile_ = requested_profile;
+ DCHECK(requested_profile);
+ if (HasView() && requested_profile->IsSameProfile(profile_))
+ return;
+
+ profile_ = requested_profile->GetOriginalProfile();
+ if (HasView()) {
+ UpdateViewForNewProfile();
+ return;
+ }
app_list_ = MakeViewForCurrentProfile();
delegate_->OnViewCreated();
}
}
app_list::AppListView* AppListShower::MakeViewForCurrentProfile() {
- // The view delegate will be owned by the app list view. The app list view
- // manages its own lifetime.
- AppListViewDelegate* view_delegate = new AppListViewDelegate(
- profile_, delegate_->GetControllerDelegateForCreate());
- app_list::AppListView* view = new app_list::AppListView(view_delegate);
+ // The app list view manages its own lifetime.
+ app_list::AppListView* view =
+ new app_list::AppListView(delegate_->GetViewDelegateForCreate());
gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
view->InitAsBubbleAtFixedLocation(NULL,
0,