Chromium Code Reviews| Index: apps/app_shim/extension_app_shim_handler_mac.cc |
| diff --git a/apps/app_shim/extension_app_shim_handler_mac.cc b/apps/app_shim/extension_app_shim_handler_mac.cc |
| index 95169b783497ee9631fdbbe449920e730d3d701a..166c3e6e17f73a5903d2a53d639b511da8315c72 100644 |
| --- a/apps/app_shim/extension_app_shim_handler_mac.cc |
| +++ b/apps/app_shim/extension_app_shim_handler_mac.cc |
| @@ -26,26 +26,11 @@ |
| #include "content/public/browser/notification_source.h" |
| #include "ui/base/cocoa/focus_window_set.h" |
| -namespace { |
| +namespace apps { |
| typedef extensions::ShellWindowRegistry::ShellWindowList ShellWindowList; |
| -ShellWindowList GetWindows(Profile* profile, const std::string& extension_id) { |
| - return extensions::ShellWindowRegistry::Get(profile)-> |
| - GetShellWindowsForApp(extension_id); |
| -} |
| - |
| -const extensions::Extension* GetExtension(Profile* profile, |
| - const std::string& extension_id) { |
| - return extensions::ExtensionSystem::Get(profile)->extension_service()-> |
| - GetExtensionById(extension_id, false); |
| -} |
| - |
| -} // namespace |
| - |
| -namespace apps { |
| - |
| -bool ExtensionAppShimHandler::ProfileManagerFacade::ProfileExistsForPath( |
| +bool ExtensionAppShimHandler::Delegate::ProfileExistsForPath( |
| const base::FilePath& path) { |
| ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| // Check for the profile name in the profile info cache to ensure that we |
| @@ -55,13 +40,44 @@ bool ExtensionAppShimHandler::ProfileManagerFacade::ProfileExistsForPath( |
| return cache.GetIndexOfProfileWithPath(full_path) != std::string::npos; |
| } |
| -Profile* ExtensionAppShimHandler::ProfileManagerFacade::ProfileForPath( |
| +Profile* ExtensionAppShimHandler::Delegate::ProfileForPath( |
| const base::FilePath& path) { |
| return g_browser_process->profile_manager()->GetProfile(path); |
| } |
| +ShellWindowList ExtensionAppShimHandler::Delegate::GetWindows( |
| + Profile* profile, |
| + const std::string& extension_id) { |
| + return extensions::ShellWindowRegistry::Get(profile)-> |
| + GetShellWindowsForApp(extension_id); |
| +} |
| + |
| +const extensions::Extension* |
| +ExtensionAppShimHandler::Delegate::GetExtension( |
|
tapted
2013/06/21 04:30:47
since the is_platform_app check is moving in here,
jackhou1
2013/06/21 05:46:27
Done.
|
| + Profile* profile, |
| + const std::string& extension_id) { |
| + const extensions::Extension* extension = |
| + extensions::ExtensionSystem::Get(profile)->extension_service()-> |
|
tapted
2013/06/21 04:30:47
Should DCHECK here that that extension_service is
jackhou1
2013/06/21 05:46:27
Done.
|
| + GetExtensionById(extension_id, false); |
| + return extension && extension->is_platform_app() ? extension : NULL; |
| +} |
| + |
| +content::WebContents* ExtensionAppShimHandler::Delegate::LaunchApp( |
| + Profile* profile, |
| + const extensions::Extension* extension) { |
| + return chrome::OpenApplication(chrome::AppLaunchParams( |
| + profile, extension, NEW_FOREGROUND_TAB)); |
| +} |
| + |
| +void ExtensionAppShimHandler::Delegate::LaunchShim( |
| + Profile* profile, |
| + const extensions::Extension* extension) { |
| + web_app::MaybeLaunchShortcut( |
| + web_app::ShortcutInfoForExtensionAndProfile(extension, profile)); |
| +} |
| + |
| ExtensionAppShimHandler::ExtensionAppShimHandler() |
| - : profile_manager_facade_(new ProfileManagerFacade) { |
| + : delegate_(new Delegate) { |
| // This is instantiated in BrowserProcessImpl::PreMainMessageLoopRun with |
| // AppShimHostManager. Since PROFILE_CREATED is not fired until |
| // ProfileManager::GetLastUsedProfile/GetLastOpenedProfiles, this should catch |
| @@ -79,7 +95,7 @@ bool ExtensionAppShimHandler::OnShimLaunch(Host* host, |
| const base::FilePath& profile_path = host->GetProfilePath(); |
| DCHECK(!profile_path.empty()); |
| - if (!profile_manager_facade_->ProfileExistsForPath(profile_path)) { |
| + if (!delegate_->ProfileExistsForPath(profile_path)) { |
| // User may have deleted the profile this shim was originally created for. |
| // TODO(jackhou): Add some UI for this case and remove the LOG. |
| LOG(ERROR) << "Requested directory is not a known profile '" |
| @@ -87,7 +103,7 @@ bool ExtensionAppShimHandler::OnShimLaunch(Host* host, |
| return false; |
| } |
| - Profile* profile = profile_manager_facade_->ProfileForPath(profile_path); |
| + Profile* profile = delegate_->ProfileForPath(profile_path); |
| const std::string& app_id = host->GetAppId(); |
| if (!extensions::Extension::IdIsValid(app_id)) { |
| @@ -96,9 +112,25 @@ bool ExtensionAppShimHandler::OnShimLaunch(Host* host, |
| } |
| // TODO(jackhou): Add some UI for this case and remove the LOG. |
| - if (!LaunchApp(profile, app_id, launch_type)) |
| + const extensions::Extension* extension = |
| + delegate_->GetExtension(profile, app_id); |
| + if (!extension) { |
| + LOG(ERROR) << "Attempted to launch nonexistent app with id '" |
| + << app_id << "'."; |
| + return false; |
| + } |
| + |
| + if (launch_type == APP_SHIM_LAUNCH_REGISTER_ONLY && |
|
tapted
2013/06/21 04:30:47
needs curlies if the condition is multi-line
jackhou1
2013/06/21 05:46:27
Done.
|
| + delegate_->GetWindows(profile, app_id).empty()) |
|
tapted
2013/06/21 04:30:47
Should this be !empty()?
Maybe a comment, like ~"
jackhou1
2013/06/21 05:46:27
It should be empty(), because it returns false if
|
| return false; |
| + // TODO(jeremya): Handle the case that launching the app fails. Probably we |
| + // need to watch for 'app successfully launched' or at least 'background page |
| + // exists/was created' and time out with failure if we don't see that sign of |
| + // life within a certain window. |
| + if (launch_type == APP_SHIM_LAUNCH_NORMAL) |
| + delegate_->LaunchApp(profile, extension); |
|
tapted
2013/06/21 04:30:47
Should it return false if LaunchApp returns NULL h
jackhou1
2013/06/21 05:46:27
Turns out LaunchApplication always returns NULL fo
|
| + |
| // The first host to claim this (profile, app_id) becomes the main host. |
| // For any others, focus the app and return false. |
| if (!hosts_.insert(make_pair(make_pair(profile, app_id), host)).second) { |
| @@ -110,10 +142,10 @@ bool ExtensionAppShimHandler::OnShimLaunch(Host* host, |
| } |
| void ExtensionAppShimHandler::OnShimClose(Host* host) { |
| - DCHECK(profile_manager_facade_->ProfileExistsForPath( |
| + DCHECK(delegate_->ProfileExistsForPath( |
|
tapted
2013/06/21 04:30:47
nit: can this fit on the line above now?
jackhou1
2013/06/21 05:46:27
Done.
|
| host->GetProfilePath())); |
| Profile* profile = |
| - profile_manager_facade_->ProfileForPath(host->GetProfilePath()); |
| + delegate_->ProfileForPath(host->GetProfilePath()); |
|
tapted
2013/06/21 04:30:47
nit: one line?
up to 6 more below too
jackhou1
2013/06/21 05:46:27
Done.
|
| HostMap::iterator it = hosts_.find(make_pair(profile, host->GetAppId())); |
| // Any hosts other than the main host will still call OnShimClose, so ignore |
| @@ -123,12 +155,13 @@ void ExtensionAppShimHandler::OnShimClose(Host* host) { |
| } |
| void ExtensionAppShimHandler::OnShimFocus(Host* host) { |
| - DCHECK(profile_manager_facade_->ProfileExistsForPath( |
| + DCHECK(delegate_->ProfileExistsForPath( |
| host->GetProfilePath())); |
| Profile* profile = |
| - profile_manager_facade_->ProfileForPath(host->GetProfilePath()); |
| + delegate_->ProfileForPath(host->GetProfilePath()); |
| - const ShellWindowList windows = GetWindows(profile, host->GetAppId()); |
| + const ShellWindowList windows = |
| + delegate_->GetWindows(profile, host->GetAppId()); |
| std::set<gfx::NativeWindow> native_windows; |
| for (ShellWindowList::const_iterator it = windows.begin(); |
| it != windows.end(); ++it) { |
| @@ -138,43 +171,22 @@ void ExtensionAppShimHandler::OnShimFocus(Host* host) { |
| } |
| void ExtensionAppShimHandler::OnShimQuit(Host* host) { |
| - DCHECK(profile_manager_facade_->ProfileExistsForPath( |
| + DCHECK(delegate_->ProfileExistsForPath( |
| host->GetProfilePath())); |
| Profile* profile = |
| - profile_manager_facade_->ProfileForPath(host->GetProfilePath()); |
| + delegate_->ProfileForPath(host->GetProfilePath()); |
| - const ShellWindowList windows = GetWindows(profile, host->GetAppId()); |
| + const ShellWindowList windows = |
| + delegate_->GetWindows(profile, host->GetAppId()); |
| for (extensions::ShellWindowRegistry::const_iterator it = windows.begin(); |
| it != windows.end(); ++it) { |
| (*it)->GetBaseWindow()->Close(); |
| } |
| } |
| -void ExtensionAppShimHandler::set_profile_manager_facade( |
| - ProfileManagerFacade* profile_manager_facade) { |
| - profile_manager_facade_.reset(profile_manager_facade); |
| -} |
| - |
| -bool ExtensionAppShimHandler::LaunchApp(Profile* profile, |
| - const std::string& app_id, |
| - AppShimLaunchType launch_type) { |
| - const extensions::Extension* extension = GetExtension(profile, app_id); |
| - if (!extension) { |
| - LOG(ERROR) << "Attempted to launch nonexistent app with id '" |
| - << app_id << "'."; |
| - return false; |
| - } |
| - |
| - if (launch_type == APP_SHIM_LAUNCH_REGISTER_ONLY) |
| - return !GetWindows(profile, app_id).empty(); |
| - |
| - // TODO(jeremya): Handle the case that launching the app fails. Probably we |
| - // need to watch for 'app successfully launched' or at least 'background page |
| - // exists/was created' and time out with failure if we don't see that sign of |
| - // life within a certain window. |
| - chrome::OpenApplication(chrome::AppLaunchParams( |
| - profile, extension, NEW_FOREGROUND_TAB)); |
| - return true; |
| +void ExtensionAppShimHandler::set_dependency_facade( |
| + Delegate* dependency_facade) { |
| + delegate_.reset(dependency_facade); |
| } |
| void ExtensionAppShimHandler::Observe( |
| @@ -211,15 +223,15 @@ void ExtensionAppShimHandler::OnAppStart(Profile* profile, |
| void ExtensionAppShimHandler::OnAppActivated(Profile* profile, |
| const std::string& app_id) { |
| - const extensions::Extension* extension = GetExtension(profile, app_id); |
| - if (!extension || !extension->is_platform_app()) |
| + const extensions::Extension* extension = |
| + delegate_->GetExtension(profile, app_id); |
| + if (!extension) |
| return; |
| - if (hosts_.count(make_pair(profile, extension->id()))) |
| + if (hosts_.count(make_pair(profile, app_id))) |
| return; |
| - web_app::MaybeLaunchShortcut( |
| - web_app::ShortcutInfoForExtensionAndProfile(extension, profile)); |
| + delegate_->LaunchShim(profile, extension); |
| } |
| void ExtensionAppShimHandler::OnAppDeactivated(Profile* profile, |