Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/user_data_dir_extractor.h" | |
|
sky
2013/03/25 15:43:14
user_data_dir_extractor should be moved below with
hshi1
2013/03/25 17:18:55
Done.
| |
| 6 #include "chrome/browser/user_data_dir_extractor_win.h" | |
| 7 | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/file_util.h" | |
| 10 #include "base/files/file_path.h" | |
| 11 #include "base/logging.h" | |
| 12 #include "base/path_service.h" | |
| 13 #include "base/process_util.h" | |
| 14 #include "chrome/browser/ui/user_data_dir_dialog.h" | |
| 15 #include "chrome/common/chrome_paths.h" | |
| 16 #include "chrome/common/chrome_switches.h" | |
| 17 #include "content/public/common/main_function_params.h" | |
| 18 | |
| 19 namespace chrome { | |
| 20 | |
| 21 base::Closure* g_custom_show_user_data_dir_dialog_callback = NULL; | |
|
sky
2013/03/25 15:43:14
This isn't a global.
hshi1
2013/03/25 17:18:55
Done.
| |
| 22 void InstallCustomShowUserDataDirDialogCallbackForTest( | |
| 23 base::Closure* callback) { | |
| 24 g_custom_show_user_data_dir_dialog_callback = callback; | |
| 25 } | |
| 26 | |
| 27 base::FilePath GetUserDataDir(const content::MainFunctionParams& parameters) { | |
| 28 base::FilePath user_data_dir; | |
| 29 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | |
| 30 | |
| 31 // On Windows, if we fail to get the user data dir, bring up a dialog to | |
| 32 // prompt the user to pick a different directory, and restart chrome with | |
| 33 // the new dir. | |
| 34 // http://code.google.com/p/chromium/issues/detail?id=11510 | |
| 35 if (!file_util::PathExists(user_data_dir)) { | |
| 36 #if defined(USE_AURA) | |
| 37 // TODO(beng): | |
| 38 NOTIMPLEMENTED(); | |
| 39 #else | |
| 40 // If tests have installed a custom callback for ShowUserDataDirDialog(), | |
| 41 // invoke the callback and return. | |
| 42 if (g_custom_show_user_data_dir_dialog_callback) { | |
|
sky
2013/03/25 15:43:14
If this is set then invoke it first thing and earl
hshi1
2013/03/25 17:18:55
Actually it wasn't my intention to make the callba
sky
2013/03/25 19:19:04
This logic should be in the specified function and
hshi1
2013/03/25 19:31:15
Understood, Done.
| |
| 43 g_custom_show_user_data_dir_dialog_callback->Run(); | |
| 44 return base::FilePath(); | |
| 45 } | |
| 46 | |
| 47 base::FilePath new_user_data_dir = | |
| 48 chrome::ShowUserDataDirDialog(user_data_dir); | |
| 49 | |
| 50 if (!new_user_data_dir.empty()) { | |
| 51 // Because of the way CommandLine parses, it's sufficient to append a new | |
| 52 // --user-data-dir switch. The last flag of the same name wins. | |
| 53 // TODO(tc): It would be nice to remove the flag we don't want, but that | |
| 54 // sounds risky if we parse differently than CommandLineToArgvW. | |
| 55 CommandLine new_command_line = parameters.command_line; | |
| 56 new_command_line.AppendSwitchPath(switches::kUserDataDir, | |
| 57 new_user_data_dir); | |
| 58 base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL); | |
| 59 } | |
| 60 #endif | |
| 61 NOTREACHED() << "Failed to get user data directory!"; | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 } // namespace chrome | |
| OLD | NEW |