Chromium Code Reviews| 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/app_shim_host_manager_mac.h" | 5 #include "apps/app_shim/app_shim_host_manager_mac.h" |
| 6 | 6 |
| 7 #include "apps/app_shim/app_shim_handler_mac.h" | 7 #include "apps/app_shim/app_shim_handler_mac.h" |
| 8 #include "apps/app_shim/app_shim_host_mac.h" | 8 #include "apps/app_shim/app_shim_host_mac.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/mac/app_mode_common.h" | 17 #include "chrome/common/mac/app_mode_common.h" |
| 18 #include "ipc/unix_domain_socket_util.h" | |
| 19 | 18 |
| 20 using content::BrowserThread; | 19 using content::BrowserThread; |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 void CreateAppShimHost(const IPC::ChannelHandle& handle) { | 23 void CreateAppShimHost(const IPC::ChannelHandle& handle) { |
| 25 // AppShimHost takes ownership of itself. | 24 // AppShimHost takes ownership of itself. |
| 26 (new AppShimHost)->ServeChannel(handle); | 25 (new AppShimHost)->ServeChannel(handle); |
| 27 } | 26 } |
| 28 | 27 |
| 29 } // namespace | 28 } // namespace |
| 30 | 29 |
| 31 const base::FilePath* AppShimHostManager::g_override_user_data_dir_ = NULL; | |
| 32 | |
| 33 AppShimHostManager::AppShimHostManager() {} | 30 AppShimHostManager::AppShimHostManager() {} |
| 34 | 31 |
| 35 void AppShimHostManager::Init() { | 32 void AppShimHostManager::Init() { |
| 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 37 apps::AppShimHandler::SetDefaultHandler(&extension_app_shim_handler_); | 34 apps::AppShimHandler::SetDefaultHandler(&extension_app_shim_handler_); |
| 38 BrowserThread::PostTask( | 35 BrowserThread::PostTask( |
| 39 BrowserThread::FILE, FROM_HERE, | 36 BrowserThread::FILE, FROM_HERE, |
| 40 base::Bind(&AppShimHostManager::InitOnFileThread, this)); | 37 base::Bind(&AppShimHostManager::InitOnFileThread, this)); |
| 41 } | 38 } |
| 42 | 39 |
| 43 AppShimHostManager::~AppShimHostManager() { | 40 AppShimHostManager::~AppShimHostManager() { |
| 44 apps::AppShimHandler::SetDefaultHandler(NULL); | 41 apps::AppShimHandler::SetDefaultHandler(NULL); |
| 45 } | 42 } |
| 46 | 43 |
| 47 void AppShimHostManager::InitOnFileThread() { | 44 void AppShimHostManager::InitOnFileThread() { |
| 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 49 base::FilePath user_data_dir; | 46 base::FilePath user_data_dir; |
| 50 if (g_override_user_data_dir_) { | 47 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) { |
| 51 user_data_dir = *g_override_user_data_dir_; | |
| 52 } else if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) { | |
| 53 LOG(ERROR) << "Couldn't get user data directory while creating App Shim " | 48 LOG(ERROR) << "Couldn't get user data directory while creating App Shim " |
|
tapted
2013/11/21 11:12:05
while we are here.. let's ditch this LOG and just
jackhou1
2013/11/22 00:20:40
Done.
| |
| 54 << "Host manager."; | 49 << "Host manager."; |
| 55 return; | 50 return; |
| 56 } | 51 } |
| 57 | 52 |
| 53 // The socket cannot be created if its path is longer than 128 chars | |
| 54 // (IPC::kMaxSocketNameLength). To circumvent this, we use a short path in | |
| 55 // /tmp/ that is generated from a hash of the user data dir. | |
| 56 base::FilePath udd_plus_socket_name = | |
| 57 user_data_dir.Append(app_mode::kAppShimSocketName); | |
| 58 base::FilePath socket_path = | 58 base::FilePath socket_path = |
| 59 user_data_dir.Append(app_mode::kAppShimSocketName); | 59 app_mode::GetShortSocketPath(udd_plus_socket_name); |
|
tapted
2013/11/21 11:12:05
Ah, so this is just /tmp/TWFuIGlzIGRpc3Rpbm which
jackhou1
2013/11/22 00:20:40
Yeah, I think this is a good idea. I've changed th
| |
| 60 // This mirrors a check in unix_domain_socket_util.cc which will guarantee | |
| 61 // failure and spam log files on bots because they have deeply nested paths to | |
| 62 // |user_data_dir| when swarming. See http://crbug.com/240554. Shim tests that | |
| 63 // run on the bots must override the path using AppShimHostManagerTestApi. | |
| 64 if (socket_path.value().length() >= IPC::kMaxSocketNameLength && | |
| 65 CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { | |
| 66 return; | |
| 67 } | |
| 68 | 60 |
| 69 factory_.reset(new IPC::ChannelFactory(socket_path, this)); | 61 factory_.reset(new IPC::ChannelFactory(socket_path, this)); |
| 70 BrowserThread::PostTask( | 62 BrowserThread::PostTask( |
| 71 BrowserThread::IO, FROM_HERE, | 63 BrowserThread::IO, FROM_HERE, |
| 72 base::Bind(&AppShimHostManager::ListenOnIOThread, this)); | 64 base::Bind(&AppShimHostManager::ListenOnIOThread, this)); |
| 73 } | 65 } |
| 74 | 66 |
| 75 void AppShimHostManager::ListenOnIOThread() { | 67 void AppShimHostManager::ListenOnIOThread() { |
| 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 77 if (!factory_->Listen()) { | 69 if (!factory_->Listen()) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 88 BrowserThread::UI, FROM_HERE, | 80 BrowserThread::UI, FROM_HERE, |
| 89 base::Bind(&CreateAppShimHost, handle)); | 81 base::Bind(&CreateAppShimHost, handle)); |
| 90 } | 82 } |
| 91 | 83 |
| 92 void AppShimHostManager::OnListenError() { | 84 void AppShimHostManager::OnListenError() { |
| 93 // TODO(tapted): Set a timeout and attempt to reconstruct the channel. Until | 85 // TODO(tapted): Set a timeout and attempt to reconstruct the channel. Until |
| 94 // cases where the error could occur are better known, just reset the factory | 86 // cases where the error could occur are better known, just reset the factory |
| 95 // to allow failure to be communicated via the test API. | 87 // to allow failure to be communicated via the test API. |
| 96 factory_.reset(); | 88 factory_.reset(); |
| 97 } | 89 } |
| OLD | NEW |