diff options
author | munjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-11 23:10:55 +0000 |
---|---|---|
committer | munjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-11 23:10:55 +0000 |
commit | e64e90172572f90ffb4633b90b1f5045a13a5aef (patch) | |
tree | 138d5db7c418369a87c70339439ae99e28192ebc /chrome/browser/bookmarks | |
parent | f5f241605193ceb9efad351d502814e3e3d33626 (diff) | |
download | chromium_src-e64e90172572f90ffb4633b90b1f5045a13a5aef.zip chromium_src-e64e90172572f90ffb4633b90b1f5045a13a5aef.tar.gz chromium_src-e64e90172572f90ffb4633b90b1f5045a13a5aef.tar.bz2 |
Use string16 instead of wstring in bookmark data model.
Add overloads to bookmark model for string16. Wrap wstring
versions in #if !defined since string16 is just a typedef of
wstring on windows.
TEST=exist
BUG=32013
Review URL: http://codereview.chromium.org/536013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35964 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/bookmarks')
-rw-r--r-- | chrome/browser/bookmarks/bookmark_model.cc | 50 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_model.h | 39 |
2 files changed, 87 insertions, 2 deletions
diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc index a4e17dc..19e1fcc 100644 --- a/chrome/browser/bookmarks/bookmark_model.cc +++ b/chrome/browser/bookmarks/bookmark_model.cc @@ -215,13 +215,18 @@ const SkBitmap& BookmarkModel::GetFavIcon(const BookmarkNode* node) { return node->favicon(); } +#if !defined(WCHAR_T_IS_UTF16) void BookmarkModel::SetTitle(const BookmarkNode* node, const std::wstring& title) { + SetTitle(node, WideToUTF16(title)); +} +#endif +void BookmarkModel::SetTitle(const BookmarkNode* node, const string16& title) { if (!node) { NOTREACHED(); return; } - if (node->GetTitle() == title) + if (node->GetTitleAsString16() == title) return; if (node == bookmark_bar_node_ || node == other_node_) { @@ -287,9 +292,16 @@ const BookmarkNode* BookmarkModel::GetNodeByID(int64 id) { return GetNodeByID(&root_, id); } +#if !defined(WCHAR_T_IS_UTF16) const BookmarkNode* BookmarkModel::AddGroup(const BookmarkNode* parent, int index, const std::wstring& title) { + return AddGroup(parent, index, WideToUTF16(title)); +} +#endif +const BookmarkNode* BookmarkModel::AddGroup(const BookmarkNode* parent, + int index, + const string16& title) { if (!loaded_ || parent == &root_ || !IsValidIndex(parent, index, true)) { // Can't add to the root. NOTREACHED(); @@ -305,19 +317,38 @@ const BookmarkNode* BookmarkModel::AddGroup(const BookmarkNode* parent, return AddNode(AsMutable(parent), index, new_node, false); } +#if !defined(WCHAR_T_IS_UTF16) const BookmarkNode* BookmarkModel::AddURL(const BookmarkNode* parent, int index, const std::wstring& title, const GURL& url) { + return AddURL(parent, index, WideToUTF16(title), url); +} +#endif +const BookmarkNode* BookmarkModel::AddURL(const BookmarkNode* parent, + int index, + const string16& title, + const GURL& url) { 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, + const string16& title, + const GURL& url, + const Time& creation_time) { if (!loaded_ || !url.is_valid() || is_root(parent) || !IsValidIndex(parent, index, true)) { NOTREACHED(); @@ -367,9 +398,16 @@ 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) { std::vector<const BookmarkNode*> bookmarks; GetNodesByURL(url, &bookmarks); bool bookmarks_exist = !bookmarks.empty(); @@ -402,14 +440,22 @@ void BookmarkModel::ResetDateGroupModified(const BookmarkNode* node) { SetDateGroupModified(node, Time()); } +#if !defined(WCHAR_T_IS_UTF16) void BookmarkModel::GetBookmarksWithTitlesMatching( const std::wstring& text, size_t max_count, std::vector<bookmark_utils::TitleMatch>* matches) { + GetBookmarksWithTitlesMatching(WideToUTF16(text), max_count, matches); +} +#endif +void BookmarkModel::GetBookmarksWithTitlesMatching( + const string16& text, + size_t max_count, + std::vector<bookmark_utils::TitleMatch>* matches) { if (!loaded_) return; - index_->GetBookmarksWithTitlesMatching(text, max_count, matches); + index_->GetBookmarksWithTitlesMatching(UTF16ToWide(text), max_count, matches); } void BookmarkModel::ClearStore() { diff --git a/chrome/browser/bookmarks/bookmark_model.h b/chrome/browser/bookmarks/bookmark_model.h index ba66791..fcea7c7 100644 --- a/chrome/browser/bookmarks/bookmark_model.h +++ b/chrome/browser/bookmarks/bookmark_model.h @@ -13,6 +13,7 @@ #include "app/tree_node_model.h" #include "base/lock.h" #include "base/observer_list.h" +#include "base/string16.h" #include "base/waitable_event.h" #include "chrome/browser/bookmarks/bookmark_model_observer.h" #include "chrome/browser/bookmarks/bookmark_service.h" @@ -217,8 +218,12 @@ class BookmarkModel : public NotificationObserver, public BookmarkService { // loaded it is loaded and the observer of the model notified when done. const SkBitmap& GetFavIcon(const BookmarkNode* node); + // TODO(munjal): Remove wstring overload once all code is moved to string16. // Sets the title of the specified node. +#if !defined(WCHAR_T_IS_UTF16) void SetTitle(const BookmarkNode* node, const std::wstring& title); +#endif + void SetTitle(const BookmarkNode* node, const string16& title); // Returns true if the model finished loading. bool IsLoaded() { return loaded_; } @@ -245,34 +250,61 @@ class BookmarkModel : public NotificationObserver, public BookmarkService { // the specified id. const BookmarkNode* GetNodeByID(int64 id); + // TODO(munjal): Remove wstring overload once all code is moved to string16. // Adds a new group node at the specified position. +#if !defined(WCHAR_T_IS_UTF16) const BookmarkNode* AddGroup(const BookmarkNode* parent, int index, const std::wstring& title); +#endif + const BookmarkNode* AddGroup(const BookmarkNode* parent, + int index, + const string16& title); + // TODO(munjal): Remove wstring overload once all code is moved to string16. // Adds a url at the specified position. +#if !defined(WCHAR_T_IS_UTF16) const BookmarkNode* AddURL(const BookmarkNode* parent, int index, const std::wstring& title, const GURL& url); +#endif + const BookmarkNode* AddURL(const BookmarkNode* parent, + int index, + 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, + const GURL& url, + const base::Time& creation_time); // Sorts the children of |parent|, notifying observers by way of the // 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); // Sets the date modified time of the specified node. void SetDateGroupModified(const BookmarkNode* parent, const base::Time time); @@ -282,10 +314,17 @@ class BookmarkModel : public NotificationObserver, public BookmarkService { // combobox of most recently modified groups. void ResetDateGroupModified(const BookmarkNode* node); + // TODO(munjal): Remove wstring overload once all code is moved to string16. +#if !defined(WCHAR_T_IS_UTF16) void GetBookmarksWithTitlesMatching( const std::wstring& text, size_t max_count, std::vector<bookmark_utils::TitleMatch>* matches); +#endif + void GetBookmarksWithTitlesMatching( + const string16& text, + size_t max_count, + std::vector<bookmark_utils::TitleMatch>* matches); Profile* profile() const { return profile_; } |