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

Side by Side Diff: chrome/browser/user_data_dir_extractor_win.cc

Issue 13825003: Fix uninintialized ResourceBundle in ShowUserDataDirDialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use l10n_util::GetApplicationLocale instead of cmdline switches. Created 7 years, 8 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 | no next file » | 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) 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/l10n/l10n_util.h"
18 #include "ui/base/resource/resource_bundle.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 kUserDataDirDialogFallbackLocale[] = "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 std::string locale = l10n_util::GetApplicationLocale(std::string());
57 DCHECK(!locale.empty());
58 if (locale.empty())
59 locale = kUserDataDirDialogFallbackLocale;
60 ResourceBundle::InitSharedInstanceWithLocale(locale, NULL);
61 }
62
49 base::FilePath new_user_data_dir = 63 base::FilePath new_user_data_dir =
50 chrome::ShowUserDataDirDialog(user_data_dir); 64 chrome::ShowUserDataDirDialog(user_data_dir);
51 65
52 if (!new_user_data_dir.empty()) { 66 if (!new_user_data_dir.empty()) {
53 // Because of the way CommandLine parses, it's sufficient to append a new 67 // 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. 68 // --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 69 // 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. 70 // sounds risky if we parse differently than CommandLineToArgvW.
57 CommandLine new_command_line = parameters.command_line; 71 CommandLine new_command_line = parameters.command_line;
58 new_command_line.AppendSwitchPath(switches::kUserDataDir, 72 new_command_line.AppendSwitchPath(switches::kUserDataDir,
59 new_user_data_dir); 73 new_user_data_dir);
60 base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL); 74 base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL);
61 } 75 }
62 #endif 76 #endif
63 NOTREACHED() << "Failed to get user data directory!"; 77 NOTREACHED() << "Failed to get user data directory!";
64 } 78 }
65 return user_data_dir; 79 return user_data_dir;
66 } 80 }
67 81
68 } // namespace chrome 82 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698