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

Side by Side Diff: chrome/app/chrome_main_delegate.cc

Issue 174253002: Initialize chrome::DIR_USER_DATA early on for service processes, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use dynamic_annotations_win64 for common_constants_win64. Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/chrome_browser_main.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/app/chrome_main_delegate.h" 5 #include "chrome/app/chrome_main_delegate.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/metrics/statistics_recorder.h" 12 #include "base/metrics/statistics_recorder.h"
13 #include "base/metrics/stats_counters.h" 13 #include "base/metrics/stats_counters.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/process/memory.h" 15 #include "base/process/memory.h"
16 #include "base/process/process_handle.h" 16 #include "base/process/process_handle.h"
17 #include "base/strings/string_util.h"
17 #include "build/build_config.h" 18 #include "build/build_config.h"
18 #include "chrome/browser/chrome_content_browser_client.h" 19 #include "chrome/browser/chrome_content_browser_client.h"
19 #include "chrome/browser/defaults.h" 20 #include "chrome/browser/defaults.h"
20 #include "chrome/common/chrome_constants.h" 21 #include "chrome/common/chrome_constants.h"
21 #include "chrome/common/chrome_content_client.h" 22 #include "chrome/common/chrome_content_client.h"
22 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/chrome_paths_internal.h"
23 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/chrome_version_info.h" 26 #include "chrome/common/chrome_version_info.h"
25 #include "chrome/common/crash_keys.h" 27 #include "chrome/common/crash_keys.h"
26 #include "chrome/common/logging_chrome.h" 28 #include "chrome/common/logging_chrome.h"
27 #include "chrome/common/profiling.h" 29 #include "chrome/common/profiling.h"
30 #include "chrome/common/switch_utils.h"
28 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
29 #include "chrome/plugin/chrome_content_plugin_client.h" 32 #include "chrome/plugin/chrome_content_plugin_client.h"
30 #include "chrome/renderer/chrome_content_renderer_client.h" 33 #include "chrome/renderer/chrome_content_renderer_client.h"
31 #include "chrome/utility/chrome_content_utility_client.h" 34 #include "chrome/utility/chrome_content_utility_client.h"
32 #include "components/nacl/common/nacl_switches.h" 35 #include "components/nacl/common/nacl_switches.h"
33 #include "components/startup_metric_utils/startup_metric_utils.h" 36 #include "components/startup_metric_utils/startup_metric_utils.h"
34 #include "content/public/common/content_client.h" 37 #include "content/public/common/content_client.h"
35 #include "content/public/common/content_paths.h" 38 #include "content/public/common/content_paths.h"
36 #include "ui/base/ui_base_switches.h" 39 #include "ui/base/ui_base_switches.h"
37 40
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 #if defined(USE_X11) 92 #if defined(USE_X11)
90 #include <stdlib.h> 93 #include <stdlib.h>
91 #include <string.h> 94 #include <string.h>
92 #include "ui/base/x/x11_util.h" 95 #include "ui/base/x/x11_util.h"
93 #endif 96 #endif
94 97
95 #if defined(OS_POSIX) && !defined(OS_MACOSX) 98 #if defined(OS_POSIX) && !defined(OS_MACOSX)
96 #include "components/breakpad/app/breakpad_linux.h" 99 #include "components/breakpad/app/breakpad_linux.h"
97 #endif 100 #endif
98 101
102 #if defined(OS_LINUX)
103 #include "base/environment.h"
104 #endif
105
106 #if defined(OS_MACOSX) || defined(OS_WIN)
107 #include "chrome/browser/policy/policy_path_parser.h"
108 #endif
109
99 #if !defined(CHROME_MULTIPLE_DLL_CHILD) 110 #if !defined(CHROME_MULTIPLE_DLL_CHILD)
100 base::LazyInstance<chrome::ChromeContentBrowserClient> 111 base::LazyInstance<chrome::ChromeContentBrowserClient>
101 g_chrome_content_browser_client = LAZY_INSTANCE_INITIALIZER; 112 g_chrome_content_browser_client = LAZY_INSTANCE_INITIALIZER;
102 #endif 113 #endif
103 114
104 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) 115 #if !defined(CHROME_MULTIPLE_DLL_BROWSER)
105 base::LazyInstance<ChromeContentRendererClient> 116 base::LazyInstance<ChromeContentRendererClient>
106 g_chrome_content_renderer_client = LAZY_INSTANCE_INITIALIZER; 117 g_chrome_content_renderer_client = LAZY_INSTANCE_INITIALIZER;
107 base::LazyInstance<chrome::ChromeContentUtilityClient> 118 base::LazyInstance<chrome::ChromeContentUtilityClient>
108 g_chrome_content_utility_client = LAZY_INSTANCE_INITIALIZER; 119 g_chrome_content_utility_client = LAZY_INSTANCE_INITIALIZER;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 } 314 }
304 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID) 315 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID)
305 316
306 #endif // OS_POSIX 317 #endif // OS_POSIX
307 318
308 struct MainFunction { 319 struct MainFunction {
309 const char* name; 320 const char* name;
310 int (*function)(const content::MainFunctionParams&); 321 int (*function)(const content::MainFunctionParams&);
311 }; 322 };
312 323
324 // Initializes the user data dir. Must be called before InitializeLocalState().
325 void InitializeUserDataDir() {
326 CommandLine* command_line = CommandLine::ForCurrentProcess();
327 base::FilePath user_data_dir =
328 command_line->GetSwitchValuePath(switches::kUserDataDir);
329 std::string process_type =
330 command_line->GetSwitchValueASCII(switches::kProcessType);
331
332 #if defined(OS_LINUX)
333 // On Linux, Chrome does not support running multiple copies under different
334 // DISPLAYs, so the profile directory can be specified in the environment to
335 // support the virtual desktop use-case.
336 if (user_data_dir.empty()) {
337 std::string user_data_dir_string;
338 scoped_ptr<base::Environment> environment(base::Environment::Create());
339 if (environment->GetVar("CHROME_USER_DATA_DIR", &user_data_dir_string) &&
340 IsStringUTF8(user_data_dir_string)) {
341 user_data_dir = base::FilePath::FromUTF8Unsafe(user_data_dir_string);
342 }
343 }
344 #endif
345 #if defined(OS_MACOSX) || defined(OS_WIN)
346 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir);
347 #endif
348
349 const bool specified_directory_was_invalid = !user_data_dir.empty() &&
350 !PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA,
351 user_data_dir, chrome::ProcessNeedsProfileDir(process_type));
352 // Save inaccessible or invalid paths so the user may be prompted later.
353 if (specified_directory_was_invalid)
354 chrome::SetInvalidSpecifiedUserDataDir(user_data_dir);
355
356 // Getting the user data directory can fail if the directory isn't creatable.
357 // ProcessSingleton needs a real user data directory on Mac/Linux, so it's
358 // better to fail here than fail mysteriously elsewhere.
359 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
360 << "Must be able to get user data directory!";
361
362 // Append the fallback user data directory to the commandline. Otherwise,
363 // child or service processes will attempt to use the invalid directory.
364 if (specified_directory_was_invalid)
365 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
366 }
367
313 } // namespace 368 } // namespace
314 369
315 ChromeMainDelegate::ChromeMainDelegate() { 370 ChromeMainDelegate::ChromeMainDelegate() {
316 #if defined(OS_ANDROID) 371 #if defined(OS_ANDROID)
317 // On Android the main entry point time is the time when the Java code starts. 372 // On Android the main entry point time is the time when the Java code starts.
318 // This happens before the shared library containing this code is even loaded. 373 // This happens before the shared library containing this code is even loaded.
319 // The Java startup code has recorded that time, but the C++ code can't fetch it 374 // The Java startup code has recorded that time, but the C++ code can't fetch it
320 // from the Java side until it has initialized the JNI. See 375 // from the Java side until it has initialized the JNI. See
321 // ChromeMainDelegateAndroid. 376 // ChromeMainDelegateAndroid.
322 #else 377 #else
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 chrome::GetVersionedDirectory(). 626 chrome::GetVersionedDirectory().
572 Append(chrome::kHelperProcessExecutablePath)); 627 Append(chrome::kHelperProcessExecutablePath));
573 628
574 InitMacCrashReporter(command_line, process_type); 629 InitMacCrashReporter(command_line, process_type);
575 #endif 630 #endif
576 631
577 #if defined(OS_WIN) 632 #if defined(OS_WIN)
578 child_process_logging::Init(); 633 child_process_logging::Init();
579 #endif 634 #endif
580 635
636 // Initialize the user data dir for service processes, logging, etc.
637 InitializeUserDataDir();
638
581 stats_counter_timer_.reset(new base::StatsCounterTimer("Chrome.Init")); 639 stats_counter_timer_.reset(new base::StatsCounterTimer("Chrome.Init"));
582 startup_timer_.reset(new base::StatsScope<base::StatsCounterTimer> 640 startup_timer_.reset(new base::StatsScope<base::StatsCounterTimer>
583 (*stats_counter_timer_)); 641 (*stats_counter_timer_));
584 642
585 // Enable the heap profiler as early as possible! 643 // Enable the heap profiler as early as possible!
586 EnableHeapProfiler(command_line); 644 EnableHeapProfiler(command_line);
587 645
588 // Enable Message Loop related state asap. 646 // Enable Message Loop related state asap.
589 if (command_line.HasSwitch(switches::kMessageLoopHistogrammer)) 647 if (command_line.HasSwitch(switches::kMessageLoopHistogrammer))
590 base::MessageLoop::EnableHistogrammer(true); 648 base::MessageLoop::EnableHistogrammer(true);
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 } 885 }
828 886
829 content::ContentUtilityClient* 887 content::ContentUtilityClient*
830 ChromeMainDelegate::CreateContentUtilityClient() { 888 ChromeMainDelegate::CreateContentUtilityClient() {
831 #if defined(CHROME_MULTIPLE_DLL_BROWSER) 889 #if defined(CHROME_MULTIPLE_DLL_BROWSER)
832 return NULL; 890 return NULL;
833 #else 891 #else
834 return g_chrome_content_utility_client.Pointer(); 892 return g_chrome_content_utility_client.Pointer();
835 #endif 893 #endif
836 } 894 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chrome_browser_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698