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

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

Issue 2867063002: Stability instrumentation Crashpad integration (Closed)
Patch Set: clang compile 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
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 (!IsProcessTypeInitialized()) {
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() { 530 bool IsProcessTypeInitialized() {
robertshield 2017/05/24 18:10:48 actually, could we get rid of this and inline it i
manzagop (departed) 2017/05/24 21:48:46 Done.
519 return g_process_type != ProcessType::UNINITIALIZED; 531 return g_process_type != ProcessType::UNINITIALIZED;
520 } 532 }
521 533
522 bool IsNonBrowserProcess() { 534 bool IsNonBrowserProcess() {
523 assert(g_process_type != ProcessType::UNINITIALIZED); 535 EnsureProcessTypeIsInitialized();
524 return g_process_type != ProcessType::BROWSER_PROCESS; 536 return g_process_type != ProcessType::BROWSER_PROCESS;
525 } 537 }
526 538
527 bool ProcessNeedsProfileDir(const std::string& process_type) { 539 bool ProcessNeedsProfileDir(const std::string& process_type) {
528 return ProcessNeedsProfileDir(GetProcessType(UTF8ToUTF16(process_type))); 540 return ProcessNeedsProfileDir(GetProcessType(UTF8ToUTF16(process_type)));
529 } 541 }
530 542
543 bool CurrentProcessNeedsProfileDir() {
544 EnsureProcessTypeIsInitialized();
545 return ProcessNeedsProfileDir(g_process_type);
546 }
547
548 std::wstring GetUserDataDirectory() {
549 return install_static::InstallDetails::Get().user_data_dir();
550 }
551
552 std::wstring GetInvalidUserDataDirectory() {
553 return install_static::InstallDetails::Get().invalid_user_data_dir();
554 }
555
531 std::wstring GetCrashDumpLocation() { 556 std::wstring GetCrashDumpLocation() {
532 // In order to be able to start crash handling very early and in chrome_elf, 557 // 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 558 // we cannot rely on chrome's PathService entries (for DIR_CRASH_DUMPS) being
534 // available on Windows. See https://crbug.com/564398. 559 // available on Windows. See https://crbug.com/564398.
535 std::wstring user_data_dir; 560 std::wstring user_data_dir = GetUserDataDirectory();
536 bool ret = GetUserDataDirectory(&user_data_dir, nullptr); 561 if (user_data_dir.empty())
537 assert(ret); 562 return user_data_dir;
538 IgnoreUnused(ret);
539 return user_data_dir.append(L"\\Crashpad"); 563 return user_data_dir.append(L"\\Crashpad");
540 } 564 }
541 565
542 std::string GetEnvironmentString(const std::string& variable_name) { 566 std::string GetEnvironmentString(const std::string& variable_name) {
543 return UTF16ToUTF8( 567 return UTF16ToUTF8(
544 GetEnvironmentString16(UTF8ToUTF16(variable_name).c_str())); 568 GetEnvironmentString16(UTF8ToUTF16(variable_name).c_str()));
545 } 569 }
546 570
547 std::wstring GetEnvironmentString16(const wchar_t* variable_name) { 571 std::wstring GetEnvironmentString16(const wchar_t* variable_name) {
548 DWORD value_length = ::GetEnvironmentVariableW(variable_name, nullptr, 0); 572 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: 911 case ChannelStrategy::ADDITIONAL_PARAMETERS:
888 return ChannelFromAdditionalParameters(mode, ap_value); 912 return ChannelFromAdditionalParameters(mode, ap_value);
889 case ChannelStrategy::FIXED: 913 case ChannelStrategy::FIXED:
890 return mode.default_channel_name; 914 return mode.default_channel_name;
891 } 915 }
892 916
893 return std::wstring(); 917 return std::wstring();
894 } 918 }
895 919
896 } // namespace install_static 920 } // namespace install_static
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698