Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / components / bookmarks / browser / bookmark_node.h
blob3d24462a9befebc66ab10c928fbe4703f2552c65
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_NODE_H_
6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_NODE_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/task/cancelable_task_tracker.h"
10 #include "base/time/time.h"
11 #include "components/favicon_base/favicon_types.h"
12 #include "ui/base/models/tree_node_model.h"
13 #include "ui/gfx/image/image.h"
14 #include "url/gurl.h"
16 namespace bookmarks {
18 class BookmarkModel;
20 // BookmarkNode ---------------------------------------------------------------
22 // BookmarkNode contains information about a starred entry: title, URL, favicon,
23 // id and type. BookmarkNodes are returned from BookmarkModel.
24 class BookmarkNode : public ui::TreeNode<BookmarkNode> {
25 public:
26 enum Type {
27 URL,
28 FOLDER,
29 BOOKMARK_BAR,
30 OTHER_NODE,
31 MOBILE
34 enum FaviconState {
35 INVALID_FAVICON,
36 LOADING_FAVICON,
37 LOADED_FAVICON,
40 typedef std::map<std::string, std::string> MetaInfoMap;
42 static const int64 kInvalidSyncTransactionVersion;
44 // Creates a new node with an id of 0 and |url|.
45 explicit BookmarkNode(const GURL& url);
46 // Creates a new node with |id| and |url|.
47 BookmarkNode(int64 id, const GURL& url);
49 ~BookmarkNode() override;
51 // Set the node's internal title. Note that this neither invokes observers
52 // nor updates any bookmark model this node may be in. For that functionality,
53 // BookmarkModel::SetTitle(..) should be used instead.
54 void SetTitle(const base::string16& title) override;
56 // Returns an unique id for this node.
57 // For bookmark nodes that are managed by the bookmark model, the IDs are
58 // persisted across sessions.
59 int64 id() const { return id_; }
60 void set_id(int64 id) { id_ = id; }
62 const GURL& url() const { return url_; }
63 void set_url(const GURL& url) { url_ = url; }
65 // Returns the favicon's URL. Returns an empty URL if there is no favicon
66 // associated with this bookmark.
67 const GURL& icon_url() const { return icon_url_; }
69 Type type() const { return type_; }
70 void set_type(Type type) { type_ = type; }
72 // Returns the time the node was added.
73 const base::Time& date_added() const { return date_added_; }
74 void set_date_added(const base::Time& date) { date_added_ = date; }
76 // Returns the last time the folder was modified. This is only maintained
77 // for folders (including the bookmark bar and other folder).
78 const base::Time& date_folder_modified() const {
79 return date_folder_modified_;
81 void set_date_folder_modified(const base::Time& date) {
82 date_folder_modified_ = date;
85 // Convenience for testing if this node represents a folder. A folder is a
86 // node whose type is not URL.
87 bool is_folder() const { return type_ != URL; }
88 bool is_url() const { return type_ == URL; }
90 bool is_favicon_loaded() const { return favicon_state_ == LOADED_FAVICON; }
92 // Accessor method for controlling the visibility of a bookmark node/sub-tree.
93 // Note that visibility is not propagated down the tree hierarchy so if a
94 // parent node is marked as invisible, a child node may return "Visible". This
95 // function is primarily useful when traversing the model to generate a UI
96 // representation but we may want to suppress some nodes.
97 virtual bool IsVisible() const;
99 // Gets/sets/deletes value of |key| in the meta info represented by
100 // |meta_info_str_|. Return true if key is found in meta info for gets or
101 // meta info is changed indeed for sets/deletes.
102 bool GetMetaInfo(const std::string& key, std::string* value) const;
103 bool SetMetaInfo(const std::string& key, const std::string& value);
104 bool DeleteMetaInfo(const std::string& key);
105 void SetMetaInfoMap(const MetaInfoMap& meta_info_map);
106 // Returns NULL if there are no values in the map.
107 const MetaInfoMap* GetMetaInfoMap() const;
109 void set_sync_transaction_version(int64 sync_transaction_version) {
110 sync_transaction_version_ = sync_transaction_version;
112 int64 sync_transaction_version() const {
113 return sync_transaction_version_;
116 // TODO(sky): Consider adding last visit time here, it'll greatly simplify
117 // HistoryContentsProvider.
119 private:
120 friend class BookmarkModel;
122 // A helper function to initialize various fields during construction.
123 void Initialize(int64 id);
125 // Called when the favicon becomes invalid.
126 void InvalidateFavicon();
128 // Sets the favicon's URL.
129 void set_icon_url(const GURL& icon_url) {
130 icon_url_ = icon_url;
133 // Returns the favicon. In nearly all cases you should use the method
134 // BookmarkModel::GetFavicon rather than this one as it takes care of
135 // loading the favicon if it isn't already loaded.
136 const gfx::Image& favicon() const { return favicon_; }
137 void set_favicon(const gfx::Image& icon) { favicon_ = icon; }
139 favicon_base::IconType favicon_type() const { return favicon_type_; }
140 void set_favicon_type(favicon_base::IconType type) { favicon_type_ = type; }
142 FaviconState favicon_state() const { return favicon_state_; }
143 void set_favicon_state(FaviconState state) { favicon_state_ = state; }
145 base::CancelableTaskTracker::TaskId favicon_load_task_id() const {
146 return favicon_load_task_id_;
148 void set_favicon_load_task_id(base::CancelableTaskTracker::TaskId id) {
149 favicon_load_task_id_ = id;
152 // The unique identifier for this node.
153 int64 id_;
155 // The URL of this node. BookmarkModel maintains maps off this URL, so changes
156 // to the URL must be done through the BookmarkModel.
157 GURL url_;
159 // The type of this node. See enum above.
160 Type type_;
162 // Date of when this node was created.
163 base::Time date_added_;
165 // Date of the last modification. Only used for folders.
166 base::Time date_folder_modified_;
168 // The favicon of this node.
169 gfx::Image favicon_;
171 // The type of favicon currently loaded.
172 favicon_base::IconType favicon_type_;
174 // The URL of the node's favicon.
175 GURL icon_url_;
177 // The loading state of the favicon.
178 FaviconState favicon_state_;
180 // If not base::CancelableTaskTracker::kBadTaskId, it indicates
181 // we're loading the
182 // favicon and the task is tracked by CancelabelTaskTracker.
183 base::CancelableTaskTracker::TaskId favicon_load_task_id_;
185 // A map that stores arbitrary meta information about the node.
186 scoped_ptr<MetaInfoMap> meta_info_map_;
188 // The sync transaction version. Defaults to kInvalidSyncTransactionVersion.
189 int64 sync_transaction_version_;
191 DISALLOW_COPY_AND_ASSIGN(BookmarkNode);
194 // BookmarkPermanentNode -------------------------------------------------------
196 // Node used for the permanent folders (excluding the root).
197 class BookmarkPermanentNode : public BookmarkNode {
198 public:
199 explicit BookmarkPermanentNode(int64 id);
200 ~BookmarkPermanentNode() override;
202 // WARNING: this code is used for other projects. Contact noyau@ for details.
203 void set_visible(bool value) { visible_ = value; }
205 // BookmarkNode overrides:
206 bool IsVisible() const override;
208 private:
209 bool visible_;
211 DISALLOW_COPY_AND_ASSIGN(BookmarkPermanentNode);
214 } // namespace bookmarks
216 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_NODE_H_