Chromium Code Reviews| Index: chrome/browser/user_data_dir_extractor_win.cc |
| diff --git a/chrome/browser/user_data_dir_extractor_win.cc b/chrome/browser/user_data_dir_extractor_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..502408c41af58a425b81c9d6da5b1f9234859627 |
| --- /dev/null |
| +++ b/chrome/browser/user_data_dir_extractor_win.cc |
| @@ -0,0 +1,65 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#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.
|
| +#include "chrome/browser/user_data_dir_extractor_win.h" |
| + |
| +#include "base/command_line.h" |
| +#include "base/file_util.h" |
| +#include "base/files/file_path.h" |
| +#include "base/logging.h" |
| +#include "base/path_service.h" |
| +#include "base/process_util.h" |
| +#include "chrome/browser/ui/user_data_dir_dialog.h" |
| +#include "chrome/common/chrome_paths.h" |
| +#include "chrome/common/chrome_switches.h" |
| +#include "content/public/common/main_function_params.h" |
| + |
| +namespace chrome { |
| + |
| +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.
|
| +void InstallCustomShowUserDataDirDialogCallbackForTest( |
| + base::Closure* callback) { |
| + g_custom_show_user_data_dir_dialog_callback = callback; |
| +} |
| + |
| +base::FilePath GetUserDataDir(const content::MainFunctionParams& parameters) { |
| + base::FilePath user_data_dir; |
| + 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 |
| + // If tests have installed a custom callback for ShowUserDataDirDialog(), |
| + // invoke the callback and return. |
| + 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.
|
| + g_custom_show_user_data_dir_dialog_callback->Run(); |
| + return base::FilePath(); |
| + } |
| + |
| + 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!"; |
| + } |
| +} |
| + |
| +} // namespace chrome |