Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: apps/app_shim/app_shim_host_manager_mac.mm

Issue 66043003: Put app shim IPC socket in a temporary directory. (Mac) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « apps/app_shim/app_shim_host_manager_mac.h ('k') | apps/app_shim/chrome_main_app_mode_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/file_util.h"
11 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/path_service.h" 14 #include "base/path_service.h"
14 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
15 #include "chrome/common/chrome_paths.h" 16 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/mac/app_mode_common.h" 18 #include "chrome/common/mac/app_mode_common.h"
18 #include "ipc/unix_domain_socket_util.h"
19 19
20 using content::BrowserThread; 20 using content::BrowserThread;
21 21
22 namespace { 22 namespace {
23 23
24 void CreateAppShimHost(const IPC::ChannelHandle& handle) { 24 void CreateAppShimHost(const IPC::ChannelHandle& handle) {
25 // AppShimHost takes ownership of itself. 25 // AppShimHost takes ownership of itself.
26 (new AppShimHost)->ServeChannel(handle); 26 (new AppShimHost)->ServeChannel(handle);
27 } 27 }
28 28
29 } // namespace 29 } // namespace
30 30
31 const base::FilePath* AppShimHostManager::g_override_user_data_dir_ = NULL;
32
33 AppShimHostManager::AppShimHostManager() {} 31 AppShimHostManager::AppShimHostManager() {}
34 32
35 void AppShimHostManager::Init() { 33 void AppShimHostManager::Init() {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
37 apps::AppShimHandler::SetDefaultHandler(&extension_app_shim_handler_); 35 apps::AppShimHandler::SetDefaultHandler(&extension_app_shim_handler_);
38 BrowserThread::PostTask( 36 BrowserThread::PostTask(
39 BrowserThread::FILE, FROM_HERE, 37 BrowserThread::FILE, FROM_HERE,
40 base::Bind(&AppShimHostManager::InitOnFileThread, this)); 38 base::Bind(&AppShimHostManager::InitOnFileThread, this));
41 } 39 }
42 40
43 AppShimHostManager::~AppShimHostManager() { 41 AppShimHostManager::~AppShimHostManager() {
44 apps::AppShimHandler::SetDefaultHandler(NULL); 42 apps::AppShimHandler::SetDefaultHandler(NULL);
43 // This is destroyed on the UI thread, but only during shutdown.
44 if (!directory_created_in_tmp_.empty())
45 base::DeleteFile(directory_created_in_tmp_, true);
45 } 46 }
46 47
47 void AppShimHostManager::InitOnFileThread() { 48 void AppShimHostManager::InitOnFileThread() {
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
49 base::FilePath user_data_dir; 50 base::FilePath user_data_dir;
50 if (g_override_user_data_dir_) { 51 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 "
54 << "Host manager.";
55 return; 52 return;
56 }
57 53
58 base::FilePath socket_path = 54 // The socket path must be shorter than 128 chars (IPC::kMaxSocketNameLength).
59 user_data_dir.Append(app_mode::kAppShimSocketName); 55 // To accommodate this, we use a short path in /tmp/ that is generated from a
60 // This mirrors a check in unix_domain_socket_util.cc which will guarantee 56 // hash of the user data dir.
61 // failure and spam log files on bots because they have deeply nested paths to 57 base::FilePath socket_path = app_mode::GetShortSocketPath(user_data_dir);
62 // |user_data_dir| when swarming. See http://crbug.com/240554. Shim tests that 58 if (file_util::CreateDirectory(socket_path.DirName())) {
tapted 2013/11/22 05:04:31 pretty sure this succeeds if the directory already
jackhou1 2013/11/22 05:51:03 Done.
63 // run on the bots must override the path using AppShimHostManagerTestApi. 59 directory_created_in_tmp_ = socket_path.DirName();
64 if (socket_path.value().length() >= IPC::kMaxSocketNameLength && 60 } else {
tapted 2013/11/22 05:04:31 (so I think this line can be removed)
jackhou1 2013/11/22 05:51:03 Done.
65 CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { 61 if (!base::PathIsWritable(socket_path.DirName()))
66 return; 62 return;
67 } 63 }
68 64
69 factory_.reset(new IPC::ChannelFactory(socket_path, this)); 65 factory_.reset(new IPC::ChannelFactory(socket_path, this));
70 BrowserThread::PostTask( 66 BrowserThread::PostTask(
71 BrowserThread::IO, FROM_HERE, 67 BrowserThread::IO, FROM_HERE,
72 base::Bind(&AppShimHostManager::ListenOnIOThread, this)); 68 base::Bind(&AppShimHostManager::ListenOnIOThread, this));
73 } 69 }
74 70
75 void AppShimHostManager::ListenOnIOThread() { 71 void AppShimHostManager::ListenOnIOThread() {
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
(...skipping 11 matching lines...) Expand all
88 BrowserThread::UI, FROM_HERE, 84 BrowserThread::UI, FROM_HERE,
89 base::Bind(&CreateAppShimHost, handle)); 85 base::Bind(&CreateAppShimHost, handle));
90 } 86 }
91 87
92 void AppShimHostManager::OnListenError() { 88 void AppShimHostManager::OnListenError() {
93 // TODO(tapted): Set a timeout and attempt to reconstruct the channel. Until 89 // 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 90 // cases where the error could occur are better known, just reset the factory
95 // to allow failure to be communicated via the test API. 91 // to allow failure to be communicated via the test API.
96 factory_.reset(); 92 factory_.reset();
97 } 93 }
OLDNEW
« no previous file with comments | « apps/app_shim/app_shim_host_manager_mac.h ('k') | apps/app_shim/chrome_main_app_mode_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698