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 d8127e1000ec880104428203fdede77458bf36c3..11825c0cc330756587fa5978b0e46db08218a8b6 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,11 +2,14 @@ |
| // 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" |
| #include "base/file_util.h" |
| #include "base/lazy_instance.h" |
| +#include "base/memory/singleton.h" |
| #include "base/memory/weak_ptr.h" |
| #include "base/path_service.h" |
| #include "base/prefs/pref_service.h" |
| @@ -24,9 +27,10 @@ |
| #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/app_list/app_list_controller_win.h" |
| #include "chrome/browser/ui/views/browser_dialogs.h" |
| #include "chrome/common/chrome_constants.h" |
| #include "chrome/common/chrome_notification_types.h" |
| @@ -131,11 +135,14 @@ class AppListControllerDelegateWin : public AppListControllerDelegate { |
| // 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 { |
| +class AppListController : public AppListControllerWin { |
| public: |
| - AppListController(); |
| virtual ~AppListController(); |
| + static AppListController* GetInstance() { |
| + return Singleton<AppListController>::get(); |
| + } |
| + |
| 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_; } |
| @@ -144,45 +151,52 @@ class AppListController : public ProfileInfoCacheObserver { |
| // show it. Does nothing if the view already exists. |
| void InitView(Profile* profile); |
| + void AppListClosing(); |
| + void AppListActivationChanged(bool active); |
| + |
| + app_list::AppListView* GetView() { return current_view_; } |
| + |
| + // AppListService overrides: |
| + |
|
koz (OOO until 15th September)
2013/02/19 00:08:09
nit: no newline
tapted
2013/02/19 03:15:32
Done.
|
| + virtual void Init(Profile* initial_profile) OVERRIDE; |
| + |
| // Activates the app list at the current mouse cursor location, creating the |
| // app list if necessary. |
| - virtual void ShowAppList(Profile* profile); |
| + virtual void ShowAppList(Profile* profile) OVERRIDE; |
| // Hides the app list. |
| - virtual void DismissAppList(); |
| - |
| - virtual void OnBeginExtensionInstall(Profile* profile, |
| - const std::string& extension_id, |
| - const std::string& extension_name, |
| - const gfx::ImageSkia& installing_icon); |
| - virtual void OnDownloadProgress(Profile* profile, |
| - const std::string& extension_id, |
| - int percent_downloaded); |
| - virtual bool IsAppListVisible() const; |
| - virtual void OnInstallFailure(Profile* profile, |
| - const std::string& extension_id); |
| + virtual void DismissAppList() OVERRIDE; |
| // 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); |
| + virtual void SetAppListProfile( |
| + const base::FilePath& profile_file_path) OVERRIDE; |
| - void AppListClosing(); |
| - void AppListActivationChanged(bool active); |
| - app_list::AppListView* GetView() { return current_view_; } |
| + virtual Profile* GetCurrentAppListProfile() OVERRIDE; |
| + |
| + virtual bool IsAppListVisible() const OVERRIDE; |
| + |
| + virtual void OnBeginExtensionInstall( |
| + Profile* profile, |
| + const std::string& extension_id, |
| + const std::string& extension_name, |
| + const gfx::ImageSkia& installing_icon) OVERRIDE; |
| - // TODO(koz): Split the responsibility for tracking profiles into a |
| - // platform-independent class. |
| - // Overidden from ProfileInfoCacheObserver. |
| - void OnProfileAdded(const base::FilePath& profilePath) OVERRIDE {} |
| + virtual void OnDownloadProgress(Profile* profile, |
| + const std::string& extension_id, |
| + int percent_downloaded) OVERRIDE; |
| + |
| + virtual void OnExtensionInstallFailure( |
| + Profile* profile, const std::string& extension_id) OVERRIDE; |
| + |
| + // ProfileInfoCacheObserver 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 {} |
| + virtual void OnProfileWillBeRemoved( |
| + const base::FilePath& profile_path) OVERRIDE; |
| private: |
| + AppListController(); |
| + |
| // Loads a profile asynchronously and calls OnProfileLoaded() when done. |
| void LoadProfileAsync(const base::FilePath& profile_file_path); |
| @@ -252,30 +266,29 @@ class AppListController : public ProfileInfoCacheObserver { |
| base::WeakPtrFactory<AppListController> weak_factory_; |
| + friend struct DefaultSingletonTraits<AppListController>; |
| + |
| DISALLOW_COPY_AND_ASSIGN(AppListController); |
| }; |
| -base::LazyInstance<AppListController>::Leaky g_app_list_controller = |
| - LAZY_INSTANCE_INITIALIZER; |
| - |
| AppListControllerDelegateWin::AppListControllerDelegateWin() {} |
| AppListControllerDelegateWin::~AppListControllerDelegateWin() {} |
| void AppListControllerDelegateWin::DismissView() { |
| - g_app_list_controller.Get().DismissAppList(); |
| + AppListController::GetInstance()->DismissAppList(); |
| } |
| void AppListControllerDelegateWin::ViewActivationChanged(bool active) { |
| - g_app_list_controller.Get().AppListActivationChanged(active); |
| + AppListController::GetInstance()->AppListActivationChanged(active); |
| } |
| void AppListControllerDelegateWin::ViewClosing() { |
| - g_app_list_controller.Get().AppListClosing(); |
| + AppListController::GetInstance()->AppListClosing(); |
| } |
| gfx::NativeWindow AppListControllerDelegateWin::GetAppListWindow() { |
| - app_list::AppListView* view = g_app_list_controller.Get().GetView(); |
| + app_list::AppListView* view = AppListController::GetInstance()->GetView(); |
| return view ? view->GetWidget()->GetNativeWindow() : NULL; |
| } |
| @@ -290,11 +303,11 @@ bool AppListControllerDelegateWin::CanPin() { |
| } |
| void AppListControllerDelegateWin::OnShowExtensionPrompt() { |
| - g_app_list_controller.Get().set_can_close(false); |
| + AppListController::GetInstance()->set_can_close(false); |
| } |
| void AppListControllerDelegateWin::OnCloseExtensionPrompt() { |
| - g_app_list_controller.Get().set_can_close(true); |
| + AppListController::GetInstance()->set_can_close(true); |
| } |
| bool AppListControllerDelegateWin::CanShowCreateShortcutsDialog() { |
| @@ -310,7 +323,7 @@ void AppListControllerDelegateWin::ShowCreateShortcutsDialog( |
| extension_id); |
| DCHECK(extension); |
| - app_list::AppListView* view = g_app_list_controller.Get().GetView(); |
| + app_list::AppListView* view = AppListController::GetInstance()->GetView(); |
| if (!view) |
| return; |
| @@ -359,7 +372,7 @@ void AppListController::OnProfileWillBeRemoved( |
| } |
| } |
| -void AppListController::SetProfilePath( |
| +void AppListController::SetAppListProfile( |
| const base::FilePath& profile_file_path) { |
| g_browser_process->local_state()->SetString( |
| prefs::kAppListProfile, |
| @@ -529,12 +542,8 @@ void AppListController::OnDownloadProgress(Profile* profile, |
| view_delegate_->OnDownloadProgress(extension_id, percent_downloaded); |
| } |
| -bool AppListController::IsAppListVisible() const { |
| - return app_list_is_showing_; |
| -} |
| - |
| -void AppListController::OnInstallFailure(Profile* profile, |
| - const std::string& extension_id) { |
| +void AppListController::OnExtensionInstallFailure( |
| + Profile* profile, const std::string& extension_id) { |
| // 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 |
| @@ -814,80 +823,10 @@ void CheckAppListTaskbarShortcutOnFileThread( |
| } |
| void InitView(Profile* profile) { |
| - g_app_list_controller.Get().InitView(profile); |
| -} |
| - |
| -#if defined(USE_ASH) |
| -// The AppListControllerAsh class provides the functionality for |
| -// displaying/hiding the App list for Windows 8 Chrome ASH. |
| -class AppListControllerAsh : public AppListController { |
| - public: |
| - AppListControllerAsh() {} |
| - virtual ~AppListControllerAsh() {} |
| - |
| - // AppListController overrides. |
| - virtual void ShowAppList(Profile* profile) OVERRIDE; |
| - |
| - virtual void DismissAppList() OVERRIDE; |
| - |
| - // The OnBeginExtensionInstall/OnDownloadProgress/OnInstallFalure overrides |
| - // are not necessary for ASH as these are handled by the ash Shell. |
| - virtual void OnBeginExtensionInstall(Profile* profile, |
| - const std::string& extension_id, |
| - const std::string& extension_name, |
| - const gfx::ImageSkia& installing_icon) |
| - OVERRIDE {} |
| - |
| - virtual void OnDownloadProgress(Profile* profile, |
| - const std::string& extension_id, |
| - int percent_downloaded) OVERRIDE {} |
| - |
| - virtual bool IsAppListVisible() const OVERRIDE; |
| - |
| - virtual void OnInstallFailure( |
| - Profile* profile, |
| - const std::string& extension_id) OVERRIDE {} |
| - |
| - private: |
| - DISALLOW_COPY_AND_ASSIGN(AppListControllerAsh); |
| -}; |
| - |
| -base::LazyInstance<AppListControllerAsh>::Leaky g_app_list_controller_ash = |
| - LAZY_INSTANCE_INITIALIZER; |
| - |
| -void AppListControllerAsh::ShowAppList(Profile* profile) { |
| - // This may not work correctly if the profile passed in is different from the |
| - // one the ash Shell is currently using. |
| - // TODO(ananta): Handle profile changes correctly. |
| - if (!IsAppListVisible()) |
| - ash::Shell::GetInstance()->ToggleAppList(NULL); |
| + AppListController::GetInstance()->InitView(profile); |
| } |
| -void AppListControllerAsh::DismissAppList() { |
| - if (AppListControllerAsh::IsAppListVisible()) |
| - ash::Shell::GetInstance()->ToggleAppList(NULL); |
| -} |
| - |
| -bool AppListControllerAsh::IsAppListVisible() const { |
| - return ash::Shell::GetInstance()->GetAppListWindow() != NULL; |
| -} |
| - |
| -#endif |
| - |
| -// Returns the AppListController instance for the current environment. |
| -AppListController* GetCurrentAppListController() { |
| -#if defined(USE_ASH) |
| - if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) |
| - return &g_app_list_controller_ash.Get(); |
| -#endif |
| - return &g_app_list_controller.Get(); |
| -} |
| - |
| -} // namespace |
| - |
| -namespace chrome { |
| - |
| -void InitAppList(Profile* profile) { |
| +void AppListController::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. |
| @@ -905,60 +844,28 @@ void InitAppList(Profile* profile) { |
| } |
| // Instantiate AppListController so it listens for profile deletions. |
| - g_app_list_controller.Get(); |
| + AppListController::GetInstance(); |
| // Post a task to create the app list. This is posted to not impact startup |
| // time. |
| const int kInitWindowDelay = 5; |
| MessageLoop::current()->PostDelayedTask( |
| FROM_HERE, |
| - base::Bind(&InitView, profile), |
| + base::Bind(&::InitView, initial_profile), |
| base::TimeDelta::FromSeconds(kInitWindowDelay)); |
| } |
| -void ShowAppList(Profile* profile) { |
| - GetCurrentAppListController()->ShowAppList(profile); |
| -} |
| - |
| -void SetAppListProfile(const base::FilePath& profile_file_path) { |
| - GetCurrentAppListController()->SetProfilePath(profile_file_path); |
| +Profile* AppListController::GetCurrentAppListProfile() { |
| + return profile(); |
| } |
| -void DismissAppList() { |
| - GetCurrentAppListController()->DismissAppList(); |
| -} |
| - |
| -Profile* GetCurrentAppListProfile() { |
| - return GetCurrentAppListController()->profile(); |
| -} |
| - |
| -bool IsAppListVisible() { |
| - return GetCurrentAppListController()->IsAppListVisible(); |
| -} |
| - |
| -void NotifyAppListOfBeginExtensionInstall( |
| - Profile* profile, |
| - const std::string& extension_id, |
| - const std::string& extension_name, |
| - const gfx::ImageSkia& installing_icon) { |
| - GetCurrentAppListController()->OnBeginExtensionInstall(profile, |
| - extension_id, |
| - extension_name, |
| - installing_icon); |
| +bool AppListController::IsAppListVisible() const { |
| + return app_list_is_showing_; |
| } |
| -void NotifyAppListOfDownloadProgress( |
| - Profile* profile, |
| - const std::string& extension_id, |
| - int percent_downloaded) { |
| - GetCurrentAppListController()->OnDownloadProgress(profile, extension_id, |
| - percent_downloaded); |
| -} |
| +} // namespace |
| -void NotifyAppListOfExtensionInstallFailure( |
| - Profile* profile, |
| - const std::string& extension_id) { |
| - GetCurrentAppListController()->OnInstallFailure(profile, extension_id); |
| +// static |
| +AppListControllerWin* AppListControllerWin::GetInstance() { |
| + return AppListController::GetInstance(); |
| } |
| - |
| -} // namespace chrome |