| 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..34270ae845ef79eaa35865efa1e3c2952c913751 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,36 @@ 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;
|
| +void AppShimHost::LoadProfile(const base::FilePath& profile_dir,
|
| + base::Callback<void(Profile*)> callback) {
|
| + base::FilePath full_profile_dir =
|
| + g_browser_process->profile_manager()->user_data_dir().Append(profile_dir);
|
| +
|
| + size_t profile_index =
|
| + g_browser_process->profile_manager()->GetProfileInfoCache()
|
| + .GetIndexOfProfileWithPath(full_profile_dir);
|
| + if (profile_index == std::string::npos) {
|
| + callback.Run(NULL);
|
| + return;
|
| }
|
| - Profile* profile = profileManager->GetProfile(path);
|
| +
|
| + profile_loader_.LoadProfileInvalidatingOtherLoads(full_profile_dir, callback);
|
| +}
|
| +
|
| +void AppShimHost::LaunchAppWithProfile(const std::string& app_id,
|
| + apps::AppShimLaunchType launch_type,
|
| + Profile* profile) {
|
| if (!profile) {
|
| - 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() {
|
|
|