OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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/browser/user_data_dir_extractor_win.h" | 5 #include "chrome/browser/user_data_dir_extractor_win.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
12 #include "chrome/browser/ui/user_data_dir_dialog.h" | 12 #include "chrome/browser/ui/user_data_dir_dialog.h" |
13 #include "chrome/browser/user_data_dir_extractor.h" | 13 #include "chrome/browser/user_data_dir_extractor.h" |
14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "content/public/common/main_function_params.h" | 16 #include "content/public/common/main_function_params.h" |
17 #include "ui/base/resource/resource_bundle.h" | |
18 #include "ui/base/ui_base_switches.h" | |
17 | 19 |
18 namespace chrome { | 20 namespace chrome { |
19 | 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 GetUserDataDirCallback* custom_get_user_data_dir_callback = NULL; | 24 GetUserDataDirCallback* custom_get_user_data_dir_callback = NULL; |
23 | 25 |
26 const char kDefaultUserDataDirDialogLocale[] = "en-US"; | |
27 | |
24 } // namespace | 28 } // namespace |
25 | 29 |
26 void InstallCustomGetUserDataDirCallbackForTest( | 30 void InstallCustomGetUserDataDirCallbackForTest( |
27 GetUserDataDirCallback* callback) { | 31 GetUserDataDirCallback* callback) { |
28 custom_get_user_data_dir_callback = callback; | 32 custom_get_user_data_dir_callback = callback; |
29 } | 33 } |
30 | 34 |
31 base::FilePath GetUserDataDir(const content::MainFunctionParams& parameters) { | 35 base::FilePath GetUserDataDir(const content::MainFunctionParams& parameters) { |
32 // If tests have installed a custom callback for GetUserDataDir(), invoke the | 36 // If tests have installed a custom callback for GetUserDataDir(), invoke the |
33 // callback and return. | 37 // callback and return. |
34 if (custom_get_user_data_dir_callback) | 38 if (custom_get_user_data_dir_callback) |
35 return custom_get_user_data_dir_callback->Run(); | 39 return custom_get_user_data_dir_callback->Run(); |
36 | 40 |
37 base::FilePath user_data_dir; | 41 base::FilePath user_data_dir; |
38 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 42 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
39 | 43 |
40 // On Windows, if we fail to get the user data dir, bring up a dialog to | 44 // On Windows, if we fail to get the user data dir, bring up a dialog to |
41 // prompt the user to pick a different directory, and restart chrome with | 45 // prompt the user to pick a different directory, and restart chrome with |
42 // the new dir. | 46 // the new dir. |
43 // http://code.google.com/p/chromium/issues/detail?id=11510 | 47 // http://code.google.com/p/chromium/issues/detail?id=11510 |
44 if (!file_util::PathExists(user_data_dir)) { | 48 if (!file_util::PathExists(user_data_dir)) { |
45 #if defined(USE_AURA) | 49 #if defined(USE_AURA) |
46 // TODO(beng): | 50 // TODO(beng): |
47 NOTIMPLEMENTED(); | 51 NOTIMPLEMENTED(); |
48 #else | 52 #else |
53 // Make sure ResourceBundle is initialized. The user data dialog needs to | |
54 // access string resources. See http://crbug.com/230432 | |
55 if (!ResourceBundle::HasSharedInstance()) { | |
56 // Check if a locale override has been specified on the command line. | |
57 CommandLine command_line = parameters.command_line; | |
58 std::string locale = command_line.GetSwitchValueASCII(switches::kLang); | |
59 if (locale.empty()) | |
60 locale = kDefaultUserDataDirDialogLocale; | |
jungshik at Google
2013/04/11 21:57:55
Can we do better than this? Is this only for Windo
hshi1
2013/04/11 23:05:33
Can you review Patch Set #4? Thanks!
On 2013/04/1
| |
61 ResourceBundle::InitSharedInstanceWithLocale(locale, NULL); | |
62 } | |
63 | |
49 base::FilePath new_user_data_dir = | 64 base::FilePath new_user_data_dir = |
50 chrome::ShowUserDataDirDialog(user_data_dir); | 65 chrome::ShowUserDataDirDialog(user_data_dir); |
51 | 66 |
52 if (!new_user_data_dir.empty()) { | 67 if (!new_user_data_dir.empty()) { |
53 // Because of the way CommandLine parses, it's sufficient to append a new | 68 // Because of the way CommandLine parses, it's sufficient to append a new |
54 // --user-data-dir switch. The last flag of the same name wins. | 69 // --user-data-dir switch. The last flag of the same name wins. |
55 // TODO(tc): It would be nice to remove the flag we don't want, but that | 70 // TODO(tc): It would be nice to remove the flag we don't want, but that |
56 // sounds risky if we parse differently than CommandLineToArgvW. | 71 // sounds risky if we parse differently than CommandLineToArgvW. |
57 CommandLine new_command_line = parameters.command_line; | 72 CommandLine new_command_line = parameters.command_line; |
58 new_command_line.AppendSwitchPath(switches::kUserDataDir, | 73 new_command_line.AppendSwitchPath(switches::kUserDataDir, |
59 new_user_data_dir); | 74 new_user_data_dir); |
60 base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL); | 75 base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL); |
61 } | 76 } |
62 #endif | 77 #endif |
63 NOTREACHED() << "Failed to get user data directory!"; | 78 NOTREACHED() << "Failed to get user data directory!"; |
64 } | 79 } |
65 return user_data_dir; | 80 return user_data_dir; |
66 } | 81 } |
67 | 82 |
68 } // namespace chrome | 83 } // namespace chrome |
OLD | NEW |