OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "apps/app_shim/extension_app_shim_handler_mac.h" | 5 #include "apps/app_shim/extension_app_shim_handler_mac.h" |
6 | 6 |
7 #include "apps/app_lifetime_monitor_factory.h" | 7 #include "apps/app_lifetime_monitor_factory.h" |
8 #include "apps/app_shim/app_shim_messages.h" | 8 #include "apps/app_shim/app_shim_messages.h" |
9 #include "apps/shell_window.h" | 9 #include "apps/shell_window.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 base::FilePath full_path = profile_manager->user_data_dir().Append(path); | 55 base::FilePath full_path = profile_manager->user_data_dir().Append(path); |
56 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 56 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
57 return cache.GetIndexOfProfileWithPath(full_path) != std::string::npos; | 57 return cache.GetIndexOfProfileWithPath(full_path) != std::string::npos; |
58 } | 58 } |
59 | 59 |
60 Profile* ExtensionAppShimHandler::Delegate::ProfileForPath( | 60 Profile* ExtensionAppShimHandler::Delegate::ProfileForPath( |
61 const base::FilePath& path) { | 61 const base::FilePath& path) { |
62 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 62 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
63 base::FilePath full_path = profile_manager->user_data_dir().Append(path); | 63 base::FilePath full_path = profile_manager->user_data_dir().Append(path); |
64 Profile* profile = profile_manager->GetProfileByPath(full_path); | 64 Profile* profile = profile_manager->GetProfileByPath(full_path); |
65 if (!profile) | |
66 return NULL; | |
67 | 65 |
68 // Use IsValidProfile to check if the profile has been created. | 66 // Use IsValidProfile to check if the profile has been created. |
69 return profile_manager->IsValidProfile(profile) ? profile : NULL; | 67 return profile && profile_manager->IsValidProfile(profile) ? profile : NULL; |
70 } | 68 } |
71 | 69 |
72 void ExtensionAppShimHandler::Delegate::LoadProfileAsync( | 70 void ExtensionAppShimHandler::Delegate::LoadProfileAsync( |
73 const base::FilePath& path, | 71 const base::FilePath& path, |
74 base::Callback<void(Profile*)> callback) { | 72 base::Callback<void(Profile*)> callback) { |
75 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 73 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
76 base::FilePath full_path = profile_manager->user_data_dir().Append(path); | 74 base::FilePath full_path = profile_manager->user_data_dir().Append(path); |
77 profile_manager->CreateProfileAsync( | 75 profile_manager->CreateProfileAsync( |
78 full_path, | 76 full_path, |
79 base::Bind(&ProfileLoadedCallback, callback), | 77 base::Bind(&ProfileLoadedCallback, callback), |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 201 |
204 // TODO(jeremya): Handle the case that launching the app fails. Probably we | 202 // TODO(jeremya): Handle the case that launching the app fails. Probably we |
205 // need to watch for 'app successfully launched' or at least 'background page | 203 // need to watch for 'app successfully launched' or at least 'background page |
206 // exists/was created' and time out with failure if we don't see that sign of | 204 // exists/was created' and time out with failure if we don't see that sign of |
207 // life within a certain window. | 205 // life within a certain window. |
208 if (launch_type == APP_SHIM_LAUNCH_NORMAL) | 206 if (launch_type == APP_SHIM_LAUNCH_NORMAL) |
209 delegate_->LaunchApp(profile, extension); | 207 delegate_->LaunchApp(profile, extension); |
210 } | 208 } |
211 | 209 |
212 void ExtensionAppShimHandler::OnShimClose(Host* host) { | 210 void ExtensionAppShimHandler::OnShimClose(Host* host) { |
213 DCHECK(delegate_->ProfileExistsForPath(host->GetProfilePath())); | 211 // This might be called when shutting down. Don't try to look up the profile |
214 Profile* profile = delegate_->ProfileForPath(host->GetProfilePath()); | 212 // since profile_manager might not be around. |
215 | 213 for (HostMap::iterator it = hosts_.begin(); it != hosts_.end(); ) { |
216 HostMap::iterator it = hosts_.find(make_pair(profile, host->GetAppId())); | 214 HostMap::iterator current = it++; |
217 // Any hosts other than the main host will still call OnShimClose, so ignore | 215 if (current->second == host) |
218 // them. | 216 hosts_.erase(current); |
219 if (it != hosts_.end() && it->second == host) | 217 } |
220 hosts_.erase(it); | |
221 } | 218 } |
222 | 219 |
223 void ExtensionAppShimHandler::OnShimFocus(Host* host, | 220 void ExtensionAppShimHandler::OnShimFocus(Host* host, |
224 AppShimFocusType focus_type) { | 221 AppShimFocusType focus_type) { |
225 DCHECK(delegate_->ProfileExistsForPath(host->GetProfilePath())); | 222 DCHECK(delegate_->ProfileExistsForPath(host->GetProfilePath())); |
226 Profile* profile = delegate_->ProfileForPath(host->GetProfilePath()); | 223 Profile* profile = delegate_->ProfileForPath(host->GetProfilePath()); |
227 | 224 |
228 const ShellWindowList windows = | 225 const ShellWindowList windows = |
229 delegate_->GetWindows(profile, host->GetAppId()); | 226 delegate_->GetWindows(profile, host->GetAppId()); |
230 std::set<gfx::NativeWindow> native_windows; | 227 std::set<gfx::NativeWindow> native_windows; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 | 353 |
357 void ExtensionAppShimHandler::OnAppDeactivated(Profile* profile, | 354 void ExtensionAppShimHandler::OnAppDeactivated(Profile* profile, |
358 const std::string& app_id) {} | 355 const std::string& app_id) {} |
359 | 356 |
360 void ExtensionAppShimHandler::OnAppStop(Profile* profile, | 357 void ExtensionAppShimHandler::OnAppStop(Profile* profile, |
361 const std::string& app_id) {} | 358 const std::string& app_id) {} |
362 | 359 |
363 void ExtensionAppShimHandler::OnChromeTerminating() {} | 360 void ExtensionAppShimHandler::OnChromeTerminating() {} |
364 | 361 |
365 } // namespace apps | 362 } // namespace apps |
OLD | NEW |