diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-18 06:34:13 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-18 06:34:13 +0000 |
commit | 6524385ef3fb2f1f26675d66cee2dad649883be6 (patch) | |
tree | c0f807e54894299399da67834a1980534daa1a2d /chrome | |
parent | f51ef0d27f701feb2c47096c9a73039e0c389a60 (diff) | |
download | chromium_src-6524385ef3fb2f1f26675d66cee2dad649883be6.zip chromium_src-6524385ef3fb2f1f26675d66cee2dad649883be6.tar.gz chromium_src-6524385ef3fb2f1f26675d66cee2dad649883be6.tar.bz2 |
Remove wstrings from bookmarks, part 1 (of many).
Start by removing wstring versions of BookmarkModel::AddURLWithCreationTime()
and BookmarkModel::SetURLStarred().
BUG=23581
TEST=builds and passes tests
Review URL: http://codereview.chromium.org/3111012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56488 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
12 files changed, 58 insertions, 69 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc b/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc index e267f3c..230c62a 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc @@ -10,6 +10,7 @@ #include "base/message_loop.h" #include "base/platform_thread.h" #include "base/ref_counted.h" +#include "base/string16.h" #include "base/string_util.h" #include "base/time.h" #include "base/utf_string_conversions.h" @@ -236,7 +237,7 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, cur.typed_count, t, false); history_service->SetPageContents(url, UTF8ToUTF16(cur.body)); if (cur.starred) { - bookmark_model->SetURLStarred(url, std::wstring(), true); + bookmark_model->SetURLStarred(url, string16(), true); } } } diff --git a/chrome/browser/autocomplete/history_contents_provider_unittest.cc b/chrome/browser/autocomplete/history_contents_provider_unittest.cc index 124a9a2..9212bce 100644 --- a/chrome/browser/autocomplete/history_contents_provider_unittest.cc +++ b/chrome/browser/autocomplete/history_contents_provider_unittest.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. @@ -157,7 +157,8 @@ TEST_F(HistoryContentsProviderTest, Bookmarks) { // Add a bookmark. GURL bookmark_url("http://www.google.com/4"); - profile()->GetBookmarkModel()->SetURLStarred(bookmark_url, L"bar", true); + profile()->GetBookmarkModel()->SetURLStarred(bookmark_url, + ASCIIToUTF16("bar"), true); // Ask for synchronous. This should only get the bookmark. AutocompleteInput sync_input(L"bar", std::wstring(), true, false, true); diff --git a/chrome/browser/bookmarks/bookmark_html_writer_unittest.cc b/chrome/browser/bookmarks/bookmark_html_writer_unittest.cc index 042f3aa..8172437 100644 --- a/chrome/browser/bookmarks/bookmark_html_writer_unittest.cc +++ b/chrome/browser/bookmarks/bookmark_html_writer_unittest.cc @@ -8,8 +8,10 @@ #include "base/file_util.h" #include "base/message_loop.h" #include "base/path_service.h" +#include "base/string16.h" #include "base/string_util.h" #include "base/time.h" +#include "base/utf_string_conversions.h" #include "base/i18n/time_formatting.h" #include "chrome/browser/bookmarks/bookmark_html_writer.h" #include "chrome/browser/bookmarks/bookmark_model.h" @@ -80,7 +82,7 @@ class BookmarkHTMLWriterTest : public testing::Test { // Creates a set of bookmark values to a string for assertion testing. std::wstring BookmarkValuesToString(bool on_toolbar, const GURL& url, - const std::wstring& title, + const string16& title, base::Time creation_time, const std::wstring& f1, const std::wstring& f2, @@ -99,7 +101,7 @@ class BookmarkHTMLWriterTest : public testing::Test { entry.path.push_back(f3); } } - entry.title = title; + entry.title = UTF16ToWideHack(title); entry.creation_time = creation_time; return BookmarkEntryToString(entry); } @@ -107,7 +109,7 @@ class BookmarkHTMLWriterTest : public testing::Test { void AssertBookmarkEntryEquals(const ProfileWriter::BookmarkEntry& entry, bool on_toolbar, const GURL& url, - const std::wstring& title, + const string16& title, base::Time creation_time, const std::wstring& f1, const std::wstring& f2, @@ -175,10 +177,10 @@ TEST_F(BookmarkHTMLWriterTest, Test) { std::wstring f2_title = L"F2"; std::wstring f3_title = L"F 3"; std::wstring f4_title = L"F4"; - std::wstring url1_title = L"url 1"; - std::wstring url2_title = L"url&2"; - std::wstring url3_title = L"url\"3"; - std::wstring url4_title = L"url\"&;"; + string16 url1_title = ASCIIToUTF16("url 1"); + string16 url2_title = ASCIIToUTF16("url&2"); + string16 url3_title = ASCIIToUTF16("url\"3"); + string16 url4_title = ASCIIToUTF16("url\"&;"); GURL url1("http://url1"); GURL url1_favicon("http://url1/icon.ico"); GURL url2("http://url2"); diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc index a5c87bf..4e35c21 100644 --- a/chrome/browser/bookmarks/bookmark_model.cc +++ b/chrome/browser/bookmarks/bookmark_model.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. @@ -398,17 +398,6 @@ const BookmarkNode* BookmarkModel::AddURL(const BookmarkNode* parent, return AddURLWithCreationTime(parent, index, title, url, Time::Now()); } -#if !defined(WCHAR_T_IS_UTF16) -const BookmarkNode* BookmarkModel::AddURLWithCreationTime( - const BookmarkNode* parent, - int index, - const std::wstring& title, - const GURL& url, - const Time& creation_time) { - return AddURLWithCreationTime(parent, index, WideToUTF16(title), - url, creation_time); -} -#endif const BookmarkNode* BookmarkModel::AddURLWithCreationTime( const BookmarkNode* parent, int index, @@ -464,13 +453,6 @@ void BookmarkModel::SortChildren(const BookmarkNode* parent) { BookmarkNodeChildrenReordered(this, parent)); } -#if !defined(WCHAR_T_IS_UTF16) -void BookmarkModel::SetURLStarred(const GURL& url, - const std::wstring& title, - bool is_starred) { - SetURLStarred(url, WideToUTF16(title), is_starred); -} -#endif void BookmarkModel::SetURLStarred(const GURL& url, const string16& title, bool is_starred) { diff --git a/chrome/browser/bookmarks/bookmark_model.h b/chrome/browser/bookmarks/bookmark_model.h index 00730d7..7103615 100644 --- a/chrome/browser/bookmarks/bookmark_model.h +++ b/chrome/browser/bookmarks/bookmark_model.h @@ -289,15 +289,7 @@ class BookmarkModel : public NotificationObserver, public BookmarkService { const string16& title, const GURL& url); - // TODO(munjal): Remove wstring overload once all code is moved to string16. // Adds a url with a specific creation date. -#if !defined(WCHAR_T_IS_UTF16) - const BookmarkNode* AddURLWithCreationTime(const BookmarkNode* parent, - int index, - const std::wstring& title, - const GURL& url, - const base::Time& creation_time); -#endif const BookmarkNode* AddURLWithCreationTime(const BookmarkNode* parent, int index, const string16& title, @@ -308,15 +300,9 @@ class BookmarkModel : public NotificationObserver, public BookmarkService { // BookmarkNodeChildrenReordered method. void SortChildren(const BookmarkNode* parent); - // TODO(munjal): Remove wstring overload once all code is moved to string16. // This is the convenience that makes sure the url is starred or not starred. // If is_starred is false, all bookmarks for URL are removed. If is_starred is // true and there are no bookmarks for url, a bookmark is created. -#if !defined(WCHAR_T_IS_UTF16) - void SetURLStarred(const GURL& url, - const std::wstring& title, - bool is_starred); -#endif void SetURLStarred(const GURL& url, const string16& title, bool is_starred); diff --git a/chrome/browser/bookmarks/bookmark_model_unittest.cc b/chrome/browser/bookmarks/bookmark_model_unittest.cc index 4001d35..b1d5883 100644 --- a/chrome/browser/bookmarks/bookmark_model_unittest.cc +++ b/chrome/browser/bookmarks/bookmark_model_unittest.cc @@ -10,6 +10,7 @@ #include "base/file_util.h" #include "base/hash_tables.h" #include "base/path_service.h" +#include "base/string16.h" #include "base/string_number_conversions.h" #include "base/string_util.h" #include "chrome/browser/bookmarks/bookmark_codec.h" @@ -941,7 +942,7 @@ TEST_F(BookmarkModelTestWithProfile2, RemoveNotification) { // Add a URL. GURL url("http://www.google.com"); - bb_model_->SetURLStarred(url, std::wstring(), true); + bb_model_->SetURLStarred(url, string16(), true); profile_->GetHistoryService(Profile::EXPLICIT_ACCESS)->AddPage( url, NULL, 1, GURL(), PageTransition::TYPED, diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index c6cd15b..ac91d86 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -20,6 +20,7 @@ #include "base/path_service.h" #include "base/string_util.h" #include "base/thread.h" +#include "base/utf_string_conversions.h" #include "gfx/point.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/autofill/autofill_manager.h" @@ -1494,7 +1495,7 @@ void Browser::BookmarkCurrentPage() { bookmark_utils::GetURLAndTitleToBookmark(GetSelectedTabContents(), &url, &title); bool was_bookmarked = model->IsBookmarked(url); - model->SetURLStarred(url, title, true); + model->SetURLStarred(url, WideToUTF16Hack(title), true); // Make sure the model actually added a bookmark before showing the star. A // bookmark isn't created if the url is invalid. if (window_->IsActive() && model->IsBookmarked(url)) { diff --git a/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm b/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm index a0491a2..48174c4 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm +++ b/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm @@ -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. @@ -7,8 +7,10 @@ #include "app/theme_provider.h" #include "base/basictypes.h" #include "base/scoped_nsobject.h" +#include "base/string16.h" #include "base/string_util.h" #include "base/sys_string_conversions.h" +#include "base/utf_string_conversions.h" #include "chrome/browser/bookmarks/bookmark_model.h" #import "chrome/browser/cocoa/bookmark_bar_constants.h" #import "chrome/browser/cocoa/bookmark_bar_controller.h" @@ -543,7 +545,8 @@ TEST_F(BookmarkBarControllerTest, OffTheSideButtonHidden) { EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); for (int i = 0; i < 2; i++) { - model->SetURLStarred(GURL("http://www.foo.com"), L"small", true); + model->SetURLStarred(GURL("http://www.foo.com"), ASCIIToUTF16("small"), + true); EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); } @@ -594,8 +597,7 @@ TEST_F(BookmarkBarControllerTest, DeleteFromOffTheSideWhileItIsOpen) { for (int i = 0; i < 100; i++) { std::ostringstream title; title << "super duper wide title " << i; - model->AddURL(parent, parent->GetChildCount(), - ASCIIToWide(title.str().c_str()), + model->AddURL(parent, parent->GetChildCount(), ASCIIToUTF16(title.str()), GURL("http://superfriends.hall-of-justice.edu")); } EXPECT_FALSE([bar_ offTheSideButtonIsHidden]); @@ -685,8 +687,9 @@ TEST_F(BookmarkBarControllerTest, MenuForFolderNode) { // Test two bookmarks. GURL gurl("http://www.foo.com"); - model->SetURLStarred(gurl, L"small", true); - model->SetURLStarred(GURL("http://www.cnn.com"), L"bigger title", true); + model->SetURLStarred(gurl, ASCIIToUTF16("small"), true); + model->SetURLStarred(GURL("http://www.cnn.com"), ASCIIToUTF16("bigger title"), + true); menu = [bar_ menuForFolderNode:model->GetBookmarkBarNode()]; EXPECT_EQ([menu numberOfItems], 2); NSMenuItem *item = [menu itemWithTitle:@"bigger title"]; @@ -776,13 +779,13 @@ TEST_F(BookmarkBarControllerTest, TestAddRemoveAndClear) { // narrow. // TODO(viettrungluu): make the test independent of window/view size, font // metrics, button size and spacing, and everything else. - std::wstring title1(L"x"); + string16 title1(ASCIIToUTF16("x")); model->SetURLStarred(gurl1, title1, true); EXPECT_EQ(1U, [[bar_ buttons] count]); EXPECT_EQ(1+initial_subview_count, [[buttonView subviews] count]); GURL gurl2("http://legion-of-doom.gov"); - std::wstring title2(L"y"); + string16 title2(ASCIIToUTF16("y")); model->SetURLStarred(gurl2, title2, true); EXPECT_EQ(2U, [[bar_ buttons] count]); EXPECT_EQ(2+initial_subview_count, [[buttonView subviews] count]); @@ -873,11 +876,11 @@ TEST_F(BookmarkBarControllerTest, TestButtonMarch) { TEST_F(BookmarkBarControllerTest, CheckForGrowth) { BookmarkModel* model = helper_.profile()->GetBookmarkModel(); GURL gurl1("http://www.google.com"); - std::wstring title1(L"x"); + string16 title1(ASCIIToUTF16("x")); model->SetURLStarred(gurl1, title1, true); GURL gurl2("http://www.google.com/blah"); - std::wstring title2(L"y"); + string16 title2(ASCIIToUTF16("y")); model->SetURLStarred(gurl2, title2, true); EXPECT_EQ(2U, [[bar_ buttons] count]); @@ -956,7 +959,7 @@ TEST_F(BookmarkBarControllerTest, Display) { TEST_F(BookmarkBarControllerTest, MiddleClick) { BookmarkModel* model = helper_.profile()->GetBookmarkModel(); GURL gurl1("http://www.google.com/"); - std::wstring title1(L"x"); + string16 title1(ASCIIToUTF16("x")); model->SetURLStarred(gurl1, title1, true); EXPECT_EQ(1U, [[bar_ buttons] count]); @@ -1048,11 +1051,11 @@ TEST_F(BookmarkBarControllerTest, DropBookmarks) { TEST_F(BookmarkBarControllerTest, TestButtonOrBar) { BookmarkModel* model = helper_.profile()->GetBookmarkModel(); GURL gurl1("http://www.google.com"); - std::wstring title1(L"x"); + string16 title1(ASCIIToUTF16("x")); model->SetURLStarred(gurl1, title1, true); GURL gurl2("http://www.google.com/gurl_power"); - std::wstring title2(L"gurl power"); + string16 title2(ASCIIToUTF16("gurl power")); model->SetURLStarred(gurl2, title2, true); NSButton* first = [[bar_ buttons] objectAtIndex:0]; @@ -1108,7 +1111,9 @@ TEST_F(BookmarkBarControllerTest, TestDragButton) { GURL gurls[] = { GURL("http://www.google.com/a"), GURL("http://www.google.com/b"), GURL("http://www.google.com/c") }; - std::wstring titles[] = { L"a", L"b", L"c" }; + string16 titles[] = { ASCIIToUTF16("a"), + ASCIIToUTF16("b"), + ASCIIToUTF16("c") }; for (unsigned i = 0; i < arraysize(titles); i++) { model->SetURLStarred(gurls[i], titles[i], true); } @@ -1179,7 +1184,9 @@ TEST_F(BookmarkBarControllerTest, TestCopyButton) { GURL gurls[] = { GURL("http://www.google.com/a"), GURL("http://www.google.com/b"), GURL("http://www.google.com/c") }; - std::wstring titles[] = { L"a", L"b", L"c" }; + string16 titles[] = { ASCIIToUTF16("a"), + ASCIIToUTF16("b"), + ASCIIToUTF16("c") }; for (unsigned i = 0; i < arraysize(titles); i++) { model->SetURLStarred(gurls[i], titles[i], true); } @@ -1203,7 +1210,7 @@ TEST_F(BookmarkBarControllerTest, TestCopyButton) { // buttons have the same colored text. Repeat more than once. TEST_F(BookmarkBarControllerTest, TestThemedButton) { BookmarkModel* model = helper_.profile()->GetBookmarkModel(); - model->SetURLStarred(GURL("http://www.foo.com"), L"small", true); + model->SetURLStarred(GURL("http://www.foo.com"), ASCIIToUTF16("small"), true); BookmarkButton* button = [[bar_ buttons] objectAtIndex:0]; EXPECT_TRUE(button); @@ -1231,7 +1238,9 @@ TEST_F(BookmarkBarControllerTest, TestClearOnDealloc) { GURL gurls[] = { GURL("http://www.foo.com/"), GURL("http://www.bar.com/"), GURL("http://www.baz.com/") }; - std::wstring titles[] = { L"foo", L"bar", L"baz" }; + string16 titles[] = { ASCIIToUTF16("a"), + ASCIIToUTF16("b"), + ASCIIToUTF16("c") }; for (size_t i = 0; i < arraysize(titles); i++) model->SetURLStarred(gurls[i], titles[i], true); diff --git a/chrome/browser/cocoa/bookmark_bubble_controller.mm b/chrome/browser/cocoa/bookmark_bubble_controller.mm index 641c37e..8b83541 100644 --- a/chrome/browser/cocoa/bookmark_bubble_controller.mm +++ b/chrome/browser/cocoa/bookmark_bubble_controller.mm @@ -7,6 +7,7 @@ #include "app/l10n_util_mac.h" #include "base/mac_util.h" #include "base/sys_string_conversions.h" +#include "base/utf_string_conversions.h" // TODO(viettrungluu): remove #include "chrome/browser/bookmarks/bookmark_model.h" #import "chrome/browser/cocoa/bookmark_button.h" #import "chrome/browser/cocoa/browser_window_controller.h" @@ -276,7 +277,9 @@ void BookmarkBubbleNotificationBridge::Observe( - (IBAction)remove:(id)sender { [self stopPulsingBookmarkButton]; - model_->SetURLStarred(node_->GetURL(), node_->GetTitle(), false); + // TODO(viettrungluu): get rid of conversion and utf_string_conversions.h. + model_->SetURLStarred(node_->GetURL(), WideToUTF16Hack(node_->GetTitle()), + false); UserMetrics::RecordAction(UserMetricsAction("BookmarkBubble_Unstar"), model_->profile()); node_ = NULL; // no longer valid diff --git a/chrome/browser/history/expire_history_backend_unittest.cc b/chrome/browser/history/expire_history_backend_unittest.cc index 95b391f..ac3e834 100644 --- a/chrome/browser/history/expire_history_backend_unittest.cc +++ b/chrome/browser/history/expire_history_backend_unittest.cc @@ -8,6 +8,7 @@ #include "base/file_util.h" #include "base/path_service.h" #include "base/scoped_ptr.h" +#include "base/string16.h" #include "base/utf_string_conversions.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/history/archived_database.h" @@ -517,7 +518,7 @@ TEST_F(ExpireHistoryTest, DontDeleteStarredURL) { ASSERT_TRUE(HasThumbnail(url_row.id())); // Unstar the URL and delete again. - bookmark_model_.SetURLStarred(url, std::wstring(), false); + bookmark_model_.SetURLStarred(url, string16(), false); expirer_.DeleteURL(url); // Now it should be completely deleted. diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc index 780038d..fe36c9d 100644 --- a/chrome/browser/history/history_backend_unittest.cc +++ b/chrome/browser/history/history_backend_unittest.cc @@ -8,6 +8,7 @@ #include "base/path_service.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" +#include "base/string16.h" #include "base/utf_string_conversions.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/history/history_backend.h" @@ -350,8 +351,8 @@ TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { URLID row2_id = backend_->db_->GetRowForURL(row2.url(), NULL); // Star the two URLs. - bookmark_model_.SetURLStarred(row1.url(), std::wstring(), true); - bookmark_model_.SetURLStarred(row2.url(), std::wstring(), true); + bookmark_model_.SetURLStarred(row1.url(), string16(), true); + bookmark_model_.SetURLStarred(row2.url(), string16(), true); // Delete url 2. Because url 2 is starred this won't delete the URL, only // the visits. @@ -368,7 +369,7 @@ TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { backend_->thumbnail_db_->GetFavIconIDForFavIconURL(favicon_url2)); // Unstar row2. - bookmark_model_.SetURLStarred(row2.url(), std::wstring(), false); + bookmark_model_.SetURLStarred(row2.url(), string16(), false); // Tell the backend it was unstarred. We have to explicitly do this as // BookmarkModel isn't wired up to the backend during testing. std::set<GURL> unstarred_urls; @@ -382,7 +383,7 @@ TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { backend_->thumbnail_db_->GetFavIconIDForFavIconURL(favicon_url2)); // Unstar row 1. - bookmark_model_.SetURLStarred(row1.url(), std::wstring(), false); + bookmark_model_.SetURLStarred(row1.url(), string16(), false); // Tell the backend it was unstarred. We have to explicitly do this as // BookmarkModel isn't wired up to the backend during testing. unstarred_urls.clear(); diff --git a/chrome/browser/importer/profile_writer.cc b/chrome/browser/importer/profile_writer.cc index 0061efc..679f0ec 100644 --- a/chrome/browser/importer/profile_writer.cc +++ b/chrome/browser/importer/profile_writer.cc @@ -6,6 +6,7 @@ #include "base/string_util.h" #include "base/thread.h" +#include "base/utf_string_conversions.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/importer/importer.h" #include "chrome/browser/password_manager/password_store.h" @@ -110,7 +111,7 @@ void ProfileWriter::AddBookmarkEntry( } groups_added_to.insert(parent); model->AddURLWithCreationTime(parent, parent->GetChildCount(), - it->title, it->url, it->creation_time); + WideToUTF16Hack(it->title), it->url, it->creation_time); // If some items are put into toolbar, it looks like the user was using // it in their last browser. We turn on the bookmarks toolbar. |