Chromium Code Reviews| Index: chrome/browser/chrome_browser_main.cc |
| diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc |
| index d7f2f648b0a65f3465316190b3c67627705da54f..0ca87cf79862531a06fc1627466a36677eb7e7c4 100644 |
| --- a/chrome/browser/chrome_browser_main.cc |
| +++ b/chrome/browser/chrome_browser_main.cc |
| @@ -354,6 +354,49 @@ base::FilePath GetStartupProfilePath(const base::FilePath& user_data_dir, |
| user_data_dir); |
| } |
| +// Returns the user data dir. Must be called prior to InitializeLocalState(). |
| +base::FilePath GetUserDataDir(const content::MainFunctionParams& parameters) { |
|
sky
2013/03/22 23:14:27
Move all of this into it its own file, maybe named
hshi1
2013/03/22 23:51:04
Done.
|
| + base::FilePath user_data_dir; |
| +#if defined(OS_WIN) |
| + PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| + |
| + // On Windows, if we fail to get the user data dir, bring up a dialog to |
| + // prompt the user to pick a different directory, and restart chrome with |
| + // the new dir. |
| + // http://code.google.com/p/chromium/issues/detail?id=11510 |
| + if (!file_util::PathExists(user_data_dir)) { |
| +#if defined(USE_AURA) |
| + // TODO(beng): |
| + NOTIMPLEMENTED(); |
| +#else |
| + base::FilePath new_user_data_dir = |
| + chrome::ShowUserDataDirDialog(user_data_dir); |
| + |
| + if (!new_user_data_dir.empty()) { |
| + // Because of the way CommandLine parses, it's sufficient to append a new |
| + // --user-data-dir switch. The last flag of the same name wins. |
| + // TODO(tc): It would be nice to remove the flag we don't want, but that |
| + // sounds risky if we parse differently than CommandLineToArgvW. |
| + CommandLine new_command_line = parameters.command_line; |
| + new_command_line.AppendSwitchPath(switches::kUserDataDir, |
| + new_user_data_dir); |
| + base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL); |
| + } |
| +#endif |
| + NOTREACHED() << "Failed to get user data directory!"; |
| + } |
| +#else |
| + // Getting the user data dir can fail if the directory isn't |
| + // creatable, for example; on Windows in code above we bring up a |
| + // dialog prompting the user to pick a different directory. |
| + // However, ProcessSingleton needs a real user_data_dir on Mac/Linux, |
| + // so it's better to fail here than fail mysteriously elsewhere. |
| + CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) |
| + << "Must be able to get user data directory!"; |
| +#endif |
| + return user_data_dir; |
| +} |
| + |
| // Initializes the profile, possibly doing some user prompting to pick a |
| // fallback profile. Returns the newly created profile, or NULL if startup |
| // should not continue. |
| @@ -386,35 +429,10 @@ Profile* CreateProfile(const content::MainFunctionParams& parameters, |
| if (profile) |
| return profile; |
| -#if defined(OS_WIN) |
| -#if defined(USE_AURA) |
| - // TODO(beng): |
| - NOTIMPLEMENTED(); |
| -#else |
| - // Ideally, we should be able to run w/o access to disk. For now, we |
| - // prompt the user to pick a different user-data-dir and restart chrome |
| - // with the new dir. |
| - // http://code.google.com/p/chromium/issues/detail?id=11510 |
| - base::FilePath new_user_data_dir = |
| - chrome::ShowUserDataDirDialog(user_data_dir); |
| - |
| - if (!new_user_data_dir.empty()) { |
| - // Because of the way CommandLine parses, it's sufficient to append a new |
| - // --user-data-dir switch. The last flag of the same name wins. |
| - // TODO(tc): It would be nice to remove the flag we don't want, but that |
| - // sounds risky if we parse differently than CommandLineToArgvW. |
| - CommandLine new_command_line = parameters.command_line; |
| - new_command_line.AppendSwitchPath(switches::kUserDataDir, |
| - new_user_data_dir); |
| - base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL); |
| - } |
| -#endif |
| -#else |
| // TODO(port): fix this. See comments near the definition of |
| // user_data_dir. It is better to CHECK-fail here than it is to |
| // silently exit because of missing code in the above test. |
| CHECK(profile) << "Cannot get default profile."; |
| -#endif |
| return NULL; |
| } |
| @@ -808,17 +826,7 @@ int ChromeBrowserMainParts::PreCreateThreads() { |
| int ChromeBrowserMainParts::PreCreateThreadsImpl() { |
| run_message_loop_ = false; |
| -#if defined(OS_WIN) |
| - PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_); |
| -#else |
| - // Getting the user data dir can fail if the directory isn't |
| - // creatable, for example; on Windows in code below we bring up a |
| - // dialog prompting the user to pick a different directory. |
| - // However, ProcessSingleton needs a real user_data_dir on Mac/Linux, |
| - // so it's better to fail here than fail mysteriously elsewhere. |
| - CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_)) |
| - << "Must be able to get user data directory!"; |
| -#endif |
| + user_data_dir_ = GetUserDataDir(parameters()); |
| // Whether this is First Run. |do_first_run_tasks_| should be prefered to this |
| // unless the desire is actually to know whether this is really First Run |