OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/install_static/install_util.h" | 5 #include "chrome/install_static/install_util.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <assert.h> | 8 #include <assert.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 | 57 |
58 // TODO(ananta) | 58 // TODO(ananta) |
59 // http://crbug.com/604923 | 59 // http://crbug.com/604923 |
60 // These constants are defined in the chrome/installer directory as well. We | 60 // These constants are defined in the chrome/installer directory as well. We |
61 // need to unify them. | 61 // need to unify them. |
62 constexpr wchar_t kRegValueAp[] = L"ap"; | 62 constexpr wchar_t kRegValueAp[] = L"ap"; |
63 constexpr wchar_t kRegValueName[] = L"name"; | 63 constexpr wchar_t kRegValueName[] = L"name"; |
64 constexpr wchar_t kRegValueUsageStats[] = L"usagestats"; | 64 constexpr wchar_t kRegValueUsageStats[] = L"usagestats"; |
65 constexpr wchar_t kMetricsReportingEnabled[] = L"MetricsReportingEnabled"; | 65 constexpr wchar_t kMetricsReportingEnabled[] = L"MetricsReportingEnabled"; |
66 | 66 |
67 constexpr wchar_t kCloudPrintServiceProcess[] = L"cloud-print-service"; | |
68 constexpr wchar_t kNaClBrokerProcess[] = L"nacl-broker"; | |
grt (UTC plus 2)
2017/05/17 20:10:36
#if !defined(DISABLE_NACL)
manzagop (departed)
2017/05/17 21:15:56
Done.
| |
69 constexpr wchar_t kNaClLoaderProcess[] = L"nacl-loader"; | |
70 | |
67 void Trace(const wchar_t* format_string, ...) { | 71 void Trace(const wchar_t* format_string, ...) { |
68 static const int kMaxLogBufferSize = 1024; | 72 static const int kMaxLogBufferSize = 1024; |
69 static wchar_t buffer[kMaxLogBufferSize] = {}; | 73 static wchar_t buffer[kMaxLogBufferSize] = {}; |
70 | 74 |
71 va_list args = {}; | 75 va_list args = {}; |
72 | 76 |
73 va_start(args, format_string); | 77 va_start(args, format_string); |
74 vswprintf(buffer, kMaxLogBufferSize, format_string, args); | 78 vswprintf(buffer, kMaxLogBufferSize, format_string, args); |
75 OutputDebugStringW(buffer); | 79 OutputDebugStringW(buffer); |
76 va_end(args); | 80 va_end(args); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 } | 285 } |
282 if (MatchPattern(value, kChromeChannelBetaPattern) || | 286 if (MatchPattern(value, kChromeChannelBetaPattern) || |
283 MatchPattern(value, kChromeChannelBetaX64Pattern)) { | 287 MatchPattern(value, kChromeChannelBetaX64Pattern)) { |
284 return kChromeChannelBeta; | 288 return kChromeChannelBeta; |
285 } | 289 } |
286 // Else report values with garbage as stable since they will match the stable | 290 // Else report values with garbage as stable since they will match the stable |
287 // rules in the update configs. | 291 // rules in the update configs. |
288 return std::wstring(); | 292 return std::wstring(); |
289 } | 293 } |
290 | 294 |
295 // Converts a process type specified as a string to the ProcessType enum. | |
296 ProcessType GetProcessType(std::wstring process_type) { | |
grt (UTC plus 2)
2017/05/17 20:10:36
const&
manzagop (departed)
2017/05/17 21:15:56
Err... Done.
| |
297 if (process_type.empty()) { | |
grt (UTC plus 2)
2017/05/17 20:10:36
no braces and no "else":
if (foo)
return fo
manzagop (departed)
2017/05/17 21:15:56
Done.
| |
298 return ProcessType::BROWSER_PROCESS; | |
299 } else if (process_type == kCloudPrintServiceProcess) { | |
300 return ProcessType::CLOUD_PRINT_SERVICE_PROCESS; | |
301 #if !defined(DISABLE_NACL) | |
302 } else if (process_type == kNaClBrokerProcess) { | |
303 return ProcessType::NACL_BROKER_PROCESS; | |
304 } else if (process_type == kNaClLoaderProcess) { | |
305 return ProcessType::NACL_LOADER_PROCESS; | |
306 #endif | |
307 } else { | |
308 return ProcessType::OTHER_PROCESS; | |
309 } | |
310 } | |
311 | |
312 // Returns whether |process_type| needs the profile directory. | |
313 bool ProcessNeedsProfileDir(ProcessType process_type) { | |
314 // On windows we don't want subprocesses other than the browser process and | |
grt (UTC plus 2)
2017/05/17 20:10:36
nit: Windows
manzagop (departed)
2017/05/17 21:15:56
Done.
| |
315 // service processes to be able to use the profile directory because if it | |
316 // lies on a network share the sandbox will prevent us from accessing it. | |
317 | |
318 if (process_type == ProcessType::BROWSER_PROCESS || | |
grt (UTC plus 2)
2017/05/17 20:10:36
to protect against future types being added to the
manzagop (departed)
2017/05/17 21:15:56
Done. It's just clang that throws an error in that
| |
319 process_type == ProcessType::CLOUD_PRINT_SERVICE_PROCESS) { | |
320 return true; | |
321 } | |
322 #if !defined(DISABLE_NACL) | |
323 if (process_type == ProcessType::kNaClBrokerProcess || | |
324 process_type == ProcessType::kNaClLoaderProcess) { | |
325 return true; | |
326 } | |
327 #endif | |
328 return false; | |
329 } | |
330 | |
291 } // namespace | 331 } // namespace |
292 | 332 |
293 bool IsSystemInstall() { | 333 bool IsSystemInstall() { |
294 return InstallDetails::Get().system_level(); | 334 return InstallDetails::Get().system_level(); |
295 } | 335 } |
296 | 336 |
297 std::wstring GetChromeInstallSubDirectory() { | 337 std::wstring GetChromeInstallSubDirectory() { |
298 std::wstring result; | 338 std::wstring result; |
299 AppendChromeInstallSubDirectory(InstallDetails::Get().mode(), | 339 AppendChromeInstallSubDirectory(InstallDetails::Get().mode(), |
300 true /* include_suffix */, &result); | 340 true /* include_suffix */, &result); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 kMetricsReportingEnabled, &value)) { | 487 kMetricsReportingEnabled, &value)) { |
448 *crash_reporting_enabled = (value != 0); | 488 *crash_reporting_enabled = (value != 0); |
449 return true; | 489 return true; |
450 } | 490 } |
451 | 491 |
452 return false; | 492 return false; |
453 } | 493 } |
454 | 494 |
455 void InitializeProcessType() { | 495 void InitializeProcessType() { |
456 assert(g_process_type == ProcessType::UNINITIALIZED); | 496 assert(g_process_type == ProcessType::UNINITIALIZED); |
457 typedef bool (*IsSandboxedProcessFunc)(); | 497 std::wstring process_type = |
458 IsSandboxedProcessFunc is_sandboxed_process_func = | 498 GetSwitchValueFromCommandLine(::GetCommandLine(), kProcessType); |
459 reinterpret_cast<IsSandboxedProcessFunc>( | 499 g_process_type = GetProcessType(process_type); |
460 ::GetProcAddress(::GetModuleHandle(nullptr), "IsSandboxedProcess")); | |
461 if (is_sandboxed_process_func && is_sandboxed_process_func()) { | |
462 g_process_type = ProcessType::NON_BROWSER_PROCESS; | |
463 return; | |
464 } | |
465 | |
466 // TODO(robertshield): Drop the command line check when we drop support for | |
467 // enabling chrome_elf in unsandboxed processes. | |
468 const wchar_t* command_line = GetCommandLine(); | |
469 if (command_line && ::wcsstr(command_line, L"--type")) { | |
470 g_process_type = ProcessType::NON_BROWSER_PROCESS; | |
471 return; | |
472 } | |
473 | |
474 g_process_type = ProcessType::BROWSER_PROCESS; | |
475 } | 500 } |
476 | 501 |
477 bool IsNonBrowserProcess() { | 502 bool IsNonBrowserProcess() { |
478 assert(g_process_type != ProcessType::UNINITIALIZED); | 503 assert(g_process_type != ProcessType::UNINITIALIZED); |
479 return g_process_type == ProcessType::NON_BROWSER_PROCESS; | 504 return g_process_type != ProcessType::BROWSER_PROCESS; |
505 } | |
506 | |
507 bool ProcessNeedsProfileDir(const std::string& process_type) { | |
grt (UTC plus 2)
2017/05/17 20:10:36
part of me wants this function to be an export fro
manzagop (departed)
2017/05/17 21:15:56
Acknowledged.
| |
508 return ProcessNeedsProfileDir(GetProcessType(UTF8ToUTF16(process_type))); | |
480 } | 509 } |
481 | 510 |
482 std::wstring GetCrashDumpLocation() { | 511 std::wstring GetCrashDumpLocation() { |
483 // In order to be able to start crash handling very early and in chrome_elf, | 512 // In order to be able to start crash handling very early and in chrome_elf, |
484 // we cannot rely on chrome's PathService entries (for DIR_CRASH_DUMPS) being | 513 // we cannot rely on chrome's PathService entries (for DIR_CRASH_DUMPS) being |
485 // available on Windows. See https://crbug.com/564398. | 514 // available on Windows. See https://crbug.com/564398. |
486 std::wstring user_data_dir; | 515 std::wstring user_data_dir; |
487 bool ret = GetUserDataDirectory(&user_data_dir, nullptr); | 516 bool ret = GetUserDataDirectory(&user_data_dir, nullptr); |
488 assert(ret); | 517 assert(ret); |
489 IgnoreUnused(ret); | 518 IgnoreUnused(ret); |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
838 case ChannelStrategy::ADDITIONAL_PARAMETERS: | 867 case ChannelStrategy::ADDITIONAL_PARAMETERS: |
839 return ChannelFromAdditionalParameters(mode, ap_value); | 868 return ChannelFromAdditionalParameters(mode, ap_value); |
840 case ChannelStrategy::FIXED: | 869 case ChannelStrategy::FIXED: |
841 return mode.default_channel_name; | 870 return mode.default_channel_name; |
842 } | 871 } |
843 | 872 |
844 return std::wstring(); | 873 return std::wstring(); |
845 } | 874 } |
846 | 875 |
847 } // namespace install_static | 876 } // namespace install_static |
OLD | NEW |