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

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

Issue 2884333004: Relocate Windows ProcessNeedsProfileDir to install_static (Closed)
Patch Set: polish 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') | no next file » | 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
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";
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
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) {
297 if (process_type.empty()) {
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
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 ||
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
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 // DO NOT SUBMIT: ask reviewer about the reason for the sandbox check.
scottmg 2017/05/17 17:58:37 I don't really know, but I suspect it was only a s
robertshield 2017/05/17 18:24:54 I'm pretty sure that's the long and the short of i
manzagop (departed) 2017/05/17 18:59:14 A quick look at live processes on a windows box sh
robertshield 2017/05/17 19:30:05 This suggests that and empty --process-type value
458 IsSandboxedProcessFunc is_sandboxed_process_func = 498 std::wstring process_type =
459 reinterpret_cast<IsSandboxedProcessFunc>( 499 GetSwitchValueFromCommandLine(::GetCommandLine(), kProcessType);
460 ::GetProcAddress(::GetModuleHandle(nullptr), "IsSandboxedProcess")); 500 g_process_type = GetProcessType(process_type);
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 } 501 }
476 502
477 bool IsNonBrowserProcess() { 503 bool IsNonBrowserProcess() {
478 assert(g_process_type != ProcessType::UNINITIALIZED); 504 assert(g_process_type != ProcessType::UNINITIALIZED);
479 return g_process_type == ProcessType::NON_BROWSER_PROCESS; 505 // DO NOT SUBMIT: validate ProcessType::UNINITIALIZED in condition.
506 return g_process_type != ProcessType::BROWSER_PROCESS &&
507 g_process_type != ProcessType::UNINITIALIZED;
scottmg 2017/05/17 17:58:37 Does this get hit? Wouldn't the assert trigger?
manzagop (departed) 2017/05/17 18:59:14 Ah right: I'd mentally interpreted is as DCHECK.
508 }
509
510 bool ProcessNeedsProfileDir(const std::string& process_type) {
511 return ProcessNeedsProfileDir(GetProcessType(UTF8ToUTF16(process_type)));
480 } 512 }
481 513
482 std::wstring GetCrashDumpLocation() { 514 std::wstring GetCrashDumpLocation() {
483 // In order to be able to start crash handling very early and in chrome_elf, 515 // 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 516 // we cannot rely on chrome's PathService entries (for DIR_CRASH_DUMPS) being
485 // available on Windows. See https://crbug.com/564398. 517 // available on Windows. See https://crbug.com/564398.
486 std::wstring user_data_dir; 518 std::wstring user_data_dir;
487 bool ret = GetUserDataDirectory(&user_data_dir, nullptr); 519 bool ret = GetUserDataDirectory(&user_data_dir, nullptr);
488 assert(ret); 520 assert(ret);
489 IgnoreUnused(ret); 521 IgnoreUnused(ret);
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 case ChannelStrategy::ADDITIONAL_PARAMETERS: 870 case ChannelStrategy::ADDITIONAL_PARAMETERS:
839 return ChannelFromAdditionalParameters(mode, ap_value); 871 return ChannelFromAdditionalParameters(mode, ap_value);
840 case ChannelStrategy::FIXED: 872 case ChannelStrategy::FIXED:
841 return mode.default_channel_name; 873 return mode.default_channel_name;
842 } 874 }
843 875
844 return std::wstring(); 876 return std::wstring();
845 } 877 }
846 878
847 } // namespace install_static 879 } // namespace install_static
OLDNEW
« no previous file with comments | « chrome/install_static/install_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698