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 7ae2dd69b0ba373a9b54cc50eb0085808cc275e6..b5efc9054a800909d4da775ca12b1e3c1710aa1d 100644 |
--- a/apps/app_shim/app_shim_host_mac.cc |
+++ b/apps/app_shim/app_shim_host_mac.cc |
@@ -15,7 +15,10 @@ |
#include "ipc/ipc_channel_proxy.h" |
AppShimHost::AppShimHost() |
- : channel_(NULL), profile_(NULL) { |
+ : channel_(NULL), |
+ profile_(NULL), |
+ profile_loader_(g_browser_process->profile_manager()), |
+ weak_factory_(this) { |
} |
AppShimHost::~AppShimHost() { |
@@ -74,16 +77,9 @@ void AppShimHost::OnLaunchApp(base::FilePath profile_dir, |
return; |
} |
- if (!(profile_ = FetchProfileForDirectory(profile_dir))) { |
- Send(new AppShimMsg_LaunchApp_Done(false)); |
- return; |
- } |
- |
- app_id_ = app_id; |
- |
- apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); |
- bool success = handler && handler->OnShimLaunch(this, launch_type); |
- Send(new AppShimMsg_LaunchApp_Done(success)); |
+ LoadProfile(profile_dir, |
+ base::Bind(&AppShimHost::LaunchAppWithProfile, |
+ weak_factory_.GetWeakPtr(), app_id, launch_type)); |
} |
void AppShimHost::OnFocus() { |
@@ -100,25 +96,27 @@ void AppShimHost::OnQuit() { |
handler->OnShimQuit(this); |
} |
-Profile* AppShimHost::FetchProfileForDirectory( |
- const base::FilePath& profile_dir) { |
- ProfileManager* profileManager = g_browser_process->profile_manager(); |
- // Check for the profile name in the profile info cache to ensure that we |
- // never access any directory that isn't a known profile. |
- base::FilePath path = profileManager->user_data_dir().Append(profile_dir); |
- ProfileInfoCache& cache = profileManager->GetProfileInfoCache(); |
- if (cache.GetIndexOfProfileWithPath(path) == std::string::npos) { |
- LOG(ERROR) << "Requested directory is not a known profile '" |
- << profile_dir.value() << "'."; |
- return NULL; |
- } |
- Profile* profile = profileManager->GetProfile(path); |
+void AppShimHost::LoadProfile(const base::FilePath& profile_dir, |
+ base::Callback<void(Profile*)> callback) { |
+ profile_loader_.LoadProfileInvalidatingOtherLoads( |
+ g_browser_process->profile_manager()->user_data_dir().Append(profile_dir), |
+ callback); |
+} |
+ |
+void AppShimHost::LaunchAppWithProfile(const std::string& app_id, |
+ apps::AppShimLaunchType launch_type, |
+ Profile* profile) { |
if (!profile) { |
tapted
2013/06/11 05:31:44
I don't think there's a way for a NULL pointer to
jackhou1
2013/06/12 09:41:32
LoadProfile now runs this callback with NULL if th
|
- LOG(ERROR) << "Couldn't get profile for directory '" |
- << profile_dir.value() << "'."; |
- return NULL; |
+ Send(new AppShimMsg_LaunchApp_Done(false)); |
+ return; |
} |
- return profile; |
+ |
+ profile_ = profile; |
+ app_id_ = app_id; |
+ |
+ apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); |
+ bool success = handler && handler->OnShimLaunch(this, launch_type); |
+ Send(new AppShimMsg_LaunchApp_Done(success)); |
} |
void AppShimHost::OnAppClosed() { |