Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/service_process_util.h" | |
| 6 | |
| 5 #include <algorithm> | 7 #include <algorithm> |
| 6 | 8 |
| 7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 9 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 10 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 11 #include "base/sha1.h" | 13 #include "base/sha1.h" |
| 12 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 13 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/version.h" | 18 #include "base/version.h" |
| 17 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
| 18 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/chrome_version_info.h" | 22 #include "chrome/common/chrome_version_info.h" |
| 21 #include "chrome/common/service_process_util.h" | 23 #include "components/cloud_devices/common/cloud_devices_switches.h" |
| 22 #include "content/public/common/content_paths.h" | 24 #include "content/public/common/content_paths.h" |
| 25 #include "google_apis/gaia/gaia_switches.h" | |
| 26 #include "ui/base/ui_base_switches.h" | |
| 23 | 27 |
| 24 #if !defined(OS_MACOSX) | 28 #if !defined(OS_MACOSX) |
| 25 | 29 |
| 26 namespace { | 30 namespace { |
| 27 | 31 |
| 28 // This should be more than enough to hold a version string assuming each part | 32 // This should be more than enough to hold a version string assuming each part |
| 29 // of the version string is an int64. | 33 // of the version string is an int64. |
| 30 const uint32 kMaxVersionStringLength = 256; | 34 const uint32 kMaxVersionStringLength = 256; |
| 31 | 35 |
| 32 // The structure that gets written to shared memory. | 36 // The structure that gets written to shared memory. |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 *version = service_data->service_process_version; | 148 *version = service_data->service_process_version; |
| 145 if (pid) | 149 if (pid) |
| 146 *pid = service_data->service_process_pid; | 150 *pid = service_data->service_process_pid; |
| 147 return true; | 151 return true; |
| 148 } | 152 } |
| 149 return false; | 153 return false; |
| 150 } | 154 } |
| 151 | 155 |
| 152 #endif // !OS_MACOSX | 156 #endif // !OS_MACOSX |
| 153 | 157 |
| 158 scoped_ptr<base::CommandLine> CreateServiceProcessCommandLine() { | |
| 159 base::FilePath exe_path; | |
| 160 PathService::Get(content::CHILD_PROCESS_EXE, &exe_path); | |
| 161 DCHECK(!exe_path.empty()) << "Unable to get service process binary name."; | |
| 162 scoped_ptr<base::CommandLine> command_line(new CommandLine(exe_path)); | |
|
Lei Zhang
2014/06/20 02:50:29
new base::CommandLine
Vitaly Buka (NO REVIEWS)
2014/06/20 04:38:43
Done.
| |
| 163 command_line->AppendSwitchASCII(switches::kProcessType, | |
| 164 switches::kServiceProcess); | |
| 165 static const char* const kSwitches[] = { | |
|
Lei Zhang
2014/06/20 02:50:29
kSwitchesToCopy?
Vitaly Buka (NO REVIEWS)
2014/06/20 04:38:43
Done.
| |
| 166 switches::kCloudPrintSetupProxy, | |
| 167 switches::kCloudPrintURL, | |
| 168 switches::kCloudPrintXmppEndpoint, | |
| 169 #if defined(OS_WIN) | |
| 170 switches::kEnableCloudPrintXps, | |
| 171 #endif | |
| 172 switches::kEnableLogging, | |
| 173 switches::kIgnoreUrlFetcherCertRequests, | |
| 174 switches::kLang, | |
| 175 switches::kLoggingLevel, | |
| 176 switches::kLsoUrl, | |
| 177 switches::kNoServiceAutorun, | |
| 178 switches::kUserDataDir, | |
| 179 switches::kV, | |
| 180 switches::kVModule, | |
| 181 switches::kWaitForDebugger, | |
| 182 }; | |
| 183 | |
| 184 command_line->CopySwitchesFrom(*CommandLine::ForCurrentProcess(), | |
|
Lei Zhang
2014/06/20 02:50:29
base::CommandLine
Vitaly Buka (NO REVIEWS)
2014/06/20 04:38:43
Done.
| |
| 185 kSwitches, arraysize(kSwitches)); | |
| 186 return command_line.Pass(); | |
| 187 } | |
| 188 | |
| 154 ServiceProcessState::ServiceProcessState() : state_(NULL) { | 189 ServiceProcessState::ServiceProcessState() : state_(NULL) { |
| 155 CreateAutoRunCommandLine(); | 190 autorun_command_line_ = CreateServiceProcessCommandLine(); |
| 156 CreateState(); | 191 CreateState(); |
| 157 } | 192 } |
| 158 | 193 |
| 159 ServiceProcessState::~ServiceProcessState() { | 194 ServiceProcessState::~ServiceProcessState() { |
| 160 #if !defined(OS_MACOSX) | 195 #if !defined(OS_MACOSX) |
| 161 if (shared_mem_service_data_.get()) { | 196 if (shared_mem_service_data_.get()) { |
| 162 shared_mem_service_data_->Delete(GetServiceProcessSharedMemName()); | 197 shared_mem_service_data_->Delete(GetServiceProcessSharedMemName()); |
| 163 } | 198 } |
| 164 #endif // !OS_MACOSX | 199 #endif // !OS_MACOSX |
| 165 TearDownState(); | 200 TearDownState(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 shared_data->service_process_pid = base::GetCurrentProcId(); | 275 shared_data->service_process_pid = base::GetCurrentProcId(); |
| 241 shared_mem_service_data_.reset(shared_mem_service_data.release()); | 276 shared_mem_service_data_.reset(shared_mem_service_data.release()); |
| 242 return true; | 277 return true; |
| 243 } | 278 } |
| 244 | 279 |
| 245 IPC::ChannelHandle ServiceProcessState::GetServiceProcessChannel() { | 280 IPC::ChannelHandle ServiceProcessState::GetServiceProcessChannel() { |
| 246 return ::GetServiceProcessChannel(); | 281 return ::GetServiceProcessChannel(); |
| 247 } | 282 } |
| 248 | 283 |
| 249 #endif // !OS_MACOSX | 284 #endif // !OS_MACOSX |
| 250 | |
| 251 void ServiceProcessState::CreateAutoRunCommandLine() { | |
| 252 base::FilePath exe_path; | |
| 253 PathService::Get(content::CHILD_PROCESS_EXE, &exe_path); | |
| 254 DCHECK(!exe_path.empty()) << "Unable to get service process binary name."; | |
| 255 autorun_command_line_.reset(new CommandLine(exe_path)); | |
| 256 autorun_command_line_->AppendSwitchASCII(switches::kProcessType, | |
| 257 switches::kServiceProcess); | |
| 258 | |
| 259 // The user data directory is the only other flag we currently want to | |
| 260 // possibly store. | |
| 261 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | |
| 262 base::FilePath user_data_dir = | |
| 263 browser_command_line.GetSwitchValuePath(switches::kUserDataDir); | |
| 264 if (!user_data_dir.empty()) | |
| 265 autorun_command_line_->AppendSwitchPath(switches::kUserDataDir, | |
| 266 user_data_dir); | |
| 267 } | |
| OLD | NEW |