diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-26 04:43:36 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-26 04:43:36 +0000 |
commit | 38233e6c082d748aac5f55cc38ca0d2e581755a6 (patch) | |
tree | a2172efa91d6d0d8a4de69a40dc4f445bd01d2ed | |
parent | 20ae4824364a0a871bae34322b030424f0f78653 (diff) | |
download | chromium_src-38233e6c082d748aac5f55cc38ca0d2e581755a6.zip chromium_src-38233e6c082d748aac5f55cc38ca0d2e581755a6.tar.gz chromium_src-38233e6c082d748aac5f55cc38ca0d2e581755a6.tar.bz2 |
Get rid of more calls to FromWStringHack.
BUG=24672
TEST=compiles
Patch from Thiago Farina <thiago.farina@gmail.com>
Review URL: http://codereview.chromium.org/1750013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45568 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/download/download_manager.cc | 8 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.h | 6 | ||||
-rw-r--r-- | chrome/browser/download/save_package.cc | 15 | ||||
-rw-r--r-- | chrome/browser/gtk/options/advanced_contents_gtk.cc | 9 | ||||
-rw-r--r-- | chrome/browser/profile_manager.cc | 11 | ||||
-rw-r--r-- | chrome/browser/user_data_manager.cc | 39 | ||||
-rw-r--r-- | chrome/browser/user_data_manager.h | 8 | ||||
-rw-r--r-- | chrome/common/chrome_plugin_util.cc | 8 |
8 files changed, 43 insertions, 61 deletions
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc index 9ef6ead..00eff14 100644 --- a/chrome/browser/download/download_manager.cc +++ b/chrome/browser/download/download_manager.cc @@ -321,11 +321,11 @@ void DownloadManager::RegisterUserPrefs(PrefService* prefs) { // the user if he really wants it on an unsafe place such as the desktop. if (!prefs->GetBoolean(prefs::kDownloadDirUpgraded)) { - FilePath current_download_dir = FilePath::FromWStringHack( - prefs->GetString(prefs::kDownloadDefaultDirectory)); + FilePath current_download_dir = prefs->GetFilePath( + prefs::kDownloadDefaultDirectory); if (download_util::DownloadPathIsDangerous(current_download_dir)) { - prefs->SetString(prefs::kDownloadDefaultDirectory, - default_download_path.ToWStringHack()); + prefs->SetFilePath(prefs::kDownloadDefaultDirectory, + default_download_path); } prefs->SetBoolean(prefs::kDownloadDirUpgraded, true); } diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h index e38e130..c77d480 100644 --- a/chrome/browser/download/download_manager.h +++ b/chrome/browser/download/download_manager.h @@ -469,9 +469,7 @@ class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, return static_cast<int>(in_progress_.size()); } - FilePath download_path() { - return FilePath::FromWStringHack(*download_path_); - } + FilePath download_path() { return *download_path_; } // Clears the last download path, used to initialize "save as" dialogs. void ClearLastDownloadPath(); @@ -700,7 +698,7 @@ class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, // User preferences BooleanPrefMember prompt_for_download_; - StringPrefMember download_path_; + FilePathPrefMember download_path_; // The user's last choice for download directory. This is only used when the // user wants us to prompt for a save location for each download. diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc index a549e9c..d58cc48 100644 --- a/chrome/browser/download/save_package.cc +++ b/chrome/browser/download/save_package.cc @@ -1133,22 +1133,19 @@ FilePath SavePackage::GetSaveDirPreference(PrefService* prefs) { DCHECK(prefs); if (!prefs->FindPreference(prefs::kSaveFileDefaultDirectory)) { - FilePath default_save_path; - StringPrefMember default_download_path; DCHECK(prefs->FindPreference(prefs::kDownloadDefaultDirectory)); - default_download_path.Init(prefs::kDownloadDefaultDirectory, prefs, NULL); - default_save_path = - FilePath::FromWStringHack(default_download_path.GetValue()); + FilePath default_save_path = prefs->GetFilePath( + prefs::kDownloadDefaultDirectory); prefs->RegisterFilePathPref(prefs::kSaveFileDefaultDirectory, default_save_path); } // Get the directory from preference. - StringPrefMember save_file_path; - save_file_path.Init(prefs::kSaveFileDefaultDirectory, prefs, NULL); - DCHECK(!(*save_file_path).empty()); + FilePath save_file_path = prefs->GetFilePath( + prefs::kSaveFileDefaultDirectory); + DCHECK(!save_file_path.empty()); - return FilePath::FromWStringHack(*save_file_path); + return save_file_path; } void SavePackage::GetSaveInfo() { diff --git a/chrome/browser/gtk/options/advanced_contents_gtk.cc b/chrome/browser/gtk/options/advanced_contents_gtk.cc index 031763f..022468d 100644 --- a/chrome/browser/gtk/options/advanced_contents_gtk.cc +++ b/chrome/browser/gtk/options/advanced_contents_gtk.cc @@ -166,7 +166,7 @@ class DownloadSection : public OptionsPageBase { GtkWidget* page_; // Pref members. - StringPrefMember default_download_location_; + FilePathPrefMember default_download_location_; BooleanPrefMember ask_for_save_location_; StringPrefMember auto_open_files_; @@ -266,8 +266,7 @@ void DownloadSection::NotifyPrefChanged(const std::wstring* pref_name) { if (!pref_name || *pref_name == prefs::kDownloadDefaultDirectory) { gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(download_location_button_), - FilePath::FromWStringHack( - default_download_location_.GetValue()).value().c_str()); + default_download_location_.GetValue().value().c_str()); } if (!pref_name || *pref_name == prefs::kPromptForDownload) { @@ -296,8 +295,8 @@ void DownloadSection::OnDownloadLocationChanged(GtkFileChooser* widget, g_free(folder); // Gtk seems to call this signal multiple times, so we only set the pref and // metric if something actually changed. - if (path.ToWStringHack() != section->default_download_location_.GetValue()) { - section->default_download_location_.SetValue(path.ToWStringHack()); + if (path != section->default_download_location_.GetValue()) { + section->default_download_location_.SetValue(path); section->UserMetricsRecordAction( UserMetricsAction("Options_SetDownloadDirectory"), section->profile()->GetPrefs()); diff --git a/chrome/browser/profile_manager.cc b/chrome/browser/profile_manager.cc index 332866b..851ef3e 100644 --- a/chrome/browser/profile_manager.cc +++ b/chrome/browser/profile_manager.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -98,21 +98,20 @@ Profile* ProfileManager::GetDefaultProfile(const FilePath& user_data_dir) { #if defined(OS_CHROMEOS) const CommandLine& command_line = *CommandLine::ForCurrentProcess(); if (logged_in_) { - std::wstring profile_dir; + FilePath profile_dir; // If the user has logged in, pick up the new profile. // TODO(davemoore) Delete this once chromium os has started using // "--login-profile" instead of "--profile". if (command_line.HasSwitch(switches::kLoginProfile)) { - profile_dir = command_line.GetSwitchValue(switches::kLoginProfile); + profile_dir = command_line.GetSwitchValuePath(switches::kLoginProfile); } else if (command_line.HasSwitch(switches::kProfile)) { - profile_dir = command_line.GetSwitchValue(switches::kProfile); + profile_dir = command_line.GetSwitchValuePath(switches::kProfile); } else { // We should never be logged in with no profile dir. NOTREACHED(); return NULL; } - default_profile_dir = default_profile_dir.Append( - FilePath::FromWStringHack(profile_dir)); + default_profile_dir = default_profile_dir.Append(profile_dir); return GetProfile(default_profile_dir); } else { // If not logged in on cros, always return the incognito profile diff --git a/chrome/browser/user_data_manager.cc b/chrome/browser/user_data_manager.cc index 7d9c98a..25bd366 100644 --- a/chrome/browser/user_data_manager.cc +++ b/chrome/browser/user_data_manager.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -31,15 +31,6 @@ namespace { -// TODO: don't use wstrings in all this code. :( -// But I'm not fixing it right now since this code is reported to be going -// away. -void DeprecatedPathServiceGet(int key, std::wstring* str) { - FilePath path; - PathService::Get(key, &path); - *str = path.ToWStringHack(); -} - // Helper to start chrome for a given profile index. The helper takes care of // enumerating profiles on the file thread and then it launches Chrome for the // appropriate profile on the original thread. @@ -144,9 +135,9 @@ UserDataManager* UserDataManager::instance_ = NULL; // static UserDataManager* UserDataManager::Create() { DCHECK(!instance_); - std::wstring user_data; - DeprecatedPathServiceGet(chrome::DIR_USER_DATA, &user_data); - instance_ = new UserDataManager(user_data); + FilePath user_path; + PathService::Get(chrome::DIR_USER_DATA, &user_path); + instance_ = new UserDataManager(user_path); return instance_; } @@ -156,10 +147,10 @@ UserDataManager* UserDataManager::Get() { return instance_; } -UserDataManager::UserDataManager(const std::wstring& user_data_root) +UserDataManager::UserDataManager(const FilePath& user_data_root) : user_data_root_(user_data_root) { // Determine current profile name and current folder name. - current_folder_name_ = file_util::GetFilenameFromPath(user_data_root); + current_folder_name_ = user_data_root.BaseName().ToWStringHack(); bool success = GetProfileNameFromFolderName(current_folder_name_, ¤t_profile_name_); // The current profile is a default profile if the current user data folder @@ -171,7 +162,7 @@ UserDataManager::UserDataManager(const std::wstring& user_data_root) // (TODO:munjal) Fix issue 5070: // http://code.google.com/p/chromium/issues/detail?id=5070 - file_util::UpOneDirectory(&user_data_root_); + user_data_root_ = user_data_root_.DirName(); } UserDataManager::~UserDataManager() { @@ -221,9 +212,8 @@ std::wstring UserDataManager::GetFolderNameFromProfileName( std::wstring UserDataManager::GetUserDataFolderForProfile( const std::wstring& profile_name) const { std::wstring folder_name = GetFolderNameFromProfileName(profile_name); - FilePath folder_path = - FilePath::FromWStringHack(user_data_root_) - .Append(FilePath::FromWStringHack(folder_name)); + FilePath folder_path = user_data_root_.Append( + FilePath::FromWStringHack(folder_name)); return folder_path.ToWStringHack(); } @@ -236,10 +226,10 @@ void UserDataManager::LaunchChromeForProfile( command_line.AppendSwitch(switches::kEnableUserDataDirProfiles); command_line.AppendSwitchWithValue(switches::kUserDataDir, user_data_dir); - std::wstring local_state_path; - DeprecatedPathServiceGet(chrome::FILE_LOCAL_STATE, &local_state_path); + FilePath local_state_path; + PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); command_line.AppendSwitchWithValue(switches::kParentProfile, - local_state_path); + local_state_path.ToWStringHack()); base::LaunchApp(command_line, false, false, NULL); } @@ -253,9 +243,8 @@ void UserDataManager::LaunchChromeForProfile(int index) const { void UserDataManager::GetProfiles(std::vector<std::wstring>* profiles) const { // This function should be called on the file thread. DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); - file_util::FileEnumerator file_enum( - FilePath::FromWStringHack(user_data_root_), - false, file_util::FileEnumerator::DIRECTORIES); + file_util::FileEnumerator file_enum(user_data_root_, false, + file_util::FileEnumerator::DIRECTORIES); std::wstring folder_name; while (!(folder_name = file_enum.Next().ToWStringHack()).empty()) { folder_name = file_util::GetFilenameFromPath(folder_name); diff --git a/chrome/browser/user_data_manager.h b/chrome/browser/user_data_manager.h index edd63e9..ddcc43b 100644 --- a/chrome/browser/user_data_manager.h +++ b/chrome/browser/user_data_manager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -12,9 +12,9 @@ #include <vector> #include "base/basictypes.h" +#include "base/file_path.h" #include "base/ref_counted.h" -class FilePath; class MessageLoop; // Provides an abstraction of profiles on top of the user data directory @@ -36,7 +36,7 @@ class UserDataManager { // Creates a new instance with the given root folder for storing user data // folders. - explicit UserDataManager(const std::wstring& user_data_root); + explicit UserDataManager(const FilePath& user_data_root); ~UserDataManager(); @@ -93,7 +93,7 @@ class UserDataManager { static UserDataManager* instance_; // Root folder. - std::wstring user_data_root_; + FilePath user_data_root_; // Current user data folder. std::wstring current_folder_name_; diff --git a/chrome/common/chrome_plugin_util.cc b/chrome/common/chrome_plugin_util.cc index e65b77b..08be12b 100644 --- a/chrome/common/chrome_plugin_util.cc +++ b/chrome/common/chrome_plugin_util.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -129,14 +129,14 @@ CPError CPB_GetCommandLineArgumentsCommon(const char* url, std::wstring arguments_w; // Use the same UserDataDir for new launches that we currently have set. - std::wstring user_data_dir = cmd.GetSwitchValue(switches::kUserDataDir); + FilePath user_data_dir = cmd.GetSwitchValuePath(switches::kUserDataDir); if (!user_data_dir.empty()) { // Make sure user_data_dir is an absolute path. if (file_util::AbsolutePath(&user_data_dir) && - file_util::PathExists(FilePath::FromWStringHack(user_data_dir))) { + file_util::PathExists(user_data_dir)) { // TODO(evanm): use CommandLine APIs instead of this. arguments_w += std::wstring(L"--") + ASCIIToWide(switches::kUserDataDir) + - L"=\"" + user_data_dir + L"\" "; + L"=\"" + user_data_dir.ToWStringHack() + L"\" "; } } |