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> |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 #include <iterator> | 13 #include <iterator> |
14 #include <limits> | 14 #include <limits> |
15 #include <memory> | 15 #include <memory> |
16 #include <sstream> | 16 #include <sstream> |
17 | 17 |
18 #include "chrome/install_static/install_details.h" | 18 #include "chrome/install_static/install_details.h" |
19 #include "chrome/install_static/install_modes.h" | 19 #include "chrome/install_static/install_modes.h" |
20 #include "chrome/install_static/policy_path_parser.h" | 20 #include "chrome/install_static/policy_path_parser.h" |
21 #include "chrome/install_static/user_data_dir.h" | 21 #include "chrome/install_static/user_data_dir.h" |
22 #include "chrome_elf/nt_registry/nt_registry.h" | 22 #include "chrome_elf/nt_registry/nt_registry.h" |
23 #include "components/version_info/channel.h" | 23 #include "components/version_info/channel.h" |
24 | 24 |
25 namespace install_static { | 25 namespace install_static { |
26 | 26 |
| 27 enum class ProcessType { |
| 28 UNINITIALIZED, |
| 29 OTHER_PROCESS, |
| 30 BROWSER_PROCESS, |
| 31 CLOUD_PRINT_SERVICE_PROCESS, |
| 32 #if !defined(DISABLE_NACL) |
| 33 NACL_BROKER_PROCESS, |
| 34 NACL_LOADER_PROCESS, |
| 35 #endif |
| 36 }; |
| 37 |
| 38 // Caches the |ProcessType| of the current process. |
27 ProcessType g_process_type = ProcessType::UNINITIALIZED; | 39 ProcessType g_process_type = ProcessType::UNINITIALIZED; |
28 | 40 |
29 const wchar_t kRegValueChromeStatsSample[] = L"UsageStatsInSample"; | 41 const wchar_t kRegValueChromeStatsSample[] = L"UsageStatsInSample"; |
30 | 42 |
31 // TODO(ananta) | 43 // TODO(ananta) |
32 // http://crbug.com/604923 | 44 // http://crbug.com/604923 |
33 // The constants defined in this file are also defined in chrome/installer and | 45 // The constants defined in this file are also defined in chrome/installer and |
34 // other places. we need to unify them. | 46 // other places. we need to unify them. |
35 const wchar_t kHeadless[] = L"CHROME_HEADLESS"; | 47 const wchar_t kHeadless[] = L"CHROME_HEADLESS"; |
36 const wchar_t kShowRestart[] = L"CHROME_CRASHED"; | 48 const wchar_t kShowRestart[] = L"CHROME_CRASHED"; |
(...skipping 20 matching lines...) Expand all Loading... |
57 | 69 |
58 // TODO(ananta) | 70 // TODO(ananta) |
59 // http://crbug.com/604923 | 71 // http://crbug.com/604923 |
60 // These constants are defined in the chrome/installer directory as well. We | 72 // These constants are defined in the chrome/installer directory as well. We |
61 // need to unify them. | 73 // need to unify them. |
62 constexpr wchar_t kRegValueAp[] = L"ap"; | 74 constexpr wchar_t kRegValueAp[] = L"ap"; |
63 constexpr wchar_t kRegValueName[] = L"name"; | 75 constexpr wchar_t kRegValueName[] = L"name"; |
64 constexpr wchar_t kRegValueUsageStats[] = L"usagestats"; | 76 constexpr wchar_t kRegValueUsageStats[] = L"usagestats"; |
65 constexpr wchar_t kMetricsReportingEnabled[] = L"MetricsReportingEnabled"; | 77 constexpr wchar_t kMetricsReportingEnabled[] = L"MetricsReportingEnabled"; |
66 | 78 |
| 79 constexpr wchar_t kCloudPrintServiceProcess[] = L"cloud-print-service"; |
| 80 #if !defined(DISABLE_NACL) |
| 81 constexpr wchar_t kNaClBrokerProcess[] = L"nacl-broker"; |
| 82 constexpr wchar_t kNaClLoaderProcess[] = L"nacl-loader"; |
| 83 #endif |
| 84 |
67 void Trace(const wchar_t* format_string, ...) { | 85 void Trace(const wchar_t* format_string, ...) { |
68 static const int kMaxLogBufferSize = 1024; | 86 static const int kMaxLogBufferSize = 1024; |
69 static wchar_t buffer[kMaxLogBufferSize] = {}; | 87 static wchar_t buffer[kMaxLogBufferSize] = {}; |
70 | 88 |
71 va_list args = {}; | 89 va_list args = {}; |
72 | 90 |
73 va_start(args, format_string); | 91 va_start(args, format_string); |
74 vswprintf(buffer, kMaxLogBufferSize, format_string, args); | 92 vswprintf(buffer, kMaxLogBufferSize, format_string, args); |
75 OutputDebugStringW(buffer); | 93 OutputDebugStringW(buffer); |
76 va_end(args); | 94 va_end(args); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 } | 299 } |
282 if (MatchPattern(value, kChromeChannelBetaPattern) || | 300 if (MatchPattern(value, kChromeChannelBetaPattern) || |
283 MatchPattern(value, kChromeChannelBetaX64Pattern)) { | 301 MatchPattern(value, kChromeChannelBetaX64Pattern)) { |
284 return kChromeChannelBeta; | 302 return kChromeChannelBeta; |
285 } | 303 } |
286 // Else report values with garbage as stable since they will match the stable | 304 // Else report values with garbage as stable since they will match the stable |
287 // rules in the update configs. | 305 // rules in the update configs. |
288 return std::wstring(); | 306 return std::wstring(); |
289 } | 307 } |
290 | 308 |
| 309 // Converts a process type specified as a string to the ProcessType enum. |
| 310 ProcessType GetProcessType(const std::wstring& process_type) { |
| 311 if (process_type.empty()) |
| 312 return ProcessType::BROWSER_PROCESS; |
| 313 if (process_type == kCloudPrintServiceProcess) |
| 314 return ProcessType::CLOUD_PRINT_SERVICE_PROCESS; |
| 315 #if !defined(DISABLE_NACL) |
| 316 if (process_type == kNaClBrokerProcess) |
| 317 return ProcessType::NACL_BROKER_PROCESS; |
| 318 if (process_type == kNaClLoaderProcess) |
| 319 return ProcessType::NACL_LOADER_PROCESS; |
| 320 #endif |
| 321 return ProcessType::OTHER_PROCESS; |
| 322 } |
| 323 |
| 324 // Returns whether |process_type| needs the profile directory. |
| 325 bool ProcessNeedsProfileDir(ProcessType process_type) { |
| 326 // On Windows we don't want subprocesses other than the browser process and |
| 327 // service processes to be able to use the profile directory because if it |
| 328 // lies on a network share the sandbox will prevent us from accessing it. |
| 329 switch (process_type) { |
| 330 case ProcessType::BROWSER_PROCESS: |
| 331 case ProcessType::CLOUD_PRINT_SERVICE_PROCESS: |
| 332 #if !defined(DISABLE_NACL) |
| 333 case ProcessType::NACL_BROKER_PROCESS: |
| 334 case ProcessType::NACL_LOADER_PROCESS: |
| 335 #endif |
| 336 return true; |
| 337 case ProcessType::OTHER_PROCESS: |
| 338 return false; |
| 339 case ProcessType::UNINITIALIZED: |
| 340 assert(false); |
| 341 return false; |
| 342 } |
| 343 assert(false); |
| 344 return false; |
| 345 } |
| 346 |
291 } // namespace | 347 } // namespace |
292 | 348 |
293 bool IsSystemInstall() { | 349 bool IsSystemInstall() { |
294 return InstallDetails::Get().system_level(); | 350 return InstallDetails::Get().system_level(); |
295 } | 351 } |
296 | 352 |
297 std::wstring GetChromeInstallSubDirectory() { | 353 std::wstring GetChromeInstallSubDirectory() { |
298 std::wstring result; | 354 std::wstring result; |
299 AppendChromeInstallSubDirectory(InstallDetails::Get().mode(), | 355 AppendChromeInstallSubDirectory(InstallDetails::Get().mode(), |
300 true /* include_suffix */, &result); | 356 true /* include_suffix */, &result); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 kMetricsReportingEnabled, &value)) { | 503 kMetricsReportingEnabled, &value)) { |
448 *crash_reporting_enabled = (value != 0); | 504 *crash_reporting_enabled = (value != 0); |
449 return true; | 505 return true; |
450 } | 506 } |
451 | 507 |
452 return false; | 508 return false; |
453 } | 509 } |
454 | 510 |
455 void InitializeProcessType() { | 511 void InitializeProcessType() { |
456 assert(g_process_type == ProcessType::UNINITIALIZED); | 512 assert(g_process_type == ProcessType::UNINITIALIZED); |
457 typedef bool (*IsSandboxedProcessFunc)(); | 513 std::wstring process_type = |
458 IsSandboxedProcessFunc is_sandboxed_process_func = | 514 GetSwitchValueFromCommandLine(::GetCommandLine(), kProcessType); |
459 reinterpret_cast<IsSandboxedProcessFunc>( | 515 g_process_type = GetProcessType(process_type); |
460 ::GetProcAddress(::GetModuleHandle(nullptr), "IsSandboxedProcess")); | 516 } |
461 if (is_sandboxed_process_func && is_sandboxed_process_func()) { | |
462 g_process_type = ProcessType::NON_BROWSER_PROCESS; | |
463 return; | |
464 } | |
465 | 517 |
466 // TODO(robertshield): Drop the command line check when we drop support for | 518 bool IsProcessTypeInitialized() { |
467 // enabling chrome_elf in unsandboxed processes. | 519 return g_process_type != ProcessType::UNINITIALIZED; |
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 } | 520 } |
476 | 521 |
477 bool IsNonBrowserProcess() { | 522 bool IsNonBrowserProcess() { |
478 assert(g_process_type != ProcessType::UNINITIALIZED); | 523 assert(g_process_type != ProcessType::UNINITIALIZED); |
479 return g_process_type == ProcessType::NON_BROWSER_PROCESS; | 524 return g_process_type != ProcessType::BROWSER_PROCESS; |
| 525 } |
| 526 |
| 527 bool ProcessNeedsProfileDir(const std::string& process_type) { |
| 528 return ProcessNeedsProfileDir(GetProcessType(UTF8ToUTF16(process_type))); |
480 } | 529 } |
481 | 530 |
482 std::wstring GetCrashDumpLocation() { | 531 std::wstring GetCrashDumpLocation() { |
483 // In order to be able to start crash handling very early and in chrome_elf, | 532 // 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 | 533 // we cannot rely on chrome's PathService entries (for DIR_CRASH_DUMPS) being |
485 // available on Windows. See https://crbug.com/564398. | 534 // available on Windows. See https://crbug.com/564398. |
486 std::wstring user_data_dir; | 535 std::wstring user_data_dir; |
487 bool ret = GetUserDataDirectory(&user_data_dir, nullptr); | 536 bool ret = GetUserDataDirectory(&user_data_dir, nullptr); |
488 assert(ret); | 537 assert(ret); |
489 IgnoreUnused(ret); | 538 IgnoreUnused(ret); |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 case ChannelStrategy::ADDITIONAL_PARAMETERS: | 887 case ChannelStrategy::ADDITIONAL_PARAMETERS: |
839 return ChannelFromAdditionalParameters(mode, ap_value); | 888 return ChannelFromAdditionalParameters(mode, ap_value); |
840 case ChannelStrategy::FIXED: | 889 case ChannelStrategy::FIXED: |
841 return mode.default_channel_name; | 890 return mode.default_channel_name; |
842 } | 891 } |
843 | 892 |
844 return std::wstring(); | 893 return std::wstring(); |
845 } | 894 } |
846 | 895 |
847 } // namespace install_static | 896 } // namespace install_static |
OLD | NEW |