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

Side by Side Diff: chrome/common/child_process_host.cc

Issue 164303: Re-commit r22981 after backout at r22992 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 months 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 | « chrome/common/child_process_host.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
7 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/file_path.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
9 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/path_service.h"
10 #include "base/process_util.h" 13 #include "base/process_util.h"
11 #include "base/singleton.h" 14 #include "base/singleton.h"
12 #include "base/waitable_event.h" 15 #include "base/waitable_event.h"
13 #include "chrome/browser/chrome_thread.h" 16 #include "chrome/browser/chrome_thread.h"
17 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/notification_service.h" 18 #include "chrome/common/notification_service.h"
15 #include "chrome/common/notification_type.h" 19 #include "chrome/common/notification_type.h"
16 #include "chrome/common/plugin_messages.h" 20 #include "chrome/common/plugin_messages.h"
17 #include "chrome/common/process_watcher.h" 21 #include "chrome/common/process_watcher.h"
18 #include "chrome/common/result_codes.h" 22 #include "chrome/common/result_codes.h"
19 #include "ipc/ipc_logging.h" 23 #include "ipc/ipc_logging.h"
20 24
21 25
22 namespace { 26 namespace {
23 typedef std::list<ChildProcessHost*> ChildProcessList; 27 typedef std::list<ChildProcessHost*> ChildProcessList;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 62
59 ChildProcessHost::~ChildProcessHost() { 63 ChildProcessHost::~ChildProcessHost() {
60 Singleton<ChildProcessList>::get()->remove(this); 64 Singleton<ChildProcessList>::get()->remove(this);
61 65
62 resource_dispatcher_host_->CancelRequestsForProcess(GetProcessId()); 66 resource_dispatcher_host_->CancelRequestsForProcess(GetProcessId());
63 67
64 if (handle()) 68 if (handle())
65 ProcessWatcher::EnsureProcessTerminated(handle()); 69 ProcessWatcher::EnsureProcessTerminated(handle());
66 } 70 }
67 71
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
68 bool ChildProcessHost::CreateChannel() { 133 bool ChildProcessHost::CreateChannel() {
69 channel_id_ = GenerateRandomChannelID(this); 134 channel_id_ = GenerateRandomChannelID(this);
70 channel_.reset(new IPC::Channel( 135 channel_.reset(new IPC::Channel(
71 channel_id_, IPC::Channel::MODE_SERVER, &listener_)); 136 channel_id_, IPC::Channel::MODE_SERVER, &listener_));
72 if (!channel_->Connect()) 137 if (!channel_->Connect())
73 return false; 138 return false;
74 139
75 opening_channel_ = true; 140 opening_channel_ = true;
76 141
77 return true; 142 return true;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 270
206 return *iterator_; 271 return *iterator_;
207 } while (true); 272 } while (true);
208 273
209 return NULL; 274 return NULL;
210 } 275 }
211 276
212 bool ChildProcessHost::Iterator::Done() { 277 bool ChildProcessHost::Iterator::Done() {
213 return iterator_ == Singleton<ChildProcessList>::get()->end(); 278 return iterator_ == Singleton<ChildProcessList>::get()->end();
214 } 279 }
OLDNEW
« no previous file with comments | « chrome/common/child_process_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698