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

Side by Side Diff: chrome/install_static/install_util.cc

Issue 2867063002: Stability instrumentation Crashpad integration (Closed)
Patch Set: merge Created 3 years, 7 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
« no previous file with comments | « chrome/install_static/install_util.h ('k') | chrome/install_static/install_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 11 matching lines...) Expand all
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 { 27 enum class ProcessType {
28 UNINITIALIZED, 28 UNINITIALIZED,
29 OTHER_PROCESS, 29 OTHER_PROCESS,
30 BROWSER_PROCESS, 30 BROWSER_PROCESS,
31 CLOUD_PRINT_SERVICE_PROCESS, 31 CLOUD_PRINT_SERVICE_PROCESS,
32 CRASHPAD_HANDLER_PROCESS,
32 #if !defined(DISABLE_NACL) 33 #if !defined(DISABLE_NACL)
33 NACL_BROKER_PROCESS, 34 NACL_BROKER_PROCESS,
34 NACL_LOADER_PROCESS, 35 NACL_LOADER_PROCESS,
35 #endif 36 #endif
36 }; 37 };
37 38
38 // Caches the |ProcessType| of the current process. 39 // Caches the |ProcessType| of the current process.
39 ProcessType g_process_type = ProcessType::UNINITIALIZED; 40 ProcessType g_process_type = ProcessType::UNINITIALIZED;
40 41
41 const wchar_t kRegValueChromeStatsSample[] = L"UsageStatsInSample"; 42 const wchar_t kRegValueChromeStatsSample[] = L"UsageStatsInSample";
(...skipping 28 matching lines...) Expand all
70 // TODO(ananta) 71 // TODO(ananta)
71 // http://crbug.com/604923 72 // http://crbug.com/604923
72 // These constants are defined in the chrome/installer directory as well. We 73 // These constants are defined in the chrome/installer directory as well. We
73 // need to unify them. 74 // need to unify them.
74 constexpr wchar_t kRegValueAp[] = L"ap"; 75 constexpr wchar_t kRegValueAp[] = L"ap";
75 constexpr wchar_t kRegValueName[] = L"name"; 76 constexpr wchar_t kRegValueName[] = L"name";
76 constexpr wchar_t kRegValueUsageStats[] = L"usagestats"; 77 constexpr wchar_t kRegValueUsageStats[] = L"usagestats";
77 constexpr wchar_t kMetricsReportingEnabled[] = L"MetricsReportingEnabled"; 78 constexpr wchar_t kMetricsReportingEnabled[] = L"MetricsReportingEnabled";
78 79
79 constexpr wchar_t kCloudPrintServiceProcess[] = L"cloud-print-service"; 80 constexpr wchar_t kCloudPrintServiceProcess[] = L"cloud-print-service";
81 constexpr wchar_t kCrashpadHandlerProcess[] = L"crashpad-handler";
80 #if !defined(DISABLE_NACL) 82 #if !defined(DISABLE_NACL)
81 constexpr wchar_t kNaClBrokerProcess[] = L"nacl-broker"; 83 constexpr wchar_t kNaClBrokerProcess[] = L"nacl-broker";
82 constexpr wchar_t kNaClLoaderProcess[] = L"nacl-loader"; 84 constexpr wchar_t kNaClLoaderProcess[] = L"nacl-loader";
83 #endif 85 #endif
84 86
85 void Trace(const wchar_t* format_string, ...) { 87 void Trace(const wchar_t* format_string, ...) {
86 static const int kMaxLogBufferSize = 1024; 88 static const int kMaxLogBufferSize = 1024;
87 static wchar_t buffer[kMaxLogBufferSize] = {}; 89 static wchar_t buffer[kMaxLogBufferSize] = {};
88 90
89 va_list args = {}; 91 va_list args = {};
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 301 }
300 if (MatchPattern(value, kChromeChannelBetaPattern) || 302 if (MatchPattern(value, kChromeChannelBetaPattern) ||
301 MatchPattern(value, kChromeChannelBetaX64Pattern)) { 303 MatchPattern(value, kChromeChannelBetaX64Pattern)) {
302 return kChromeChannelBeta; 304 return kChromeChannelBeta;
303 } 305 }
304 // Else report values with garbage as stable since they will match the stable 306 // Else report values with garbage as stable since they will match the stable
305 // rules in the update configs. 307 // rules in the update configs.
306 return std::wstring(); 308 return std::wstring();
307 } 309 }
308 310
311 void EnsureProcessTypeIsInitialized() {
312 if (g_process_type == ProcessType::UNINITIALIZED) {
313 InitializeProcessType();
314 assert(g_process_type != ProcessType::UNINITIALIZED);
315 }
316 }
317
309 // Converts a process type specified as a string to the ProcessType enum. 318 // Converts a process type specified as a string to the ProcessType enum.
310 ProcessType GetProcessType(const std::wstring& process_type) { 319 ProcessType GetProcessType(const std::wstring& process_type) {
311 if (process_type.empty()) 320 if (process_type.empty())
312 return ProcessType::BROWSER_PROCESS; 321 return ProcessType::BROWSER_PROCESS;
313 if (process_type == kCloudPrintServiceProcess) 322 if (process_type == kCloudPrintServiceProcess)
314 return ProcessType::CLOUD_PRINT_SERVICE_PROCESS; 323 return ProcessType::CLOUD_PRINT_SERVICE_PROCESS;
324 if (process_type == kCrashpadHandlerProcess)
325 return ProcessType::CRASHPAD_HANDLER_PROCESS;
315 #if !defined(DISABLE_NACL) 326 #if !defined(DISABLE_NACL)
316 if (process_type == kNaClBrokerProcess) 327 if (process_type == kNaClBrokerProcess)
317 return ProcessType::NACL_BROKER_PROCESS; 328 return ProcessType::NACL_BROKER_PROCESS;
318 if (process_type == kNaClLoaderProcess) 329 if (process_type == kNaClLoaderProcess)
319 return ProcessType::NACL_LOADER_PROCESS; 330 return ProcessType::NACL_LOADER_PROCESS;
320 #endif 331 #endif
321 return ProcessType::OTHER_PROCESS; 332 return ProcessType::OTHER_PROCESS;
322 } 333 }
323 334
324 // Returns whether |process_type| needs the profile directory. 335 // Returns whether |process_type| needs the profile directory.
325 bool ProcessNeedsProfileDir(ProcessType process_type) { 336 bool ProcessNeedsProfileDir(ProcessType process_type) {
326 // On Windows we don't want subprocesses other than the browser process and 337 // 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 338 // 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. 339 // lies on a network share the sandbox will prevent us from accessing it.
329 switch (process_type) { 340 switch (process_type) {
330 case ProcessType::BROWSER_PROCESS: 341 case ProcessType::BROWSER_PROCESS:
331 case ProcessType::CLOUD_PRINT_SERVICE_PROCESS: 342 case ProcessType::CLOUD_PRINT_SERVICE_PROCESS:
343 case ProcessType::CRASHPAD_HANDLER_PROCESS:
332 #if !defined(DISABLE_NACL) 344 #if !defined(DISABLE_NACL)
333 case ProcessType::NACL_BROKER_PROCESS: 345 case ProcessType::NACL_BROKER_PROCESS:
334 case ProcessType::NACL_LOADER_PROCESS: 346 case ProcessType::NACL_LOADER_PROCESS:
335 #endif 347 #endif
336 return true; 348 return true;
337 case ProcessType::OTHER_PROCESS: 349 case ProcessType::OTHER_PROCESS:
338 return false; 350 return false;
339 case ProcessType::UNINITIALIZED: 351 case ProcessType::UNINITIALIZED:
340 assert(false); 352 assert(false);
341 return false; 353 return false;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 return false; 520 return false;
509 } 521 }
510 522
511 void InitializeProcessType() { 523 void InitializeProcessType() {
512 assert(g_process_type == ProcessType::UNINITIALIZED); 524 assert(g_process_type == ProcessType::UNINITIALIZED);
513 std::wstring process_type = 525 std::wstring process_type =
514 GetSwitchValueFromCommandLine(::GetCommandLine(), kProcessType); 526 GetSwitchValueFromCommandLine(::GetCommandLine(), kProcessType);
515 g_process_type = GetProcessType(process_type); 527 g_process_type = GetProcessType(process_type);
516 } 528 }
517 529
518 bool IsProcessTypeInitialized() {
519 return g_process_type != ProcessType::UNINITIALIZED;
520 }
521
522 bool IsNonBrowserProcess() { 530 bool IsNonBrowserProcess() {
523 assert(g_process_type != ProcessType::UNINITIALIZED); 531 EnsureProcessTypeIsInitialized();
524 return g_process_type != ProcessType::BROWSER_PROCESS; 532 return g_process_type != ProcessType::BROWSER_PROCESS;
525 } 533 }
526 534
527 bool ProcessNeedsProfileDir(const std::string& process_type) { 535 bool ProcessNeedsProfileDir(const std::string& process_type) {
528 return ProcessNeedsProfileDir(GetProcessType(UTF8ToUTF16(process_type))); 536 return ProcessNeedsProfileDir(GetProcessType(UTF8ToUTF16(process_type)));
529 } 537 }
530 538
539 bool CurrentProcessNeedsProfileDir() {
540 EnsureProcessTypeIsInitialized();
541 return ProcessNeedsProfileDir(g_process_type);
542 }
543
544 std::wstring GetUserDataDirectory() {
545 return install_static::InstallDetails::Get().user_data_dir();
546 }
547
548 std::wstring GetInvalidUserDataDirectory() {
549 return install_static::InstallDetails::Get().invalid_user_data_dir();
550 }
551
531 std::wstring GetCrashDumpLocation() { 552 std::wstring GetCrashDumpLocation() {
532 // In order to be able to start crash handling very early and in chrome_elf, 553 // In order to be able to start crash handling very early and in chrome_elf,
533 // we cannot rely on chrome's PathService entries (for DIR_CRASH_DUMPS) being 554 // we cannot rely on chrome's PathService entries (for DIR_CRASH_DUMPS) being
534 // available on Windows. See https://crbug.com/564398. 555 // available on Windows. See https://crbug.com/564398.
535 std::wstring user_data_dir; 556 std::wstring user_data_dir = GetUserDataDirectory();
536 bool ret = GetUserDataDirectory(&user_data_dir, nullptr); 557 if (user_data_dir.empty())
537 assert(ret); 558 return user_data_dir;
538 IgnoreUnused(ret);
539 return user_data_dir.append(L"\\Crashpad"); 559 return user_data_dir.append(L"\\Crashpad");
540 } 560 }
541 561
542 std::string GetEnvironmentString(const std::string& variable_name) { 562 std::string GetEnvironmentString(const std::string& variable_name) {
543 return UTF16ToUTF8( 563 return UTF16ToUTF8(
544 GetEnvironmentString16(UTF8ToUTF16(variable_name).c_str())); 564 GetEnvironmentString16(UTF8ToUTF16(variable_name).c_str()));
545 } 565 }
546 566
547 std::wstring GetEnvironmentString16(const wchar_t* variable_name) { 567 std::wstring GetEnvironmentString16(const wchar_t* variable_name) {
548 DWORD value_length = ::GetEnvironmentVariableW(variable_name, nullptr, 0); 568 DWORD value_length = ::GetEnvironmentVariableW(variable_name, nullptr, 0);
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 case ChannelStrategy::ADDITIONAL_PARAMETERS: 907 case ChannelStrategy::ADDITIONAL_PARAMETERS:
888 return ChannelFromAdditionalParameters(mode, ap_value); 908 return ChannelFromAdditionalParameters(mode, ap_value);
889 case ChannelStrategy::FIXED: 909 case ChannelStrategy::FIXED:
890 return mode.default_channel_name; 910 return mode.default_channel_name;
891 } 911 }
892 912
893 return std::wstring(); 913 return std::wstring();
894 } 914 }
895 915
896 } // namespace install_static 916 } // namespace install_static
OLDNEW
« no previous file with comments | « chrome/install_static/install_util.h ('k') | chrome/install_static/install_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698