Index: apps/app_shim/app_shim_host_mac.cc |
diff --git a/apps/app_shim/app_shim_host_mac.cc b/apps/app_shim/app_shim_host_mac.cc |
index bfe28f9ac434b383dd9f2090769006bf839f1cda..7a6ffd130fff13b88b2eb39ee9cbd60aa757df47 100644 |
--- a/apps/app_shim/app_shim_host_mac.cc |
+++ b/apps/app_shim/app_shim_host_mac.cc |
@@ -39,6 +39,14 @@ void AppShimHost::ServeChannel(const IPC::ChannelHandle& handle) { |
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); |
} |
+const std::string& AppShimHost::app_id() const { |
+ return app_id_; |
+} |
+ |
+Profile* AppShimHost::profile() const { |
+ return profile_; |
+} |
+ |
bool AppShimHost::OnMessageReceived(const IPC::Message& message) { |
DCHECK(CalledOnValidThread()); |
bool handled = true; |
@@ -62,57 +70,23 @@ bool AppShimHost::Send(IPC::Message* message) { |
void AppShimHost::OnLaunchApp(std::string profile_dir, std::string app_id) { |
DCHECK(CalledOnValidThread()); |
+ if (profile_) { |
tapted
2013/05/21 06:15:37
Maybe DCHECK(!profile) as well? There would need t
jackhou1
2013/05/22 23:54:44
Done.
|
+ // Only one app launch message per channel. |
+ Send(new AppShimMsg_LaunchApp_Done(false)); |
+ return; |
+ } |
+ profile_ = FetchProfileForDirectory(profile_dir); |
tapted
2013/05/21 06:15:37
nit: blank line before, for early return
jackhou1
2013/05/22 23:54:44
Done.
|
app_id_ = app_id; |
apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); |
- bool success = |
- handler ? handler->OnShimLaunch(this) : LaunchAppImpl(profile_dir); |
+ bool success = handler && handler->OnShimLaunch(this); |
Send(new AppShimMsg_LaunchApp_Done(success)); |
} |
void AppShimHost::OnFocus() { |
DCHECK(CalledOnValidThread()); |
apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); |
- if (handler) { |
+ if (handler) |
handler->OnShimFocus(this); |
- return; |
- } |
- |
- if (!profile_) |
- return; |
- extensions::ShellWindowRegistry* registry = |
- extensions::ShellWindowRegistry::Get(profile_); |
- const std::set<ShellWindow*> windows = |
- registry->GetShellWindowsForApp(app_id_); |
- std::set<gfx::NativeWindow> native_windows; |
- for (std::set<ShellWindow*>::const_iterator i = windows.begin(); |
- i != windows.end(); |
- ++i) { |
- native_windows.insert((*i)->GetNativeWindow()); |
- } |
- ui::FocusWindowSet(native_windows); |
-} |
- |
-bool AppShimHost::LaunchAppImpl(const std::string& profile_dir) { |
- DCHECK(CalledOnValidThread()); |
- if (profile_) { |
- // Only one app launch message per channel. |
- return false; |
- } |
- if (!extensions::Extension::IdIsValid(app_id_)) { |
- LOG(ERROR) << "Bad app ID from app shim launch message."; |
- return false; |
- } |
- Profile* profile = FetchProfileForDirectory(profile_dir); |
- if (!profile) |
- return false; |
- |
- if (!LaunchApp(profile)) |
- return false; |
- |
- profile_ = profile; |
- registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
- content::Source<Profile>(profile_)); |
- return true; |
} |
Profile* AppShimHost::FetchProfileForDirectory(const std::string& profile_dir) { |
@@ -138,50 +112,6 @@ Profile* AppShimHost::FetchProfileForDirectory(const std::string& profile_dir) { |
return profile; |
} |
-bool AppShimHost::LaunchApp(Profile* profile) { |
- extensions::ExtensionSystem* extension_system = |
- extensions::ExtensionSystem::Get(profile); |
- ExtensionServiceInterface* extension_service = |
- extension_system->extension_service(); |
- const extensions::Extension* extension = |
- extension_service->GetExtensionById( |
- app_id_, false); |
- if (!extension) { |
- LOG(ERROR) << "Attempted to launch nonexistent app with id '" |
- << app_id_ << "'."; |
- 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. |
- chrome::AppLaunchParams params(profile, |
- extension, |
- extension_misc::LAUNCH_NONE, |
- NEW_WINDOW); |
- chrome::OpenApplication(params); |
- return true; |
-} |
- |
-void AppShimHost::Observe(int type, |
- const content::NotificationSource& source, |
- const content::NotificationDetails& details) { |
- DCHECK(CalledOnValidThread()); |
- DCHECK(content::Source<Profile>(source).ptr() == profile_); |
- switch (type) { |
- case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { |
- extensions::ExtensionHost* extension_host = |
- content::Details<extensions::ExtensionHost>(details).ptr(); |
- if (app_id_ == extension_host->extension_id()) |
- Close(); |
- break; |
- } |
- default: |
- NOTREACHED() << "Unexpected notification sent."; |
- break; |
- } |
-} |
- |
void AppShimHost::OnAppClosed() { |
Close(); |
} |