Chromium Code Reviews| Index: apps/app_shim/app_shim_host_manager_mac.mm |
| diff --git a/apps/app_shim/app_shim_host_manager_mac.mm b/apps/app_shim/app_shim_host_manager_mac.mm |
| index eeaa114adea0e03b5921483ca98379a4ffeee43b..5d4e8072fe6e475f84209842c77c90a5968cc04b 100644 |
| --- a/apps/app_shim/app_shim_host_manager_mac.mm |
| +++ b/apps/app_shim/app_shim_host_manager_mac.mm |
| @@ -8,6 +8,7 @@ |
| #include "apps/app_shim/app_shim_host_mac.h" |
| #include "base/bind.h" |
| #include "base/command_line.h" |
| +#include "base/file_util.h" |
| #include "base/files/file_path.h" |
| #include "base/logging.h" |
| #include "base/path_service.h" |
| @@ -15,7 +16,6 @@ |
| #include "chrome/common/chrome_paths.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/mac/app_mode_common.h" |
| -#include "ipc/unix_domain_socket_util.h" |
| using content::BrowserThread; |
| @@ -26,9 +26,12 @@ void CreateAppShimHost(const IPC::ChannelHandle& handle) { |
| (new AppShimHost)->ServeChannel(handle); |
| } |
| -} // namespace |
| +void DeleteFile(base::FilePath path) { |
| + if (!path.empty()) |
| + base::DeleteFile(path, true); |
|
palmer
2013/12/10 20:04:23
Might this follow symlinks?
jackhou1
2014/01/06 05:29:52
The comments in file_util.h says this does not fol
|
| +} |
| -const base::FilePath* AppShimHostManager::g_override_user_data_dir_ = NULL; |
| +} // namespace |
| AppShimHostManager::AppShimHostManager() {} |
| @@ -42,27 +45,27 @@ void AppShimHostManager::Init() { |
| AppShimHostManager::~AppShimHostManager() { |
| apps::AppShimHandler::SetDefaultHandler(NULL); |
| + factory_.reset(); |
| + BrowserThread::PostTask( |
| + BrowserThread::FILE, FROM_HERE, |
| + base::Bind(&DeleteFile, directory_in_tmp_)); |
| } |
| void AppShimHostManager::InitOnFileThread() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| base::FilePath user_data_dir; |
| - if (g_override_user_data_dir_) { |
| - user_data_dir = *g_override_user_data_dir_; |
| - } else if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) { |
| - LOG(ERROR) << "Couldn't get user data directory while creating App Shim " |
| - << "Host manager."; |
| + if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) |
| return; |
| - } |
| - base::FilePath socket_path = |
| - user_data_dir.Append(app_mode::kAppShimSocketName); |
| - // This mirrors a check in unix_domain_socket_util.cc which will guarantee |
| - // failure and spam log files on bots because they have deeply nested paths to |
| - // |user_data_dir| when swarming. See http://crbug.com/240554. Shim tests that |
| - // run on the bots must override the path using AppShimHostManagerTestApi. |
| - if (socket_path.value().length() >= IPC::kMaxSocketNameLength && |
| - CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
| + // The socket path must be shorter than 128 chars (IPC::kMaxSocketNameLength). |
| + // To accommodate this, we use a short path in /tmp/ that is generated from a |
| + // hash of the user data dir. |
| + base::FilePath socket_path = app_mode::GetShortSocketPath(user_data_dir); |
| + CHECK(!socket_path.empty()); |
| + directory_in_tmp_ = socket_path.DirName(); |
| + base::CreateDirectory(directory_in_tmp_); |
| + if (!base::PathIsWritable(directory_in_tmp_)) { |
| + directory_in_tmp_.clear(); |
| return; |
| } |