Chromium Code Reviews| 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 26e373bcb0eb75a5da3bbc5a3fe007907c69486b..b7a407a27890c96736ac61ad4c1bbd6ff1e76665 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 |
| @@ -2,6 +2,8 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "chrome/browser/ui/views/app_list/app_list_controller_win.h" |
| + |
| #include <sstream> |
| #include "base/command_line.h" |
| @@ -24,8 +26,8 @@ |
| #include "chrome/browser/profiles/profile_manager.h" |
| #include "chrome/browser/shell_integration.h" |
| #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
| -#include "chrome/browser/ui/app_list/app_list_util.h" |
| #include "chrome/browser/ui/app_list/app_list_view_delegate.h" |
| +#include "chrome/browser/ui/app_list_service.h" |
| #include "chrome/browser/ui/extensions/application_launch.h" |
| #include "chrome/browser/ui/views/browser_dialogs.h" |
| #include "chrome/common/chrome_constants.h" |
| @@ -46,7 +48,6 @@ |
| #include "ui/gfx/display.h" |
| #include "ui/gfx/image/image_skia.h" |
| #include "ui/gfx/screen.h" |
| -#include "ui/views/bubble/bubble_border.h" |
|
tapted
2013/02/11 04:04:20
there might be a few more includes duped from the
benwells
2013/02/11 05:52:36
Any includes in x.h can be left out of x.cc.
|
| #include "ui/views/widget/widget.h" |
| namespace { |
| @@ -151,127 +152,6 @@ class AppListControllerDelegateWin : public AppListControllerDelegate { |
| DISALLOW_COPY_AND_ASSIGN(AppListControllerDelegateWin); |
| }; |
| -// The AppListController class manages global resources needed for the app |
| -// list to operate, and controls when the app list is opened and closed. |
| -class AppListController : public ProfileInfoCacheObserver { |
| - public: |
| - AppListController(); |
| - |
| - void set_can_close(bool can_close) { can_close_app_list_ = can_close; } |
| - bool can_close() { return can_close_app_list_; } |
| - Profile* profile() const { return profile_; } |
| - bool app_list_is_showing() const { return app_list_is_showing_; } |
| - |
| - // 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 base::FilePath& profile_file_path); |
| - |
| - void DismissAppList(); |
| - void AppListClosing(); |
| - void AppListActivationChanged(bool active); |
| - app_list::AppListView* GetView() { return current_view_; } |
| - |
| - // TODO(koz): Split the responsibility for tracking profiles into a |
| - // platform-independent class. |
| - // Overidden from ProfileInfoCacheObserver. |
| - void OnProfileAdded(const base::FilePath& profilePath) OVERRIDE {} |
| - // We need to watch for profile removal to keep kAppListProfile updated. |
| - void OnProfileWillBeRemoved(const base::FilePath& profile_path) OVERRIDE; |
| - void OnProfileWasRemoved(const base::FilePath& profile_path, |
| - const string16& profile_name) OVERRIDE {} |
| - void OnProfileNameChanged(const base::FilePath& profile_path, |
| - const string16& profile_name) OVERRIDE {} |
| - void OnProfileAvatarChanged(const base::FilePath& profile_path) OVERRIDE {} |
| - |
| - void OnBeginExtensionInstall(Profile* profile, |
| - const std::string& extension_id, |
| - const std::string& extension_name, |
| - const gfx::ImageSkia& installing_icon); |
| - void OnDownloadProgress(Profile* profile, |
| - const std::string& extension_id, |
| - int percent_downloaded); |
| - |
| - private: |
| - // Loads a profile asynchronously and calls OnProfileLoaded() when done. |
| - void LoadProfileAsync(const base::FilePath& profile_file_path); |
| - |
| - // Callback for asynchronous profile load. |
| - void OnProfileLoaded(int profile_load_sequence_id, |
| - Profile* profile, |
| - Profile::CreateStatus status); |
| - |
| - // We need to keep the browser alive while we are loading a profile as that |
| - // shows intent to show the app list. These two functions track our pending |
| - // profile loads and start or end browser keep alive accordingly. |
| - void IncrementPendingProfileLoads(); |
| - void DecrementPendingProfileLoads(); |
| - |
| - // Create or recreate, and initialize |current_view_| from |profile|. |
| - void PopulateViewFromProfile(Profile* profile); |
| - |
| - // Utility methods for showing the app list. |
| - void SnapArrowLocationToTaskbarEdge( |
| - const gfx::Display& display, |
| - views::BubbleBorder::ArrowLocation* arrow, |
| - gfx::Point* anchor); |
| - void UpdateAnchorLocationForCursor( |
| - const gfx::Display& display, |
| - views::BubbleBorder::ArrowLocation* arrow, |
| - gfx::Point* anchor); |
| - void UpdateArrowPositionAndAnchorPoint(const gfx::Point& cursor); |
| - string16 GetAppListIconPath(); |
| - |
| - // Check if the app list or the taskbar has focus. The app list is kept |
| - // visible whenever either of these have focus, which allows it to be |
| - // pinned but will hide it if it otherwise loses focus. This is checked |
| - // periodically whenever the app list does not have focus. |
| - void CheckTaskbarOrViewHasFocus(); |
| - |
| - // Weak pointer. The view manages its own lifetime. |
| - app_list::AppListView* current_view_; |
| - |
| - // Weak pointer. The view owns the view delegate. |
| - AppListViewDelegate* view_delegate_; |
| - |
| - // Timer used to check if the taskbar or app list is active. Using a timer |
| - // means we don't need to hook Windows, which is apparently not possible |
| - // since Vista (and is not nice at any time). |
| - base::RepeatingTimer<AppListController> timer_; |
| - |
| - 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_; |
| - |
| - // True if the app list is showing. Used to ensure we only ever have 0 or 1 |
| - // 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_; |
| - |
| - // How many profile loads are pending. |
| - int pending_profile_loads_; |
| - |
| - base::WeakPtrFactory<AppListController> weak_factory_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(AppListController); |
| -}; |
| - |
| -base::LazyInstance<AppListController>::Leaky g_app_list_controller = |
| - LAZY_INSTANCE_INITIALIZER; |
| - |
| AppListControllerDelegateWin::AppListControllerDelegateWin() {} |
| AppListControllerDelegateWin::~AppListControllerDelegateWin() {} |
| @@ -367,7 +247,9 @@ void AppListControllerDelegateWin::LaunchApp( |
| profile, extension, NEW_FOREGROUND_TAB)); |
| } |
| -AppListController::AppListController() |
| +} // namespace |
| + |
| +AppListControllerWin::AppListControllerWin() |
| : current_view_(NULL), |
| view_delegate_(NULL), |
| profile_(NULL), |
| @@ -380,7 +262,7 @@ AppListController::AppListController() |
| profile_manager->GetProfileInfoCache().AddObserver(this); |
| } |
| -void AppListController::OnProfileWillBeRemoved( |
| +void AppListControllerWin::OnProfileWillBeRemoved( |
| const base::FilePath& profile_path) { |
| // If the profile the app list uses just got deleted, reset it to the last |
| // used profile. |
| @@ -393,7 +275,7 @@ void AppListController::OnProfileWillBeRemoved( |
| } |
| } |
| -void AppListController::SetProfilePath( |
| +void AppListControllerWin::SetProfilePath( |
| const base::FilePath& profile_file_path) { |
| g_browser_process->local_state()->SetString( |
| prefs::kAppListProfile, |
| @@ -409,7 +291,7 @@ void AppListController::SetProfilePath( |
| ShowAppList(profile); |
| } |
| -void AppListController::LoadProfileAsync( |
| +void AppListControllerWin::LoadProfileAsync( |
| const base::FilePath& profile_file_path) { |
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| @@ -426,9 +308,9 @@ void AppListController::LoadProfileAsync( |
| string16(), string16(), false); |
| } |
| -void AppListController::OnProfileLoaded(int profile_load_sequence_id, |
| - Profile* profile, |
| - Profile::CreateStatus status) { |
| +void AppListControllerWin::OnProfileLoaded(int profile_load_sequence_id, |
| + Profile* profile, |
| + Profile::CreateStatus status) { |
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| switch (status) { |
| case Profile::CREATE_STATUS_CREATED: |
| @@ -447,19 +329,19 @@ void AppListController::OnProfileLoaded(int profile_load_sequence_id, |
| } |
| -void AppListController::IncrementPendingProfileLoads() { |
| +void AppListControllerWin::IncrementPendingProfileLoads() { |
| pending_profile_loads_++; |
| if (pending_profile_loads_ == 1) |
| chrome::StartKeepAlive(); |
| } |
| -void AppListController::DecrementPendingProfileLoads() { |
| +void AppListControllerWin::DecrementPendingProfileLoads() { |
| pending_profile_loads_--; |
| if (pending_profile_loads_ == 0) |
| chrome::EndKeepAlive(); |
| } |
| -void AppListController::ShowAppList(Profile* profile) { |
| +void AppListControllerWin::ShowAppList(Profile* profile) { |
| DCHECK(profile); |
| // Invalidate any pending profile path loads. |
| @@ -491,13 +373,13 @@ void AppListController::ShowAppList(Profile* profile) { |
| current_view_->GetWidget()->SetAlwaysOnTop(true); |
| } |
| -void AppListController::InitView(Profile* profile) { |
| +void AppListControllerWin::InitView(Profile* profile) { |
| if (current_view_) |
| return; |
| PopulateViewFromProfile(profile); |
| } |
| -void AppListController::PopulateViewFromProfile(Profile* profile) { |
| +void AppListControllerWin::PopulateViewFromProfile(Profile* profile) { |
| #if !defined(USE_AURA) |
| if (profile == profile_) |
| return; |
| @@ -527,7 +409,7 @@ void AppListController::PopulateViewFromProfile(Profile* profile) { |
| #endif |
| } |
| -void AppListController::DismissAppList() { |
| +void AppListControllerWin::DismissAppList() { |
| if (current_view_ && app_list_is_showing_ && can_close_app_list_) { |
| current_view_->GetWidget()->Hide(); |
| timer_.Stop(); |
| @@ -536,13 +418,13 @@ void AppListController::DismissAppList() { |
| } |
| } |
| -void AppListController::AppListClosing() { |
| +void AppListControllerWin::AppListClosing() { |
| current_view_ = NULL; |
| view_delegate_ = NULL; |
| timer_.Stop(); |
| } |
| -void AppListController::AppListActivationChanged(bool active) { |
| +void AppListControllerWin::AppListActivationChanged(bool active) { |
| const int kFocusCheckIntervalMS = 250; |
| if (active) { |
| timer_.Stop(); |
| @@ -554,7 +436,7 @@ void AppListController::AppListActivationChanged(bool active) { |
| &AppListController::CheckTaskbarOrViewHasFocus); |
| } |
| -void AppListController::OnBeginExtensionInstall( |
| +void AppListControllerWin::OnBeginExtensionInstall( |
| Profile* profile, |
| const std::string& extension_id, |
| const std::string& extension_name, |
| @@ -564,9 +446,9 @@ void AppListController::OnBeginExtensionInstall( |
| installing_icon); |
| } |
| -void AppListController::OnDownloadProgress(Profile* profile, |
| - const std::string& extension_id, |
| - int percent_downloaded) { |
| +void AppListControllerWin::OnDownloadProgress(Profile* profile, |
| + const std::string& extension_id, |
| + int percent_downloaded) { |
| // We only have a model for the current profile, so ignore events about |
| // others. |
| // TODO(koz): We should keep a model for each profile so we can record |
| @@ -597,6 +479,8 @@ bool GetTaskbarRect(gfx::Rect* rect) { |
| #endif |
| } |
| +namespace { |
| + |
| // Used to position the view in a corner, which requires |anchor| to be in |
| // the center of the desired view location. This helper function updates |
| // |anchor| thus, using the location of the corner in |corner|, the distance |
| @@ -612,7 +496,9 @@ void FloatFromCorner(const gfx::Point& corner, |
| *arrow = views::BubbleBorder::FLOAT; |
| } |
| -void AppListController::SnapArrowLocationToTaskbarEdge( |
| +} // namespace |
| + |
| +void AppListControllerWin::SnapArrowLocationToTaskbarEdge( |
| const gfx::Display& display, |
| views::BubbleBorder::ArrowLocation* arrow, |
| gfx::Point* anchor) { |
| @@ -708,7 +594,7 @@ void AppListController::SnapArrowLocationToTaskbarEdge( |
| *arrow = views::BubbleBorder::RIGHT_CENTER; |
| } |
| -void AppListController::UpdateArrowPositionAndAnchorPoint( |
| +void AppListControllerWin::UpdateArrowPositionAndAnchorPoint( |
| const gfx::Point& cursor) { |
| gfx::Point anchor(cursor); |
| gfx::Screen* screen = |
| @@ -722,7 +608,7 @@ void AppListController::UpdateArrowPositionAndAnchorPoint( |
| current_view_->SetAnchorPoint(anchor); |
| } |
| -string16 AppListController::GetAppListIconPath() { |
| +string16 AppListControllerWin::GetAppListIconPath() { |
| base::FilePath icon_path; |
| if (!PathService::Get(base::FILE_EXE, &icon_path)) { |
| NOTREACHED(); |
| @@ -736,7 +622,7 @@ string16 AppListController::GetAppListIconPath() { |
| return result; |
| } |
| -void AppListController::CheckTaskbarOrViewHasFocus() { |
| +void AppListControllerWin::CheckTaskbarOrViewHasFocus() { |
| #if !defined(USE_AURA) |
| // Don't bother checking if the view has been closed. |
| if (!current_view_) |
| @@ -768,6 +654,8 @@ void AppListController::CheckTaskbarOrViewHasFocus() { |
| #endif |
| } |
| +namespace { |
| + |
| // Check that a taskbar shortcut exists if it should, or does not exist if |
| // it should not. A taskbar shortcut should exist if the switch |
| // kShowAppListShortcut is set. The shortcut will be created or deleted in |
| @@ -828,9 +716,7 @@ void InitView(Profile* profile) { |
| } // namespace |
| -namespace chrome { |
| - |
| -void InitAppList(Profile* profile) { |
| +void AppListControllerWin::Init(Profile* initial_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. |
| @@ -855,50 +741,40 @@ void InitAppList(Profile* profile) { |
| const int kInitWindowDelay = 5; |
| MessageLoop::current()->PostDelayedTask( |
| FROM_HERE, |
| - base::Bind(&InitView, profile), |
| + base::Bind(&InitView, initial_profile), |
| base::TimeDelta::FromSeconds(kInitWindowDelay)); |
| } |
| -#if !defined(USE_ASH) |
| -void ShowAppList(Profile* profile) { |
| - g_app_list_controller.Get().ShowAppList(profile); |
| +Profile* AppListControllerWin::GetCurrentAppListProfile() { |
| + return profile(); |
| } |
| -void SetAppListProfile(const base::FilePath& profile_file_path) { |
| - g_app_list_controller.Get().SetProfilePath(profile_file_path); |
| +bool AppListControllerWin::IsAppListVisible() { |
| + return app_list_is_showing(); |
| } |
| -void DismissAppList() { |
| - g_app_list_controller.Get().DismissAppList(); |
| -} |
| - |
| -Profile* GetCurrentAppListProfile() { |
| - return g_app_list_controller.Get().profile(); |
| -} |
| - |
| -bool IsAppListVisible() { |
| - return g_app_list_controller.Get().app_list_is_showing(); |
| -} |
| - |
| -void NotifyAppListOfBeginExtensionInstall( |
| +void AppListControllerWin::NotifyAppListOfBeginExtensionInstall( |
| Profile* profile, |
| const std::string& extension_id, |
| const std::string& extension_name, |
| const gfx::ImageSkia& installing_icon) { |
| - g_app_list_controller.Get().OnBeginExtensionInstall(profile, |
| - extension_id, |
| - extension_name, |
| - installing_icon); |
| + OnBeginExtensionInstall(profile, extension_id, extension_name, |
| + installing_icon); |
| } |
| -void NotifyAppListOfDownloadProgress( |
| +void AppListControllerWin::NotifyAppListOfDownloadProgress( |
| Profile* profile, |
| const std::string& extension_id, |
| int percent_downloaded) { |
| - g_app_list_controller.Get().OnDownloadProgress(profile, extension_id, |
| - percent_downloaded); |
| + OnDownloadProgress(profile, extension_id, percent_downloaded); |
| } |
| -#endif // !defined(USE_ASH) |
| - |
| -} // namespace chrome |
| +// static |
| +AppListService* AppListService::Get() { |
| +#if defined(USE_ASH) |
| + // TODO(tapted): Pick one based on desktop type or some other metric. |
| + return GetDisabled(); |
| +#else |
| + return AppListControllerWin::GetInstance(); |
| +#endif |
| +} |