diff options
-rw-r--r-- | app/tree_model.h | 2 | ||||
-rw-r--r-- | app/tree_node_model.h | 23 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_model.cc | 50 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_model.h | 39 |
4 files changed, 109 insertions, 5 deletions
diff --git a/app/tree_model.h b/app/tree_model.h index 86d6424..9ce6cb1 100644 --- a/app/tree_model.h +++ b/app/tree_model.h @@ -20,7 +20,7 @@ class TreeModel; class TreeModelNode { public: // Returns the title for the node. - virtual const std::wstring& GetTitle() const = 0; + virtual std::wstring GetTitle() const = 0; protected: virtual ~TreeModelNode() {} diff --git a/app/tree_node_model.h b/app/tree_node_model.h index 04aa997..b47fe03 100644 --- a/app/tree_node_model.h +++ b/app/tree_node_model.h @@ -6,6 +6,7 @@ #define APP_TREE_NODE_MODEL_H_ #include <algorithm> +#include <string> #include <vector> #include "app/tree_model.h" @@ -13,6 +14,8 @@ #include "base/scoped_ptr.h" #include "base/scoped_vector.h" #include "base/stl_util-inl.h" +#include "base/string16.h" +#include "base/utf_string_conversions.h" // TreeNodeModel and TreeNodes provide an implementation of TreeModel around // TreeNodes. TreeNodes form a directed acyclic graph. @@ -65,7 +68,12 @@ class TreeNode : public TreeModelNode { public: TreeNode() : parent_(NULL) { } + // TODO(munjal): Remove wstring overload once all code is moved to string16. +#if !defined(WCHAR_T_IS_UTF16) explicit TreeNode(const std::wstring& title) + : title_(WideToUTF16(title)), parent_(NULL) {} +#endif + explicit TreeNode(const string16& title) : title_(title), parent_(NULL) {} virtual ~TreeNode() { @@ -144,12 +152,23 @@ class TreeNode : public TreeModelNode { } // Sets the title of the node. + // TODO(munjal): Remove wstring overload once all code is moved to string16. +#if !defined(WCHAR_T_IS_UTF16) void SetTitle(const std::wstring& string) { + title_ = WideToUTF16(string); + } +#endif + void SetTitle(const string16& string) { title_ = string; } + // TODO(munjal): Remove wstring version and rename GetTitleAsString16 to + // GetTitle once all code is moved to string16. // Returns the title of the node. - virtual const std::wstring& GetTitle() const { + virtual std::wstring GetTitle() const { + return UTF16ToWide(title_); + } + virtual const string16& GetTitleAsString16() const { return title_; } @@ -171,7 +190,7 @@ class TreeNode : public TreeModelNode { private: // Title displayed in the tree. - std::wstring title_; + string16 title_; NodeType* parent_; 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_; } |