OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/common/child_process_host.h" | 5 #include "chrome/common/child_process_host.h" |
6 | 6 |
7 #include "base/command_line.h" | |
8 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
9 #include "base/file_path.h" | |
10 #include "base/logging.h" | 8 #include "base/logging.h" |
11 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
12 #include "base/path_service.h" | |
13 #include "base/process_util.h" | 10 #include "base/process_util.h" |
14 #include "base/singleton.h" | 11 #include "base/singleton.h" |
15 #include "base/waitable_event.h" | 12 #include "base/waitable_event.h" |
16 #include "chrome/browser/chrome_thread.h" | 13 #include "chrome/browser/chrome_thread.h" |
17 #include "chrome/common/chrome_switches.h" | |
18 #include "chrome/common/notification_service.h" | 14 #include "chrome/common/notification_service.h" |
19 #include "chrome/common/notification_type.h" | 15 #include "chrome/common/notification_type.h" |
20 #include "chrome/common/plugin_messages.h" | 16 #include "chrome/common/plugin_messages.h" |
21 #include "chrome/common/process_watcher.h" | 17 #include "chrome/common/process_watcher.h" |
22 #include "chrome/common/result_codes.h" | 18 #include "chrome/common/result_codes.h" |
23 #include "ipc/ipc_logging.h" | 19 #include "ipc/ipc_logging.h" |
24 | 20 |
25 | 21 |
26 namespace { | 22 namespace { |
27 typedef std::list<ChildProcessHost*> ChildProcessList; | 23 typedef std::list<ChildProcessHost*> ChildProcessList; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 58 |
63 ChildProcessHost::~ChildProcessHost() { | 59 ChildProcessHost::~ChildProcessHost() { |
64 Singleton<ChildProcessList>::get()->remove(this); | 60 Singleton<ChildProcessList>::get()->remove(this); |
65 | 61 |
66 resource_dispatcher_host_->CancelRequestsForProcess(GetProcessId()); | 62 resource_dispatcher_host_->CancelRequestsForProcess(GetProcessId()); |
67 | 63 |
68 if (handle()) | 64 if (handle()) |
69 ProcessWatcher::EnsureProcessTerminated(handle()); | 65 ProcessWatcher::EnsureProcessTerminated(handle()); |
70 } | 66 } |
71 | 67 |
72 // static | |
73 std::wstring ChildProcessHost::GetChildPath() { | |
74 std::wstring child_path = CommandLine::ForCurrentProcess()->GetSwitchValue( | |
75 switches::kBrowserSubprocessPath); | |
76 if (!child_path.empty()) | |
77 return child_path; | |
78 | |
79 #if !defined(OS_MACOSX) | |
80 // On most platforms, the child executable is the same as the current | |
81 // executable. | |
82 PathService::Get(base::FILE_EXE, &child_path); | |
83 return child_path; | |
84 #else | |
85 // On the Mac, the child executable lives at a predefined location within | |
86 // the current app bundle. | |
87 | |
88 FilePath path; | |
89 if (!PathService::Get(base::FILE_EXE, &path)) | |
90 return child_path; | |
91 | |
92 // Figure out the current executable name. In a browser, this will be | |
93 // "Chromium" or "Google Chrome". The child name will be the browser | |
94 // executable name with " Helper" appended. The child app bundle name will | |
95 // be that name with ".app" appended. | |
96 FilePath::StringType child_exe_name = path.BaseName().value(); | |
97 const FilePath::StringType child_suffix = FILE_PATH_LITERAL(" Helper"); | |
98 | |
99 if (child_exe_name.size() > child_suffix.size()) { | |
100 size_t test_suffix_pos = child_exe_name.size() - child_suffix.size(); | |
101 const FilePath::CharType* test_suffix = | |
102 child_exe_name.c_str() + test_suffix_pos; | |
103 if (strcmp(test_suffix, child_suffix.c_str()) == 0) { | |
104 // FILE_EXE already ends with the child suffix and therefore already | |
105 // refers to the child process path. Just return it. | |
106 return path.ToWStringHack(); | |
107 } | |
108 } | |
109 | |
110 child_exe_name.append(child_suffix); | |
111 FilePath::StringType child_app_name = child_exe_name; | |
112 child_app_name.append(FILE_PATH_LITERAL(".app")); | |
113 // The renderer app bundle lives in the browser app bundle's Resources | |
114 // directory. Take off the executable name. | |
115 path = path.DirName(); | |
116 | |
117 // Take off the MacOS component, after verifying that's what's there. | |
118 FilePath::StringType macos = path.BaseName().value(); | |
119 DCHECK_EQ(macos, FILE_PATH_LITERAL("MacOS")); | |
120 path = path.DirName(); | |
121 | |
122 // Append the components to get to the sub-app bundle's executable. | |
123 path = path.Append(FILE_PATH_LITERAL("Resources")); | |
124 path = path.Append(child_app_name); | |
125 path = path.Append(FILE_PATH_LITERAL("Contents")); | |
126 path = path.Append(FILE_PATH_LITERAL("MacOS")); | |
127 path = path.Append(child_exe_name); | |
128 | |
129 return path.ToWStringHack(); | |
130 #endif // OS_MACOSX | |
131 } | |
132 | |
133 bool ChildProcessHost::CreateChannel() { | 68 bool ChildProcessHost::CreateChannel() { |
134 channel_id_ = GenerateRandomChannelID(this); | 69 channel_id_ = GenerateRandomChannelID(this); |
135 channel_.reset(new IPC::Channel( | 70 channel_.reset(new IPC::Channel( |
136 channel_id_, IPC::Channel::MODE_SERVER, &listener_)); | 71 channel_id_, IPC::Channel::MODE_SERVER, &listener_)); |
137 if (!channel_->Connect()) | 72 if (!channel_->Connect()) |
138 return false; | 73 return false; |
139 | 74 |
140 opening_channel_ = true; | 75 opening_channel_ = true; |
141 | 76 |
142 return true; | 77 return true; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 205 |
271 return *iterator_; | 206 return *iterator_; |
272 } while (true); | 207 } while (true); |
273 | 208 |
274 return NULL; | 209 return NULL; |
275 } | 210 } |
276 | 211 |
277 bool ChildProcessHost::Iterator::Done() { | 212 bool ChildProcessHost::Iterator::Done() { |
278 return iterator_ == Singleton<ChildProcessList>::get()->end(); | 213 return iterator_ == Singleton<ChildProcessList>::get()->end(); |
279 } | 214 } |
OLD | NEW |