diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-28 21:54:32 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-28 21:54:32 +0000 |
commit | f7011fcb7f28651953b1765b241c974e25c8cd40 (patch) | |
tree | f3a2c97bb98cc12aaca39bb27791998f026b58b7 /chrome/browser | |
parent | 4663213354a9c41ab0e5a785d52bf5c9a9692514 (diff) | |
download | chromium_src-f7011fcb7f28651953b1765b241c974e25c8cd40.zip chromium_src-f7011fcb7f28651953b1765b241c974e25c8cd40.tar.gz chromium_src-f7011fcb7f28651953b1765b241c974e25c8cd40.tar.bz2 |
Porting profiles to the Mac.
Review URL: http://codereview.chromium.org/19623
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8831 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
43 files changed, 266 insertions, 232 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm index 2112218..3895ece 100644 --- a/chrome/browser/app_controller_mac.mm +++ b/chrome/browser/app_controller_mac.mm @@ -9,6 +9,7 @@ #import "chrome/browser/browser.h" #import "chrome/browser/browser_list.h" #import "chrome/browser/command_updater.h" +#import "chrome/browser/profile_manager.h" #import "chrome/common/temp_scaffolding_stubs.h" @interface AppController(PRIVATE) @@ -74,13 +75,16 @@ // command is supported and doesn't check, otherwise it would have been disabled // in the UI in validateUserInterfaceItem:. - (void)commandDispatch:(id)sender { + // How to get the profile created on line 314 of browser_main? Ugh. TODO:FIXME + Profile* default_profile = *g_browser_process->profile_manager()->begin(); + NSInteger tag = [sender tag]; switch (tag) { case IDC_NEW_WINDOW: - Browser::OpenEmptyWindow(ProfileManager::FakeProfile()); + Browser::OpenEmptyWindow(default_profile); break; case IDC_NEW_INCOGNITO_WINDOW: - Browser::OpenURLOffTheRecord(ProfileManager::FakeProfile(), GURL()); + Browser::OpenURLOffTheRecord(default_profile, GURL()); break; }; } diff --git a/chrome/browser/back_forward_menu_model_unittest.cc b/chrome/browser/back_forward_menu_model_unittest.cc index dbf4e4c..20f718d 100644 --- a/chrome/browser/back_forward_menu_model_unittest.cc +++ b/chrome/browser/back_forward_menu_model_unittest.cc @@ -75,7 +75,8 @@ class BackFwdMenuModelTest : public testing::Test { profile_path_ = test_dir_; file_util::AppendToPath(&profile_path_, L"New Profile"); - profile_ = ProfileManager::CreateProfile(profile_path_, + profile_ = ProfileManager::CreateProfile( + FilePath::FromWStringHack(profile_path_), L"New Profile", L"new-profile", L""); ASSERT_TRUE(profile_); pm_.AddProfile(profile_); @@ -85,7 +86,7 @@ class BackFwdMenuModelTest : public testing::Test { TabContents::RegisterFactory(kHTTPTabContentsType, NULL); // Removes a profile from the set of currently-loaded profiles. - pm_.RemoveProfileByPath(profile_path_); + pm_.RemoveProfileByPath(FilePath::FromWStringHack(profile_path_)); // Clean up test directory ASSERT_TRUE(file_util::Delete(test_dir_, true)); diff --git a/chrome/browser/bookmarks/bookmark_drag_data.cc b/chrome/browser/bookmarks/bookmark_drag_data.cc index 2e7285a..73ac107 100644 --- a/chrome/browser/bookmarks/bookmark_drag_data.cc +++ b/chrome/browser/bookmarks/bookmark_drag_data.cc @@ -92,7 +92,8 @@ void BookmarkDragData::Write(Profile* profile, OSExchangeData* data) const { } Pickle data_pickle; - data_pickle.WriteWString(profile ? profile->GetPath() : std::wstring()); + data_pickle.WriteWString( + profile ? profile->GetPath().ToWStringHack() : std::wstring()); data_pickle.WriteSize(elements.size()); for (size_t i = 0; i < elements.size(); ++i) @@ -163,5 +164,6 @@ BookmarkNode* BookmarkDragData::GetFirstNode(Profile* profile) const { bool BookmarkDragData::IsFromProfile(Profile* profile) const { // An empty path means the data is not associated with any profile. - return (!profile_path_.empty() && profile->GetPath() == profile_path_); + return (!profile_path_.empty() && + profile->GetPath().ToWStringHack() == profile_path_); } diff --git a/chrome/browser/bookmarks/bookmark_model_unittest.cc b/chrome/browser/bookmarks/bookmark_model_unittest.cc index a78dec6..1ef384c 100644 --- a/chrome/browser/bookmarks/bookmark_model_unittest.cc +++ b/chrome/browser/bookmarks/bookmark_model_unittest.cc @@ -773,7 +773,7 @@ TEST_F(BookmarkModelTestWithProfile2, MigrateFromDBToFileTest) { PathService::Get(chrome::DIR_TEST_DATA, &old_history_path); file_util::AppendToPath(&old_history_path, L"bookmarks"); file_util::AppendToPath(&old_history_path, L"History_with_starred"); - std::wstring new_history_path = profile_->GetPath(); + std::wstring new_history_path = profile_->GetPath().ToWStringHack(); file_util::Delete(new_history_path, true); file_util::CreateDirectory(new_history_path); file_util::AppendToPath(&new_history_path, chrome::kHistoryFilename); diff --git a/chrome/browser/bookmarks/bookmark_storage.cc b/chrome/browser/bookmarks/bookmark_storage.cc index 23f47b4..a159e62 100644 --- a/chrome/browser/bookmarks/bookmark_storage.cc +++ b/chrome/browser/bookmarks/bookmark_storage.cc @@ -34,9 +34,9 @@ BookmarkStorage::BookmarkStorage(Profile* profile, BookmarkModel* model) : model_(model), ALLOW_THIS_IN_INITIALIZER_LIST(save_factory_(this)), backend_thread_(g_browser_process->file_thread()) { - std::wstring path = profile->GetPath(); + std::wstring path = profile->GetPath().ToWStringHack(); file_util::AppendToPath(&path, chrome::kBookmarksFileName); - std::wstring tmp_history_path = profile->GetPath(); + std::wstring tmp_history_path = profile->GetPath().ToWStringHack(); file_util::AppendToPath(&tmp_history_path, chrome::kHistoryBookmarksFileName); backend_ = new BookmarkStorageBackend(path, tmp_history_path); } diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index d685068..368d61d 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -10,6 +10,7 @@ #include "chrome/browser/browser_list.h" #include "chrome/browser/location_bar.h" #include "chrome/browser/metrics/user_metrics.h" +#include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents_type.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" @@ -47,7 +48,6 @@ #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/plugin_process_host.h" #include "chrome/browser/plugin_service.h" -#include "chrome/browser/profile.h" #include "chrome/browser/sessions/session_service.h" #include "chrome/browser/ssl/ssl_error_info.h" #include "chrome/browser/status_bubble.h" diff --git a/chrome/browser/browser_list.cc b/chrome/browser/browser_list.cc index 739dadb..de66406 100644 --- a/chrome/browser/browser_list.cc +++ b/chrome/browser/browser_list.cc @@ -12,10 +12,10 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_shutdown.h" #include "chrome/browser/browser_window.h" +#include "chrome/browser/profile_manager.h" #if defined(OS_WIN) // TODO(port): these can probably all go away, even on win #include "chrome/browser/profile.h" -#include "chrome/browser/profile_manager.h" #include "chrome/browser/tab_contents/web_contents.h" #include "chrome/common/notification_service.h" #endif diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 8431d5d..980ae97 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -22,6 +22,7 @@ #include "chrome/browser/browser_main_win.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/plugin_service.h" +#include "chrome/browser/profile_manager.h" #include "chrome/browser/shell_integration.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" @@ -215,7 +216,7 @@ int BrowserMain(const MainFunctionParams& parameters) { main_message_loop.set_thread_name(thread_name); bool already_running = Upgrade::IsBrowserAlreadyRunning(); - std::wstring user_data_dir; + FilePath user_data_dir; PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); MessageWindow message_window(user_data_dir); @@ -263,8 +264,7 @@ int BrowserMain(const MainFunctionParams& parameters) { // On first run, we need to process the master preferences before the // browser's profile_manager object is created. first_run_ui_bypass = - !FirstRun::ProcessMasterPreferences(user_data_dir, - std::wstring(), NULL); + !FirstRun::ProcessMasterPreferences(user_data_dir, FilePath(), NULL); // If we are running in App mode, we do not want to show the importer // (first run) UI. @@ -318,7 +318,8 @@ int BrowserMain(const MainFunctionParams& parameters) { Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); if (!profile) { #if defined(OS_WIN) - user_data_dir = UserDataDirDialog::RunUserDataDirDialog(user_data_dir); + user_data_dir = FilePath::FromWStringHack( + UserDataDirDialog::RunUserDataDirDialog(user_data_dir.ToWStringHack())); // Flush the message loop which lets the UserDataDirDialog close. MessageLoop::current()->Run(); @@ -331,7 +332,7 @@ int BrowserMain(const MainFunctionParams& parameters) { // sounds risky if we parse differently than CommandLineToArgvW. CommandLine new_command_line = parsed_command_line; new_command_line.AppendSwitchWithValue(switches::kUserDataDir, - user_data_dir); + user_data_dir.ToWStringHack()); base::LaunchApp(new_command_line, false, false, NULL); } diff --git a/chrome/browser/chrome_plugin_host.cc b/chrome/browser/chrome_plugin_host.cc index 5ea298e..0f97b7b 100644 --- a/chrome/browser/chrome_plugin_host.cc +++ b/chrome/browser/chrome_plugin_host.cc @@ -423,7 +423,7 @@ int STDCALL CPB_GetBrowsingContextInfo( PluginService* service = PluginService::GetInstance(); if (!service) return CPERR_FAILURE; - std::wstring wretval = service->GetChromePluginDataDir(); + std::wstring wretval = service->GetChromePluginDataDir().ToWStringHack(); file_util::AppendToPath(&wretval, chrome::kChromePluginDataDirname); *static_cast<char**>(buf) = CPB_StringDup(CPB_Alloc, WideToUTF8(wretval)); return CPERR_SUCCESS; diff --git a/chrome/browser/first_run.cc b/chrome/browser/first_run.cc index e1cabb2..0e333ef 100755 --- a/chrome/browser/first_run.cc +++ b/chrome/browser/first_run.cc @@ -83,15 +83,16 @@ bool GetBackupChromeFile(std::wstring* path) { std::wstring GetDefaultPrefFilePath(bool create_profile_dir, const std::wstring& user_data_dir) { - std::wstring default_pref_dir = - ProfileManager::GetDefaultProfileDir(user_data_dir); + FilePath default_pref_dir = ProfileManager::GetDefaultProfileDir( + FilePath::FromWStringHack(user_data_dir)); if (create_profile_dir) { if (!file_util::PathExists(default_pref_dir)) { if (!file_util::CreateDirectory(default_pref_dir)) return std::wstring(); } } - return ProfileManager::GetDefaultProfilePath(default_pref_dir); + return ProfileManager::GetDefaultProfilePath(default_pref_dir) + .ToWStringHack(); } bool InvokeGoogleUpdateForRename() { @@ -180,8 +181,8 @@ bool FirstRun::CreateSentinel() { } bool FirstRun::ProcessMasterPreferences( - const std::wstring& user_data_dir, - const std::wstring& master_prefs_path, + const FilePath& user_data_dir, + const FilePath& master_prefs_path, int* preference_details) { DCHECK(!user_data_dir.empty()); if (preference_details) @@ -196,7 +197,7 @@ bool FirstRun::ProcessMasterPreferences( file_util::AppendToPath(&master_path, installer_util::kDefaultMasterPrefs); master_prefs = master_path; } else { - master_prefs = master_prefs_path; + master_prefs = master_prefs_path.ToWStringHack(); } int parse_result = installer_util::ParseDistributionPreferences(master_prefs); @@ -218,13 +219,14 @@ bool FirstRun::ProcessMasterPreferences( } } - std::wstring user_prefs = GetDefaultPrefFilePath(true, user_data_dir); + FilePath user_prefs = FilePath::FromWStringHack( + GetDefaultPrefFilePath(true, user_data_dir.ToWStringHack())); if (user_prefs.empty()) return true; // The master prefs are regular prefs so we can just copy the file // to the default place and they just work. - if (!file_util::CopyFile(master_prefs, user_prefs)) + if (!file_util::CopyFile(master_prefs, user_prefs.ToWStringHack())) return true; if (!(parse_result & installer_util::MASTER_PROFILE_NO_FIRST_RUN_UI)) diff --git a/chrome/browser/first_run.h b/chrome/browser/first_run.h index 676bd49..f39e365 100644 --- a/chrome/browser/first_run.h +++ b/chrome/browser/first_run.h @@ -60,8 +60,8 @@ class FirstRun { // // See chrome/installer/util/master_preferences.h for a description of // 'master_preferences' file. - static bool ProcessMasterPreferences(const std::wstring& user_data_dir, - const std::wstring& master_prefs_path, + static bool ProcessMasterPreferences(const FilePath& user_data_dir, + const FilePath& master_prefs_path, int* preference_details); // Sets the kShouldShowFirstRunBubble local state pref so that the browser diff --git a/chrome/browser/history/history.cc b/chrome/browser/history/history.cc index 99838a1..6e55160 100644 --- a/chrome/browser/history/history.cc +++ b/chrome/browser/history/history.cc @@ -123,14 +123,15 @@ HistoryService::~HistoryService() { } } -bool HistoryService::Init(const std::wstring& history_dir, +bool HistoryService::Init(const FilePath& history_dir, BookmarkService* bookmark_service) { if (!thread_->Start()) return false; // Create the history backend. scoped_refptr<HistoryBackend> backend( - new HistoryBackend(history_dir, new BackendDelegate(this), + new HistoryBackend(history_dir.ToWStringHack(), + new BackendDelegate(this), bookmark_service)); history_backend_.swap(backend); diff --git a/chrome/browser/history/history.h b/chrome/browser/history/history.h index 0e5a492..b0351c9 100644 --- a/chrome/browser/history/history.h +++ b/chrome/browser/history/history.h @@ -27,6 +27,7 @@ class BookmarkService; struct DownloadCreateInfo; +class FilePath; class GURL; class HistoryURLProvider; struct HistoryURLProviderParams; @@ -100,7 +101,7 @@ class HistoryService : public CancelableRequestProvider, // not call any other functions. The given directory will be used for storing // the history files. The BookmarkService is used when deleting URLs to // test if a URL is bookmarked; it may be NULL during testing. - bool Init(const std::wstring& history_dir, BookmarkService* bookmark_service); + bool Init(const FilePath& history_dir, BookmarkService* bookmark_service); // Did the backend finish loading the databases? bool backend_loaded() const { return backend_loaded_; } diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc index fd7d465..670555b 100644 --- a/chrome/browser/history/history_backend.cc +++ b/chrome/browser/history/history_backend.cc @@ -471,7 +471,8 @@ void HistoryBackend::InitImpl() { // Compute the file names. Note that the index file can be removed when the // text db manager is finished being hooked up. std::wstring history_name = history_dir_; - file_util::AppendToPath(&history_name, chrome::kHistoryFilename); + file_util::AppendToPath(&history_name, + FilePath(chrome::kHistoryFilename).ToWStringHack()); std::wstring thumbnail_name = GetThumbnailFileName(); std::wstring archived_name = GetArchivedFileName(); std::wstring tmp_bookmarks_file = history_dir_; diff --git a/chrome/browser/history/history_querying_unittest.cc b/chrome/browser/history/history_querying_unittest.cc index 18cbf21..153ee5c1 100644 --- a/chrome/browser/history/history_querying_unittest.cc +++ b/chrome/browser/history/history_querying_unittest.cc @@ -89,7 +89,7 @@ class HistoryQueryTest : public testing::Test { file_util::CreateDirectory(history_dir_); history_ = new HistoryService; - if (!history_->Init(history_dir_, NULL)) { + if (!history_->Init(FilePath::FromWStringHack(history_dir_), NULL)) { history_ = NULL; // Tests should notice this NULL ptr & fail. return; } diff --git a/chrome/browser/history/history_unittest.cc b/chrome/browser/history/history_unittest.cc index 3018f25..6677145 100644 --- a/chrome/browser/history/history_unittest.cc +++ b/chrome/browser/history/history_unittest.cc @@ -378,7 +378,7 @@ TEST_F(HistoryTest, ClearBrowsingData_Downloads) { TEST_F(HistoryTest, AddPage) { scoped_refptr<HistoryService> history(new HistoryService); history_service_ = history; - ASSERT_TRUE(history->Init(history_dir_, NULL)); + ASSERT_TRUE(history->Init(FilePath::FromWStringHack(history_dir_), NULL)); // Add the page once from a child frame. const GURL test_url("http://www.google.com/"); @@ -402,7 +402,7 @@ TEST_F(HistoryTest, AddPage) { TEST_F(HistoryTest, AddPageSameTimes) { scoped_refptr<HistoryService> history(new HistoryService); history_service_ = history; - ASSERT_TRUE(history->Init(history_dir_, NULL)); + ASSERT_TRUE(history->Init(FilePath::FromWStringHack(history_dir_), NULL)); Time now = Time::Now(); const GURL test_urls[] = { @@ -442,7 +442,7 @@ TEST_F(HistoryTest, AddPageSameTimes) { TEST_F(HistoryTest, AddRedirect) { scoped_refptr<HistoryService> history(new HistoryService); history_service_ = history; - ASSERT_TRUE(history->Init(history_dir_, NULL)); + ASSERT_TRUE(history->Init(FilePath::FromWStringHack(history_dir_), NULL)); const wchar_t* first_sequence[] = { L"http://first.page/", @@ -513,7 +513,7 @@ TEST_F(HistoryTest, AddRedirect) { TEST_F(HistoryTest, Typed) { scoped_refptr<HistoryService> history(new HistoryService); history_service_ = history; - ASSERT_TRUE(history->Init(history_dir_, NULL)); + ASSERT_TRUE(history->Init(FilePath::FromWStringHack(history_dir_), NULL)); // Add the page once as typed. const GURL test_url("http://www.google.com/"); @@ -556,7 +556,7 @@ TEST_F(HistoryTest, Typed) { TEST_F(HistoryTest, SetTitle) { scoped_refptr<HistoryService> history(new HistoryService); history_service_ = history; - ASSERT_TRUE(history->Init(history_dir_, NULL)); + ASSERT_TRUE(history->Init(FilePath::FromWStringHack(history_dir_), NULL)); // Add a URL. const GURL existing_url(L"http://www.google.com/"); @@ -587,7 +587,7 @@ TEST_F(HistoryTest, Segments) { scoped_refptr<HistoryService> history(new HistoryService); history_service_ = history; - ASSERT_TRUE(history->Init(history_dir_, NULL)); + ASSERT_TRUE(history->Init(FilePath::FromWStringHack(history_dir_), NULL)); static const void* scope = static_cast<void*>(this); @@ -653,7 +653,7 @@ TEST_F(HistoryTest, Segments) { TEST_F(HistoryTest, Thumbnails) { scoped_refptr<HistoryService> history(new HistoryService); history_service_ = history; - ASSERT_TRUE(history->Init(history_dir_, NULL)); + ASSERT_TRUE(history->Init(FilePath::FromWStringHack(history_dir_), NULL)); scoped_ptr<SkBitmap> thumbnail( JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); @@ -803,7 +803,7 @@ class HistoryDBTaskImpl : public HistoryDBTask { TEST_F(HistoryTest, HistoryDBTask) { CancelableRequestConsumerT<int, 0> request_consumer; HistoryService* history = new HistoryService(); - ASSERT_TRUE(history->Init(history_dir_, NULL)); + ASSERT_TRUE(history->Init(FilePath::FromWStringHack(history_dir_), NULL)); scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl()); history_service_ = history; history->ScheduleDBTask(task.get(), &request_consumer); @@ -821,7 +821,7 @@ TEST_F(HistoryTest, HistoryDBTask) { TEST_F(HistoryTest, HistoryDBTaskCanceled) { CancelableRequestConsumerT<int, 0> request_consumer; HistoryService* history = new HistoryService(); - ASSERT_TRUE(history->Init(history_dir_, NULL)); + ASSERT_TRUE(history->Init(FilePath::FromWStringHack(history_dir_), NULL)); scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl()); history_service_ = history; history->ScheduleDBTask(task.get(), &request_consumer); diff --git a/chrome/browser/message_window.cc b/chrome/browser/message_window.cc index 13eb763..1def5a7 100644 --- a/chrome/browser/message_window.cc +++ b/chrome/browser/message_window.cc @@ -34,14 +34,14 @@ BOOL CALLBACK BrowserWindowEnumeration(HWND window, LPARAM param) { } // namespace -MessageWindow::MessageWindow(const std::wstring& user_data_dir) +MessageWindow::MessageWindow(const FilePath& user_data_dir) : window_(NULL), locked_(false) { // Look for a Chrome instance that uses the same profile directory: remote_window_ = FindWindowEx(HWND_MESSAGE, NULL, chrome::kMessageWindowClass, - user_data_dir.c_str()); + user_data_dir.ToWStringHack().c_str()); } MessageWindow::~MessageWindow() { @@ -199,7 +199,7 @@ LRESULT MessageWindow::OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds) { PrefService* prefs = g_browser_process->local_state(); DCHECK(prefs); - std::wstring user_data_dir; + FilePath user_data_dir; PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); ProfileManager* profile_manager = g_browser_process->profile_manager(); Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); diff --git a/chrome/browser/message_window.h b/chrome/browser/message_window.h index 1d0d732..632c82d 100644 --- a/chrome/browser/message_window.h +++ b/chrome/browser/message_window.h @@ -9,6 +9,7 @@ #include <windows.h> #include "base/basictypes.h" +#include "base/file_path.h" // MessageWindow ------------------------------------------------------------- // @@ -20,7 +21,7 @@ class MessageWindow { public: - explicit MessageWindow(const std::wstring& user_data_dir); + explicit MessageWindow(const FilePath& user_data_dir); ~MessageWindow(); // Returns true if another process was found and notified, false if we diff --git a/chrome/browser/navigation_controller_unittest.cc b/chrome/browser/navigation_controller_unittest.cc index 09c93e6..1019d80 100644 --- a/chrome/browser/navigation_controller_unittest.cc +++ b/chrome/browser/navigation_controller_unittest.cc @@ -147,7 +147,8 @@ class NavigationControllerHistoryTest : public NavigationControllerTest { // Create a profile. profile_manager_ = new ProfileManager(); - profile = ProfileManager::CreateProfile(profile_path_, + profile = ProfileManager::CreateProfile( + FilePath::FromWStringHack(profile_path_), L"New Profile", L"new-profile", L""); ASSERT_TRUE(profile); profile_manager_->AddProfile(profile); @@ -189,8 +190,10 @@ class NavigationControllerHistoryTest : public NavigationControllerTest { helper_.set_service(NULL); delete profile_manager_; profile_manager_ = new ProfileManager(); - profile_manager_->AddProfileByPath(profile_path_); - profile = profile_manager_->GetProfileByPath(profile_path_); + profile_manager_->AddProfileByPath( + FilePath::FromWStringHack(profile_path_)); + profile = profile_manager_->GetProfileByPath( + FilePath::FromWStringHack(profile_path_)); helper_.set_service(profile->GetSessionService()); } diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index 5cd4688..7a4c3bb 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -37,8 +37,8 @@ static net::ProxyInfo* CreateProxyInfo() { // static ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal( - Profile* profile, const std::wstring& cookie_store_path, - const std::wstring& disk_cache_path) { + Profile* profile, const FilePath& cookie_store_path, + const FilePath& disk_cache_path) { DCHECK(!profile->IsOffTheRecord()); ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); @@ -46,7 +46,8 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal( context->proxy_service_ = net::ProxyService::Create(proxy_info.get()); net::HttpCache* cache = - new net::HttpCache(context->proxy_service_, disk_cache_path, 0); + new net::HttpCache(context->proxy_service_, + disk_cache_path.ToWStringHack(), 0); const CommandLine& command_line = *CommandLine::ForCurrentProcess(); bool record_mode = chrome::kRecordModeEnabled && @@ -65,7 +66,8 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal( if (!context->cookie_store_) { DCHECK(!cookie_store_path.empty()); context->cookie_db_.reset(new SQLitePersistentCookieStore( - cookie_store_path, g_browser_process->db_thread()->message_loop())); + cookie_store_path.ToWStringHack(), + g_browser_process->db_thread()->message_loop())); context->cookie_store_ = new net::CookieMonster(context->cookie_db_.get()); } diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index 915322e..f9cfafac 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -25,8 +25,8 @@ class ChromeURLRequestContext : public URLRequestContext, // Create an instance for use with an 'original' (non-OTR) profile. This is // expected to get called on the UI thread. static ChromeURLRequestContext* CreateOriginal( - Profile* profile, const std::wstring& cookie_store_path, - const std::wstring& disk_cache_path); + Profile* profile, const FilePath& cookie_store_path, + const FilePath& disk_cache_path); // Create an instance for use with an OTR profile. This is expected to get // called on the UI thread. diff --git a/chrome/browser/plugin_process_host.cc b/chrome/browser/plugin_process_host.cc index 7c272a5..0254f95 100644 --- a/chrome/browser/plugin_process_host.cc +++ b/chrome/browser/plugin_process_host.cc @@ -513,7 +513,8 @@ bool PluginProcessHost::Init(const FilePath& plugin_path, } // Gears requires the data dir to be available on startup. - std::wstring data_dir = plugin_service_->GetChromePluginDataDir();; + std::wstring data_dir = + plugin_service_->GetChromePluginDataDir().ToWStringHack(); DCHECK(!data_dir.empty()); cmd_line.AppendSwitchWithValue(switches::kPluginDataDir, data_dir); diff --git a/chrome/browser/plugin_service.cc b/chrome/browser/plugin_service.cc index f31dc68..032842c 100644 --- a/chrome/browser/plugin_service.cc +++ b/chrome/browser/plugin_service.cc @@ -45,12 +45,12 @@ void PluginService::LoadChromePlugins( ChromePluginLib::LoadChromePlugins(GetCPBrowserFuncsForBrowser()); } -void PluginService::SetChromePluginDataDir(const std::wstring& data_dir) { +void PluginService::SetChromePluginDataDir(const FilePath& data_dir) { AutoLock lock(lock_); chrome_plugin_data_dir_ = data_dir; } -const std::wstring& PluginService::GetChromePluginDataDir() { +const FilePath& PluginService::GetChromePluginDataDir() { AutoLock lock(lock_); return chrome_plugin_data_dir_; } diff --git a/chrome/browser/plugin_service.h b/chrome/browser/plugin_service.h index 2ee90b7..3bca25f 100644 --- a/chrome/browser/plugin_service.h +++ b/chrome/browser/plugin_service.h @@ -48,8 +48,8 @@ class PluginService { // Sets/gets the data directory that Chrome plugins should use to store // persistent data. - void SetChromePluginDataDir(const std::wstring& data_dir); - const std::wstring& GetChromePluginDataDir(); + void SetChromePluginDataDir(const FilePath& data_dir); + const FilePath& GetChromePluginDataDir(); // Gets the browser's UI locale. const std::wstring& GetUILocale(); @@ -131,7 +131,7 @@ class PluginService { ResourceDispatcherHost* resource_dispatcher_host_; // The data directory that Chrome plugins should use to store persistent data. - std::wstring chrome_plugin_data_dir_; + FilePath chrome_plugin_data_dir_; // The browser's UI locale. const std::wstring ui_locale_; diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index 5af89c9..b4fd605 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -13,22 +13,13 @@ #include "base/string_util.h" #include "base/values.h" #include "chrome/app/locales/locale_settings.h" -#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/download/download_manager.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/extensions/user_script_master.h" -#include "chrome/browser/history/history.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/profile_manager.h" #include "chrome/browser/renderer_host/render_process_host.h" -#include "chrome/browser/search_engines/template_url_fetcher.h" -#include "chrome/browser/search_engines/template_url_model.h" -#include "chrome/browser/sessions/session_service.h" -#include "chrome/browser/sessions/tab_restore_service.h" -#include "chrome/browser/spellchecker.h" -#include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/visitedlink_master.h" #include "chrome/browser/webdata/web_data_service.h" #include "chrome/common/chrome_constants.h" @@ -38,6 +29,7 @@ #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" +#include "chrome/common/render_messages.h" #include "chrome/common/resource_bundle.h" #include "net/base/cookie_monster.h" #include "net/base/cookie_policy.h" @@ -46,6 +38,25 @@ #include "net/url_request/url_request_context.h" #include "webkit/glue/webkit_glue.h" +#if defined(OS_POSIX) +// TODO(port): get rid of this include. It's used just to provide declarations +// and stub definitions for classes we encouter during the porting effort. +#include "chrome/common/temp_scaffolding_stubs.h" +#endif + +// TODO(port): Get rid of this section and finish porting. +#if defined(OS_WIN) +#include "chrome/browser/bookmarks/bookmark_model.h" +#include "chrome/browser/download/download_manager.h" +#include "chrome/browser/history/history.h" +#include "chrome/browser/search_engines/template_url_fetcher.h" +#include "chrome/browser/search_engines/template_url_model.h" +#include "chrome/browser/sessions/session_service.h" +#include "chrome/browser/sessions/tab_restore_service.h" +#include "chrome/browser/spellchecker.h" +#include "chrome/browser/tab_contents/navigation_controller.h" +#endif + using base::Time; using base::TimeDelta; @@ -61,13 +72,20 @@ void Profile::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true); prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true); prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true); +#if defined(OS_MACOSX) + // MASSIVE HACK!!! We don't have localization working yet. Undo this once we + // do. TODO(port): take this out + prefs->RegisterStringPref(prefs::kSpellCheckDictionary, + L"IDS_SPELLCHECK_DICTIONARY"); +#elif defined(OS_WIN) || defined(OS_LINUX) prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary, IDS_SPELLCHECK_DICTIONARY); +#endif prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true); } //static -Profile* Profile::CreateProfile(const std::wstring& path) { +Profile* Profile::CreateProfile(const FilePath& path) { return new ProfileImpl(path); } @@ -112,7 +130,7 @@ class OffTheRecordProfileImpl : public Profile, this, NOTIFY_BROWSER_CLOSED, NotificationService::AllSources()); } - virtual std::wstring GetPath() { return profile_->GetPath(); } + virtual FilePath GetPath() { return profile_->GetPath(); } virtual bool IsOffTheRecord() { return true; @@ -298,18 +316,18 @@ class OffTheRecordProfileImpl : public Profile, DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordProfileImpl); }; -ProfileImpl::ProfileImpl(const std::wstring& path) +ProfileImpl::ProfileImpl(const FilePath& path) : path_(path), off_the_record_(false), +#ifdef CHROME_PERSONALIZATION + personalization_(NULL), +#endif + request_context_(NULL), history_service_created_(false), created_web_data_service_(false), created_download_manager_(false), - request_context_(NULL), start_time_(Time::Now()), spellchecker_(NULL), -#ifdef CHROME_PERSONALIZATION - personalization_(NULL), -#endif shutdown_session_service_(false) { DCHECK(!path.empty()) << "Using an empty path will attempt to write " << "profile files to the root directory!"; @@ -329,14 +347,14 @@ void ProfileImpl::InitExtensions() { bool extensions_enabled = command_line->HasSwitch(switches::kEnableExtensions); - std::wstring script_dir; + FilePath script_dir; if (user_scripts_enabled) { script_dir = GetPath(); - file_util::AppendToPath(&script_dir, chrome::kUserScriptsDirname); + script_dir = script_dir.Append(chrome::kUserScriptsDirname); } user_script_master_ = new UserScriptMaster( - g_browser_process->file_thread()->message_loop(), FilePath(script_dir)); + g_browser_process->file_thread()->message_loop(), script_dir); extensions_service_ = new ExtensionsService( FilePath(GetPath()), user_script_master_.get()); @@ -418,7 +436,7 @@ ProfileImpl::~ProfileImpl() { MarkAsCleanShutdown(); } -std::wstring ProfileImpl::GetPath() { +FilePath ProfileImpl::GetPath() { return path_; } @@ -449,10 +467,10 @@ static void BroadcastNewHistoryTable(base::SharedMemory* table_memory) { continue; base::SharedMemoryHandle new_table; - HANDLE process = i->second->process().handle(); + base::ProcessHandle process = i->second->process().handle(); if (!process) { // process can be null if it's started with the --single-process flag. - process = GetCurrentProcess(); + process = base::Process::Current().handle(); } table_memory->ShareToProcess(process, &new_table); @@ -484,7 +502,7 @@ UserScriptMaster* ProfileImpl::GetUserScriptMaster() { PrefService* ProfileImpl::GetPrefs() { if (!prefs_.get()) { - prefs_.reset(new PrefService(GetPrefFilePath())); + prefs_.reset(new PrefService(GetPrefFilePath().ToWStringHack())); // The Profile class and ProfileManager class may read some prefs so // register known prefs as soon as possible. @@ -504,18 +522,18 @@ PrefService* ProfileImpl::GetPrefs() { return prefs_.get(); } -std::wstring ProfileImpl::GetPrefFilePath() { - std::wstring pref_file_path = path_; - file_util::AppendToPath(&pref_file_path, chrome::kPreferencesFilename); +FilePath ProfileImpl::GetPrefFilePath() { + FilePath pref_file_path = path_; + pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename); return pref_file_path; } URLRequestContext* ProfileImpl::GetRequestContext() { if (!request_context_) { - std::wstring cookie_path = GetPath(); - file_util::AppendToPath(&cookie_path, chrome::kCookieFilename); - std::wstring cache_path = GetPath(); - file_util::AppendToPath(&cache_path, chrome::kCacheDirname); + FilePath cookie_path = GetPath(); + cookie_path = cookie_path.Append(chrome::kCookieFilename); + FilePath cache_path = GetPath(); + cache_path = cache_path.Append(chrome::kCacheDirname); request_context_ = ChromeURLRequestContext::CreateOriginal( this, cookie_path, cache_path); request_context_->AddRef(); diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h index 2ef3eff..7189577 100644 --- a/chrome/browser/profile.h +++ b/chrome/browser/profile.h @@ -11,6 +11,7 @@ #include <string> #include "base/basictypes.h" +#include "base/file_path.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "base/task.h" @@ -44,7 +45,7 @@ class Profile { // Profile services are accessed with the following parameter. This parameter // defines what the caller plans to do with the service. - // The caller is responsible for not performing any operation that would + // The caller is responsible for not performing any operation that would // result in persistent implicit records while using an OffTheRecord profile. // This flag allows the profile to perform an additional check. // @@ -74,7 +75,7 @@ class Profile { static void RegisterUserPrefs(PrefService* prefs); // Create a new profile given a path. - static Profile* CreateProfile(const std::wstring& path); + static Profile* CreateProfile(const FilePath& path); // Returns the request context for the "default" profile. This may be called // from any thread. This CAN return NULL if a first request context has not @@ -86,7 +87,7 @@ class Profile { static URLRequestContext* GetDefaultRequestContext(); // Returns the path of the directory where this profile's data is stored. - virtual std::wstring GetPath() = 0; + virtual FilePath GetPath() = 0; // Return whether this profile is off the record. Default is false. virtual bool IsOffTheRecord() = 0; @@ -117,6 +118,7 @@ class Profile { // Retrieves a pointer to the HistoryService associated with this // profile. The HistoryService is lazily created the first time // that this method is called. + // // Although HistoryService is refcounted, this will not addref, and callers // do not need to do any reference counting as long as they keep the pointer // only for the local scope (which they should do anyway since the browser @@ -258,7 +260,7 @@ class ProfileImpl : public Profile, virtual ~ProfileImpl(); // Profile implementation. - virtual std::wstring GetPath(); + virtual FilePath GetPath(); virtual bool IsOffTheRecord(); virtual Profile* GetOffTheRecordProfile(); virtual Profile* GetOriginalProfile(); @@ -301,10 +303,10 @@ class ProfileImpl : public Profile, private: friend class Profile; - explicit ProfileImpl(const std::wstring& path); + explicit ProfileImpl(const FilePath& path); void CreateWebDataService(); - std::wstring GetPrefFilePath(); + FilePath GetPrefFilePath(); void StopCreateSessionServiceTimer(); @@ -321,7 +323,7 @@ class ProfileImpl : public Profile, // spellchecker to the resource message filters. void InitializeSpellChecker(bool need_to_broadcast); - std::wstring path_; + FilePath path_; bool off_the_record_; scoped_ptr<VisitedLinkMaster> visited_link_master_; scoped_refptr<ExtensionsService> extensions_service_; diff --git a/chrome/browser/profile_manager.cc b/chrome/browser/profile_manager.cc index 6a2c139..7698f62 100644 --- a/chrome/browser/profile_manager.cc +++ b/chrome/browser/profile_manager.cc @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <windows.h> - #include <set> #include "chrome/browser/profile_manager.h" @@ -14,7 +12,6 @@ #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/chrome_thread.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" @@ -22,11 +19,18 @@ #include "chrome/common/logging_chrome.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" +#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_job.h" #include "net/url_request/url_request_job_tracker.h" #include "generated_resources.h" +#if defined(OS_POSIX) +// TODO(port): get rid of this include. It's used just to provide declarations +// and stub definitions for classes we encouter during the porting effort. +#include "chrome/common/temp_scaffolding_stubs.h" +#endif + // static void ProfileManager::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterStringPref(prefs::kProfileName, L""); @@ -68,23 +72,24 @@ ProfileManager::~ProfileManager() { available_profiles_.clear(); } -std::wstring ProfileManager::GetDefaultProfileDir( - const std::wstring& user_data_dir) { - std::wstring default_profile_dir(user_data_dir); - file_util::AppendToPath(&default_profile_dir, chrome::kNotSignedInProfile); +FilePath ProfileManager::GetDefaultProfileDir( + const FilePath& user_data_dir) { + FilePath default_profile_dir(user_data_dir); + default_profile_dir = default_profile_dir.Append( + FilePath::FromWStringHack(chrome::kNotSignedInProfile)); return default_profile_dir; } -std::wstring ProfileManager::GetDefaultProfilePath( - const std::wstring &profile_dir) { - std::wstring default_prefs_path(profile_dir); - file_util::AppendToPath(&default_prefs_path, chrome::kPreferencesFilename); +FilePath ProfileManager::GetDefaultProfilePath( + const FilePath &profile_dir) { + FilePath default_prefs_path(profile_dir); + default_prefs_path = default_prefs_path.Append(chrome::kPreferencesFilename); return default_prefs_path; } -Profile* ProfileManager::GetDefaultProfile(const std::wstring& user_data_dir) { +Profile* ProfileManager::GetDefaultProfile(const FilePath& user_data_dir) { // Initialize profile, creating default if necessary - std::wstring default_profile_dir = GetDefaultProfileDir(user_data_dir); + FilePath default_profile_dir = GetDefaultProfileDir(user_data_dir); // If the profile is already loaded (e.g., chrome.exe launched twice), just // return it. Profile* profile = GetProfileByPath(default_profile_dir); @@ -118,7 +123,7 @@ Profile* ProfileManager::GetDefaultProfile(const std::wstring& user_data_dir) { return profile; } -Profile* ProfileManager::AddProfileByPath(const std::wstring& path) { +Profile* ProfileManager::AddProfileByPath(const FilePath& path) { Profile* profile = GetProfileByPath(path); if (profile) return profile; @@ -143,9 +148,9 @@ Profile* ProfileManager::AddProfileByID(const std::wstring& id) { if (!available) return NULL; - std::wstring path; + FilePath path; PathService::Get(chrome::DIR_USER_DATA, &path); - file_util::AppendToPath(&path, available->directory()); + path = path.Append(available->directory()); return AddProfileByPath(path); } @@ -169,7 +174,8 @@ bool ProfileManager::AddProfile(Profile* profile) { // that's already loaded. if (GetProfileByPath(profile->GetPath())) { NOTREACHED() << "Attempted to add profile with the same path (" << - profile->GetPath() << ") as an already-loaded profile."; + profile->GetPath().value() << + ") as an already-loaded profile."; return false; } if (GetProfileByID(profile->GetID())) { @@ -192,7 +198,7 @@ void ProfileManager::RemoveProfile(Profile* profile) { } } -void ProfileManager::RemoveProfileByPath(const std::wstring& path) { +void ProfileManager::RemoveProfileByPath(const FilePath& path) { for (ProfileVector::iterator iter = profiles_.begin(); iter != profiles_.end(); ++iter) { if ((*iter)->GetPath() == path) { @@ -202,10 +208,10 @@ void ProfileManager::RemoveProfileByPath(const std::wstring& path) { } } - NOTREACHED() << "Attempted to remove non-loaded profile: " << path; + NOTREACHED() << "Attempted to remove non-loaded profile: " << path.value(); } -Profile* ProfileManager::GetProfileByPath(const std::wstring& path) const { +Profile* ProfileManager::GetProfileByPath(const FilePath& path) const { for (ProfileVector::const_iterator iter = profiles_.begin(); iter != profiles_.end(); ++iter) { if ((*iter)->GetPath() == path) @@ -268,66 +274,43 @@ void ProfileManager::ResumeProfile(Profile* profile) { // static -bool ProfileManager::IsProfile(const std::wstring& path) { - std::wstring prefs_path = GetDefaultProfilePath(path); +bool ProfileManager::IsProfile(const FilePath& path) { + FilePath prefs_path = GetDefaultProfilePath(path); - std::wstring history_path = path; - file_util::AppendToPath(&history_path, chrome::kHistoryFilename); + FilePath history_path = path; + history_path = history_path.Append(chrome::kHistoryFilename); return file_util::PathExists(prefs_path) && file_util::PathExists(history_path); } // static -bool ProfileManager::CopyProfileData(const std::wstring& source_path, - const std::wstring& destination_path) { +bool ProfileManager::CopyProfileData(const FilePath& source_path, + const FilePath& destination_path) { // create destination directory if necessary if (!file_util::PathExists(destination_path)) { - bool result = !!CreateDirectory(destination_path.c_str(), NULL); + bool result = file_util::CreateDirectory(destination_path); if (!result) { DLOG(WARNING) << "Unable to create destination directory " << - destination_path; + destination_path.value(); return false; } } // copy files in directory - WIN32_FIND_DATA find_file_data; - std::wstring filename_spec = source_path; - file_util::AppendToPath(&filename_spec, L"*"); - HANDLE find_handle = FindFirstFile(filename_spec.c_str(), &find_file_data); - if (find_handle != INVALID_HANDLE_VALUE) { - do { - // skip directories - if (find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - continue; - - std::wstring source_file = source_path; - file_util::AppendToPath(&source_file, find_file_data.cFileName); - std::wstring dest_file = destination_path; - file_util::AppendToPath(&dest_file, find_file_data.cFileName); - bool result = !!CopyFileW(source_file.c_str(), - dest_file.c_str(), - FALSE /* overwrite */); - if (!result) - return false; - } while (FindNextFile(find_handle, &find_file_data)); - FindClose(find_handle); - } - - return true; + return file_util::CopyDirectory(source_path, destination_path, false); } // static -Profile* ProfileManager::CreateProfile(const std::wstring& path, +Profile* ProfileManager::CreateProfile(const FilePath& path, const std::wstring& name, const std::wstring& nickname, const std::wstring& id) { DCHECK_LE(nickname.length(), name.length()); if (IsProfile(path)) { - DCHECK(false) << "Attempted to create a profile with the path:\n" << path - << "\n but that path already contains a profile"; + DCHECK(false) << "Attempted to create a profile with the path:\n" + << path.value() << "\n but that path already contains a profile"; } if (!file_util::PathExists(path)) { diff --git a/chrome/browser/profile_manager.h b/chrome/browser/profile_manager.h index 72f1d63..3735492 100644 --- a/chrome/browser/profile_manager.h +++ b/chrome/browser/profile_manager.h @@ -12,6 +12,7 @@ #include <vector> #include "base/basictypes.h" +#include "base/file_path.h" #include "base/message_loop.h" #include "base/non_thread_safe.h" #include "base/system_monitor.h" @@ -26,17 +27,18 @@ class AvailableProfile { public: AvailableProfile(const std::wstring& name, const std::wstring& id, - const std::wstring& directory) + const FilePath& directory) : name_(name), id_(id), directory_(directory) {} // Decodes a DictionaryValue into an AvailableProfile static AvailableProfile* FromValue(DictionaryValue* value) { DCHECK(value); - std::wstring name, id, directory; + std::wstring name, id; + FilePath::StringType directory; value->GetString(L"name", &name); value->GetString(L"id", &id); value->GetString(L"directory", &directory); - return new AvailableProfile(name, id, directory); + return new AvailableProfile(name, id, FilePath(directory)); } // Encodes this AvailableProfile into a new DictionaryValue @@ -44,18 +46,18 @@ class AvailableProfile { DictionaryValue* value = new DictionaryValue; value->SetString(L"name", name_); value->SetString(L"id", id_); - value->SetString(L"directory", directory_); + value->SetString(L"directory", directory_.value()); return value; } std::wstring name() const { return name_; } std::wstring id() const { return id_; } - std::wstring directory() const { return directory_; } + FilePath directory() const { return directory_; } private: - std::wstring name_; // User-visible profile name - std::wstring id_; // Profile identifier - std::wstring directory_; // Subdirectory containing profile (not full path) + std::wstring name_; // User-visible profile name + std::wstring id_; // Profile identifier + FilePath directory_; // Subdirectory containing profile (not full path) DISALLOW_EVIL_CONSTRUCTORS(AvailableProfile); }; @@ -75,12 +77,12 @@ class ProfileManager : public NonThreadSafe, // Returns the default profile. This adds the profile to the // ProfileManager if it doesn't already exist. This method returns NULL if // the profile doesn't exist and we can't create it. - Profile* GetDefaultProfile(const std::wstring& user_data_dir); + Profile* GetDefaultProfile(const FilePath& user_data_dir); // If a profile with the given path is currently managed by this object, // return a pointer to the corresponding Profile object; // otherwise return NULL. - Profile* GetProfileByPath(const std::wstring& path) const; + Profile* GetProfileByPath(const FilePath& path) const; // If a profile with the given ID is currently managed by this object, // return a pointer to the corresponding Profile object; @@ -89,7 +91,7 @@ class ProfileManager : public NonThreadSafe, // Adds a profile to the set of currently-loaded profiles. Returns a // pointer to a Profile object corresponding to the given path. - Profile* AddProfileByPath(const std::wstring& path); + Profile* AddProfileByPath(const FilePath& path); // Adds a profile to the set of currently-loaded profiles. Returns a // pointer to a Profile object corresponding to the given profile ID. @@ -104,7 +106,7 @@ class ProfileManager : public NonThreadSafe, // Removes a profile from the set of currently-loaded profiles. The path must // be exactly the same (including case) as when GetProfileByPath was called. - void RemoveProfileByPath(const std::wstring& path); + void RemoveProfileByPath(const FilePath& path); // Removes a profile from the set of currently-loaded profiles. // (Does not delete the profile object.) @@ -134,26 +136,26 @@ class ProfileManager : public NonThreadSafe, // ------------------ static utility functions ------------------- // Returns the path to the profile directory based on the user data directory. - static std::wstring GetDefaultProfileDir(const std::wstring& user_data_dir); + static FilePath GetDefaultProfileDir(const FilePath& user_data_dir); // Returns the path to the profile given the user profile directory. - static std::wstring GetDefaultProfilePath(const std::wstring& profile_dir); + static FilePath GetDefaultProfilePath(const FilePath& profile_dir); // Tries to determine whether the given path represents a profile // directory, and returns true if it thinks it does. - static bool IsProfile(const std::wstring& path); + static bool IsProfile(const FilePath& path); // Tries to copy profile data from the source path to the destination path, // returning true if successful. - static bool CopyProfileData(const std::wstring& source_path, - const std::wstring& destination_path); + static bool CopyProfileData(const FilePath& source_path, + const FilePath& destination_path); // Creates a new profile at the specified path with the given name and ID. // |name| is the full-length human-readable name for the profile // |nickname| is a shorter name for the profile--can be empty string // This method should always return a valid Profile (i.e., should never // return NULL). - static Profile* CreateProfile(const std::wstring& path, + static Profile* CreateProfile(const FilePath& path, const std::wstring& name, const std::wstring& nickname, const std::wstring& id); diff --git a/chrome/browser/profile_manager_unittest.cc b/chrome/browser/profile_manager_unittest.cc index 8a7ed05..be505d0 100644 --- a/chrome/browser/profile_manager_unittest.cc +++ b/chrome/browser/profile_manager_unittest.cc @@ -12,18 +12,16 @@ #include "chrome/common/pref_service.h" #include "testing/gtest/include/gtest/gtest.h" -namespace { - class ProfileManagerTest : public testing::Test { protected: virtual void SetUp() { // Name a subdirectory of the temp directory. ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_)); - file_util::AppendToPath(&test_dir_, L"ProfileManagerTest"); + test_dir_ = test_dir_.Append(FILE_PATH_LITERAL("ProfileManagerTest")); // Create a fresh, empty copy of this directory. file_util::Delete(test_dir_, true); - CreateDirectory(test_dir_.c_str(), NULL); + file_util::CreateDirectory(test_dir_); } virtual void TearDown() { // Clean up test directory @@ -34,35 +32,33 @@ protected: MessageLoopForUI message_loop_; // the path to temporary directory used to contain the test operations - std::wstring test_dir_; -}; - + FilePath test_dir_; }; TEST_F(ProfileManagerTest, CopyProfileData) { - std::wstring source_path; + FilePath source_path; PathService::Get(chrome::DIR_TEST_DATA, &source_path); - file_util::AppendToPath(&source_path, L"profiles"); + source_path = source_path.Append(FILE_PATH_LITERAL("profiles")); ASSERT_FALSE(ProfileManager::IsProfile(source_path)); - file_util::AppendToPath(&source_path, L"sample"); + source_path = source_path.Append(FILE_PATH_LITERAL("sample")); ASSERT_TRUE(ProfileManager::IsProfile(source_path)); - std::wstring dest_path = test_dir_; - file_util::AppendToPath(&dest_path, L"profile_copy"); + FilePath dest_path = test_dir_; + dest_path = dest_path.Append(FILE_PATH_LITERAL("profile_copy")); ASSERT_FALSE(ProfileManager::IsProfile(dest_path)); ASSERT_TRUE(ProfileManager::CopyProfileData(source_path, dest_path)); ASSERT_TRUE(ProfileManager::IsProfile(dest_path)); } TEST_F(ProfileManagerTest, CreateProfile) { - std::wstring source_path; + FilePath source_path; PathService::Get(chrome::DIR_TEST_DATA, &source_path); - file_util::AppendToPath(&source_path, L"profiles"); - file_util::AppendToPath(&source_path, L"sample"); + source_path = source_path.Append(FILE_PATH_LITERAL("profiles")); + source_path = source_path.Append(FILE_PATH_LITERAL("sample")); - std::wstring dest_path = test_dir_; - file_util::AppendToPath(&dest_path, L"New Profile"); + FilePath dest_path = test_dir_; + dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); scoped_ptr<Profile> profile; diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc index 1e1db05..b208e89 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.cc +++ b/chrome/browser/renderer_host/browser_render_process_host.cc @@ -27,22 +27,11 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/cache_manager_host.h" #include "chrome/browser/extensions/user_script_master.h" -#if defined(OS_WIN) -#include "chrome/browser/history/history.h" -#else -// TODO(port): remove scaffolding, use history.h for both POSIX and WIN. -#include "chrome/common/temp_scaffolding_stubs.h" -#endif // !defined(OS_WIN) - #include "chrome/browser/plugin_service.h" +#include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_widget_helper.h" #include "chrome/browser/renderer_host/renderer_security_policy.h" #include "chrome/browser/resource_message_filter.h" -#if defined(OS_MACOSX) -// TODO(port): Enable when we finish porting spellchecker to os x. -#else -#include "chrome/browser/spellchecker.h" -#endif // !defined(OS_WIN) #include "chrome/browser/visitedlink_master.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" @@ -60,6 +49,9 @@ // TODO(port): see comment by the only usage of RenderViewHost in this file. #include "chrome/browser/renderer_host/render_view_host.h" +#include "chrome/browser/history/history.h" +#include "chrome/browser/spellchecker.h" + // Once the above TODO is finished, then this block is all Windows-specific // files. #include "base/win_util.h" @@ -479,9 +471,9 @@ void BrowserRenderProcessHost::WidgetHidden() { } void BrowserRenderProcessHost::AddWord(const std::wstring& word) { -#if defined(OS_MACOSX) +#if !defined(OS_WIN) // TODO(port): reimplement when we get the spell checker up and running on - // OS X. + // other platforms. NOTIMPLEMENTED(); #else base::Thread* io_thread = g_browser_process->io_thread(); @@ -489,7 +481,7 @@ void BrowserRenderProcessHost::AddWord(const std::wstring& word) { io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( profile()->GetSpellChecker(), &SpellChecker::AddWord, word)); } -#endif // !defined(OS_MACOSX) +#endif // !defined(OS_WIN) } base::ProcessHandle BrowserRenderProcessHost::GetRendererProcessHandle() { diff --git a/chrome/browser/resource_message_filter.cc b/chrome/browser/resource_message_filter.cc index 753590c..63ea64d 100644 --- a/chrome/browser/resource_message_filter.cc +++ b/chrome/browser/resource_message_filter.cc @@ -325,7 +325,7 @@ void ResourceMessageFilter::OnGetCookies(const GURL& url, } void ResourceMessageFilter::OnGetDataDir(std::wstring* data_dir) { - *data_dir = plugin_service_->GetChromePluginDataDir(); + *data_dir = plugin_service_->GetChromePluginDataDir().ToWStringHack(); } void ResourceMessageFilter::OnPluginMessage(const FilePath& plugin_path, diff --git a/chrome/browser/rlz/rlz.cc b/chrome/browser/rlz/rlz.cc index 33e9b59..5cd0a15 100644 --- a/chrome/browser/rlz/rlz.cc +++ b/chrome/browser/rlz/rlz.cc @@ -266,7 +266,8 @@ class DelayedInitTask : public Task { if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) return false; ProfileManager* profile_manager = g_browser_process->profile_manager(); - Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); + Profile* profile = profile_manager-> + GetDefaultProfile(FilePath::FromWStringHack(user_data_dir)); if (!profile) return false; const TemplateURL* url_template = diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc index 57d4697..b524f22 100644 --- a/chrome/browser/safe_browsing/safe_browsing_service.cc +++ b/chrome/browser/safe_browsing/safe_browsing_service.cc @@ -58,8 +58,7 @@ void SafeBrowsingService::Initialize(MessageLoop* io_loop) { FilePath user_data_dir; PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); ProfileManager* profile_manager = g_browser_process->profile_manager(); - Profile* profile = profile_manager->GetDefaultProfile( - user_data_dir.ToWStringHack()); + Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); PrefService* pref_service = profile->GetPrefs(); if (pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)) Start(); diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc index 27bfe1d..9c2959a5 100644 --- a/chrome/browser/search_engines/template_url.cc +++ b/chrome/browser/search_engines/template_url.cc @@ -9,11 +9,21 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/rlz/rlz.h" #include "chrome/browser/google_url_tracker.h" -#include "chrome/browser/search_engines/template_url_model.h" #include "chrome/common/gfx/favicon_size.h" #include "chrome/common/l10n_util.h" #include "net/base/escape.h" +#if defined(OS_POSIX) +// TODO(port): get rid of this include. It's used just to provide declarations +// and stub definitions for classes we encouter during the porting effort. +#include "chrome/common/temp_scaffolding_stubs.h" +#endif + +// TODO(port): Get rid of this section and finish porting. +#if defined(OS_WIN) +#include "chrome/browser/search_engines/template_url_model.h" +#endif + // The TemplateURLRef has any number of terms that need to be replaced. Each of // the terms is enclosed in braces. If the character preceeding the final // brace is a ?, it indicates the term is optional and can be replaced with diff --git a/chrome/browser/search_engines/template_url_model_unittest.cc b/chrome/browser/search_engines/template_url_model_unittest.cc index 9bad770..c633a19 100644 --- a/chrome/browser/search_engines/template_url_model_unittest.cc +++ b/chrome/browser/search_engines/template_url_model_unittest.cc @@ -49,7 +49,7 @@ class TemplateURLModelTestingProfile : public TestingProfile { std::wstring path = test_dir_; file_util::AppendToPath(&path, L"TestDataService.db"); service_ = new WebDataService; - EXPECT_TRUE(service_->InitWithPath(path)); + EXPECT_TRUE(service_->InitWithPath(FilePath::FromWStringHack(path))); } void TearDown() { diff --git a/chrome/browser/sessions/base_session_service.cc b/chrome/browser/sessions/base_session_service.cc index 4bb9101..bf21c63 100644 --- a/chrome/browser/sessions/base_session_service.cc +++ b/chrome/browser/sessions/base_session_service.cc @@ -73,7 +73,8 @@ BaseSessionService::BaseSessionService(SessionType type, // We should never be created when off the record. DCHECK(!profile->IsOffTheRecord()); } - backend_ = new SessionBackend(type, profile_ ? profile_->GetPath() : path_); + backend_ = new SessionBackend(type, + profile_ ? profile_->GetPath().ToWStringHack() : path_); DCHECK(backend_.get()); backend_thread_ = g_browser_process->file_thread(); if (!backend_thread_) diff --git a/chrome/browser/spellchecker.h b/chrome/browser/spellchecker.h index ef36372..6d59a2d 100644 --- a/chrome/browser/spellchecker.h +++ b/chrome/browser/spellchecker.h @@ -9,12 +9,7 @@ #include "base/string_util.h" #include "chrome/browser/browser_process.h" -#if defined(OS_WIN) #include "chrome/browser/profile.h" -#else -// TODO(port): remove scaffolding, use profile.h for both POSIX and WIN. -#include "chrome/common/temp_scaffolding_stubs.h" -#endif #include "chrome/browser/spellcheck_worditerator.h" #include "chrome/common/l10n_util.h" #include "chrome/common/pref_names.h" diff --git a/chrome/browser/tabs/tab_strip_model_unittest.cc b/chrome/browser/tabs/tab_strip_model_unittest.cc index ef536a0..38467b0 100644 --- a/chrome/browser/tabs/tab_strip_model_unittest.cc +++ b/chrome/browser/tabs/tab_strip_model_unittest.cc @@ -105,7 +105,8 @@ class TabStripModelTest : public testing::Test { profile_path_ = test_dir_; file_util::AppendToPath(&profile_path_, L"New Profile"); - profile_ = ProfileManager::CreateProfile(profile_path_, + profile_ = ProfileManager::CreateProfile( + FilePath::FromWStringHack(profile_path_), L"New Profile", L"new-profile", L""); ASSERT_TRUE(profile_); pm_.AddProfile(profile_); @@ -115,7 +116,7 @@ class TabStripModelTest : public testing::Test { TabContents::RegisterFactory(kHTTPTabContentsType, NULL); // Removes a profile from the set of currently-loaded profiles. - pm_.RemoveProfileByPath(profile_path_); + pm_.RemoveProfileByPath(FilePath::FromWStringHack(profile_path_)); // Clean up test directory ASSERT_TRUE(file_util::Delete(test_dir_, true)); diff --git a/chrome/browser/visitedlink_master.cc b/chrome/browser/visitedlink_master.cc index 9cbe290..e24f80c 100644 --- a/chrome/browser/visitedlink_master.cc +++ b/chrome/browser/visitedlink_master.cc @@ -23,12 +23,12 @@ #include "base/string_util.h" #include "base/thread.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/profile.h" #if defined(OS_WIN) #include "chrome/browser/history/history.h" -#include "chrome/browser/profile.h" #else -// TODO(port): We should be using history.h & profile.h, remove scaffolding -// when those are ported. +// TODO(port): We should be using history.h, remove scaffolding +// when it is ported. #include "chrome/common/temp_scaffolding_stubs.h" #endif // !defined(OS_WIN) #if defined(OS_WIN) @@ -686,7 +686,7 @@ bool VisitedLinkMaster::GetDatabaseFileName(FilePath* filename) { if (!profile_ || profile_->GetPath().empty()) return false; - FilePath profile_dir = FilePath::FromWStringHack(profile_->GetPath()); + FilePath profile_dir = profile_->GetPath(); *filename = profile_dir.Append(FILE_PATH_LITERAL("Visited Links")); return true; } diff --git a/chrome/browser/visitedlink_unittest.cc b/chrome/browser/visitedlink_unittest.cc index 2dac97f..5b3928a 100644 --- a/chrome/browser/visitedlink_unittest.cc +++ b/chrome/browser/visitedlink_unittest.cc @@ -50,7 +50,7 @@ class VisitedLinkTest : public testing::Test { // Initialize the history system. This should be called before InitVisited(). bool InitHistory() { history_service_ = new HistoryService; - return history_service_->Init(history_dir_.ToWStringHack(), NULL); + return history_service_->Init(history_dir_, NULL); } // Initializes the visited link objects. Pass in the size that you want a diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc index ced5a6f..da430af 100644 --- a/chrome/browser/webdata/web_data_service.cc +++ b/chrome/browser/webdata/web_data_service.cc @@ -32,13 +32,13 @@ WebDataService::~WebDataService() { } } -bool WebDataService::Init(const std::wstring& profile_path) { - std::wstring path = profile_path; - file_util::AppendToPath(&path, chrome::kWebDataFilename); +bool WebDataService::Init(const FilePath& profile_path) { + FilePath path = profile_path; + path = path.Append(chrome::kWebDataFilename); return InitWithPath(path); } -bool WebDataService::InitWithPath(const std::wstring& path) { +bool WebDataService::InitWithPath(const FilePath& path) { thread_ = new base::Thread("Chrome_WebDataThread"); if (!thread_->Start()) { @@ -384,14 +384,14 @@ void WebDataService::Commit() { } } -void WebDataService::InitializeDatabase(const std::wstring& path) { +void WebDataService::InitializeDatabase(const FilePath& path) { DCHECK(!db_); // In the rare case where the db fails to initialize a dialog may get shown // the blocks the caller, yet allows other messages through. For this reason // we only set db_ to the created database if creation is successful. That // way other methods won't do anything as db_ is still NULL. WebDatabase* db = new WebDatabase(); - if (!db->Init(path)) { + if (!db->Init(path.ToWStringHack())) { NOTREACHED() << "Cannot initialize the web database"; delete db; return; diff --git a/chrome/browser/webdata/web_data_service.h b/chrome/browser/webdata/web_data_service.h index 4e2786b..e7a8e6d 100644 --- a/chrome/browser/webdata/web_data_service.h +++ b/chrome/browser/webdata/web_data_service.h @@ -20,6 +20,7 @@ struct IE7PasswordInfo; #endif struct PasswordForm; +class FilePath; class GURL; class ShutdownTask; class TemplateURL; @@ -143,7 +144,7 @@ class WebDataService : public base::RefCountedThreadSafe<WebDataService> { // Initializes the web data service. Returns false on failure // Takes the path of the profile directory as its argument. - bool Init(const std::wstring& profile_path); + bool Init(const FilePath& profile_path); // Shutdown the web data service. The service can no longer be used after this // call. @@ -387,7 +388,7 @@ class WebDataService : public base::RefCountedThreadSafe<WebDataService> { friend class WebDataRequest; // This is invoked by the unit test; path is the path of the Web Data file. - bool InitWithPath(const std::wstring& path); + bool InitWithPath(const FilePath& path); // Invoked by request implementations when a request has been processed. void RequestCompleted(Handle h); @@ -407,7 +408,7 @@ class WebDataService : public base::RefCountedThreadSafe<WebDataService> { std::vector<TemplateURL*> > SetKeywordsRequest; // Initialize the database with the provided path. - void InitializeDatabase(const std::wstring& path); + void InitializeDatabase(const FilePath& path); // Commit any pending transaction and deletes the database. void ShutdownDatabase(); diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc index 83fa217..7d5b524 100755 --- a/chrome/browser/webdata/web_database.cc +++ b/chrome/browser/webdata/web_database.cc @@ -13,13 +13,26 @@ #include "base/string_util.h" #include "base/time.h" #include "base/values.h" -#include "chrome/browser/history/history_database.h" -#include "chrome/browser/password_manager/encryptor.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/common/l10n_util.h" #include "chrome/common/scoped_vector.h" #include "webkit/glue/password_form.h" +#if defined(OS_POSIX) +// TODO(port): get rid of this include. It's used just to provide declarations +// and stub definitions for classes we encouter during the porting effort. +#include "chrome/common/temp_scaffolding_stubs.h" +#endif + +// TODO(port): Get rid of this section and finish porting. +#if defined(OS_WIN) +// Encryptor is the *wrong* way of doing things; we need to turn it into a +// bottleneck to use the platform methods (e.g. Keychain on the Mac). That's +// going to take a massive change in its API... +#include "chrome/browser/history/history_database.h" +#include "chrome/browser/password_manager/encryptor.h" +#endif + //////////////////////////////////////////////////////////////////////////////// // // Schema |