OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_ | 5 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_ |
6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_ | 6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 class BookmarkModel; | 31 class BookmarkModel; |
32 class BookmarkStorage; | 32 class BookmarkStorage; |
33 class Profile; | 33 class Profile; |
34 | 34 |
35 namespace bookmark_utils { | 35 namespace bookmark_utils { |
36 struct TitleMatch; | 36 struct TitleMatch; |
37 } | 37 } |
38 | 38 |
39 // BookmarkNode --------------------------------------------------------------- | 39 // BookmarkNode --------------------------------------------------------------- |
40 | 40 |
41 // BookmarkNode contains information about a starred entry: title, URL, favicon, | 41 // BookmarkNode contains information about a starred entry: id, type, title, |
42 // star id and type. BookmarkNodes are returned from a BookmarkModel. | 42 // URL, favicon. BookmarkNodes are returned from BookmarkModel. |
43 // | |
44 class BookmarkNode : public ui::TreeNode<BookmarkNode> { | 43 class BookmarkNode : public ui::TreeNode<BookmarkNode> { |
45 public: | 44 public: |
46 enum Type { | 45 enum Type { |
47 URL, | 46 URL, |
48 FOLDER, | 47 FOLDER, |
49 BOOKMARK_BAR, | 48 BOOKMARK_BAR, |
50 OTHER_NODE, | 49 OTHER_NODE, |
51 SYNCED | 50 SYNCED |
52 }; | 51 }; |
53 // Creates a new node with the specified url and id of 0 | 52 |
| 53 // Creates a new node with id of 0 and |url|. |
54 explicit BookmarkNode(const GURL& url); | 54 explicit BookmarkNode(const GURL& url); |
55 // Creates a new node with the specified url and id. | 55 // Creates a new node with |id| and |url|. |
56 BookmarkNode(int64 id, const GURL& url); | 56 BookmarkNode(int64 id, const GURL& url); |
| 57 |
57 virtual ~BookmarkNode(); | 58 virtual ~BookmarkNode(); |
58 | 59 |
59 // Returns the URL. | |
60 const GURL& GetURL() const { return url_; } | 60 const GURL& GetURL() const { return url_; } |
61 // Sets the URL to the given value. | |
62 void SetURL(const GURL& url) { url_ = url; } | 61 void SetURL(const GURL& url) { url_ = url; } |
63 | 62 |
64 // Returns a unique id for this node. | 63 // Returns a unique id for this node. |
65 // For bookmark nodes that are managed by the bookmark model, the IDs are | 64 // For bookmark nodes that are managed by the bookmark model, the IDs are |
66 // persisted across sessions. | 65 // persisted across sessions. |
67 int64 id() const { return id_; } | 66 int64 id() const { return id_; } |
68 // Sets the id to the given value. | |
69 void set_id(int64 id) { id_ = id; } | 67 void set_id(int64 id) { id_ = id; } |
70 | 68 |
71 // Returns the type of this node. | |
72 Type type() const { return type_; } | 69 Type type() const { return type_; } |
73 void set_type(Type type) { type_ = type; } | 70 void set_type(Type type) { type_ = type; } |
74 | 71 |
75 // Returns the time the bookmark/folder was added. | 72 // Returns the time the bookmark/folder was added. |
76 const base::Time& date_added() const { return date_added_; } | 73 const base::Time& date_added() const { return date_added_; } |
77 // Sets the time the bookmark/folder was added. | 74 // Sets the time the bookmark/folder was added. |
78 void set_date_added(const base::Time& date) { date_added_ = date; } | 75 void set_date_added(const base::Time& date) { date_added_ = date; } |
79 | 76 |
80 // Returns the last time the folder was modified. This is only maintained | 77 // Returns the last time the folder was modified. This is only maintained |
81 // for folders (including the bookmark and other folder). | 78 // for folders (including the bookmark and other folder). |
82 const base::Time& date_folder_modified() const { | 79 const base::Time& date_folder_modified() const { |
83 return date_folder_modified_; | 80 return date_folder_modified_; |
84 } | 81 } |
85 // Sets the last time the folder was modified. | |
86 void set_date_folder_modified(const base::Time& date) { | 82 void set_date_folder_modified(const base::Time& date) { |
87 date_folder_modified_ = date; | 83 date_folder_modified_ = date; |
88 } | 84 } |
89 | 85 |
90 // Convenience for testing if this nodes represents a folder. A folder is a | 86 // Convenience for testing if this nodes represents a folder. A folder is a |
91 // node whose type is not URL. | 87 // node whose type is not URL. |
92 bool is_folder() const { return type_ != URL; } | 88 bool is_folder() const { return type_ != URL; } |
93 | 89 |
94 // Is this a URL? | 90 // Is this a URL? |
95 bool is_url() const { return type_ == URL; } | 91 bool is_url() const { return type_ == URL; } |
96 | 92 |
97 // Returns the favicon. In nearly all cases you should use the method | 93 // Returns the favicon. In nearly all cases you should use the method |
98 // BookmarkModel::GetFavicon rather than this. BookmarkModel::GetFavicon | 94 // BookmarkModel::GetFavicon rather than this. BookmarkModel::GetFavicon |
99 // takes care of loading the favicon if it isn't already loaded, where as | 95 // takes care of loading the favicon if it isn't already loaded, where as |
100 // this does not. | 96 // this does not. |
101 const SkBitmap& favicon() const { return favicon_; } | 97 const SkBitmap& favicon() const { return favicon_; } |
102 void set_favicon(const SkBitmap& icon) { favicon_ = icon; } | 98 void set_favicon(const SkBitmap& icon) { favicon_ = icon; } |
103 | 99 |
104 // The following methods are used by the bookmark model, and are not | 100 // The following methods are used by the bookmark model, and are not |
105 // really useful outside of it. | 101 // really useful outside of it. |
106 | 102 |
107 bool is_favicon_loaded() const { return loaded_favicon_; } | 103 bool favicon_loaded() const { return favicon_loaded_; } |
108 void set_favicon_loaded(bool value) { loaded_favicon_ = value; } | 104 void set_favicon_loaded(bool loaded) { favicon_loaded_ = loaded; } |
| 105 |
| 106 HistoryService::Handle favicon_load_handle() const { |
| 107 return favicon_load_handle_; |
| 108 } |
| 109 void set_favicon_load_handle(HistoryService::Handle handle) { |
| 110 favicon_load_handle_ = handle; |
| 111 } |
109 | 112 |
110 // Accessor method for controlling the visibility of a bookmark node/sub-tree. | 113 // Accessor method for controlling the visibility of a bookmark node/sub-tree. |
111 // Note that visibility is not propagated down the tree hierarchy so if a | 114 // Note that visibility is not propagated down the tree hierarchy so if a |
112 // parent node is marked as invisible, a child node may return "Visible". This | 115 // parent node is marked as invisible, a child node may return "Visible". This |
113 // function is primarily useful when traversing the model to generate a UI | 116 // function is primarily useful when traversing the model to generate a UI |
114 // representation but we may want to suppress some nodes. | 117 // representation but we may want to suppress some nodes. |
115 // TODO(yfriedman): Remove this when enable-synced-bookmarks-folder is | 118 // TODO(yfriedman): Remove this when enable-synced-bookmarks-folder is |
116 // no longer a command line flag. | 119 // no longer a command line flag. |
117 bool IsVisible() const; | 120 bool IsVisible() const; |
118 | 121 |
119 HistoryService::Handle favicon_load_handle() const { | |
120 return favicon_load_handle_; | |
121 } | |
122 void set_favicon_load_handle(HistoryService::Handle handle) { | |
123 favicon_load_handle_ = handle; | |
124 } | |
125 | |
126 // Called when the favicon becomes invalid. | 122 // Called when the favicon becomes invalid. |
127 void InvalidateFavicon(); | 123 void InvalidateFavicon(); |
128 | 124 |
129 // TODO(sky): Consider adding last visit time here, it'll greatly simplify | 125 // TODO(sky): Consider adding last visit time here, it'll greatly simplify |
130 // HistoryContentsProvider. | 126 // HistoryContentsProvider. |
131 | 127 |
132 private: | 128 private: |
133 friend class BookmarkModel; | 129 friend class BookmarkModel; |
134 | 130 |
135 // Helper to initialize various fields during construction. | 131 // A helper function to initialize some of the variables below. |
136 void Initialize(int64 id); | 132 void Initialize(int64 id); |
137 | 133 |
138 // Unique identifier for this node. | 134 // The unique identifier for this node. |
139 int64 id_; | 135 int64 id_; |
140 | 136 |
| 137 // The URL of this node. BookmarkModel maintains maps off this URL, so changes |
| 138 // changes to the URL should be done through the BookmarkModel. |
| 139 GURL url_; |
| 140 |
| 141 // The type of this node. See enum above. |
| 142 Type type_; |
| 143 |
| 144 // Date of when this node was created. |
| 145 base::Time date_added_; |
| 146 |
| 147 // Date of the last modification. Only used for folders. |
| 148 base::Time date_folder_modified_; |
| 149 |
| 150 // The favicon of this node. |
| 151 SkBitmap favicon_; |
| 152 |
141 // Whether the favicon has been loaded. | 153 // Whether the favicon has been loaded. |
142 bool loaded_favicon_; | 154 bool favicon_loaded_; |
143 | |
144 // The favicon. | |
145 SkBitmap favicon_; | |
146 | 155 |
147 // If non-zero, it indicates we're loading the favicon and this is the handle | 156 // If non-zero, it indicates we're loading the favicon and this is the handle |
148 // from the HistoryService. | 157 // from the HistoryService. |
149 HistoryService::Handle favicon_load_handle_; | 158 HistoryService::Handle favicon_load_handle_; |
150 | 159 |
151 // The URL. BookmarkModel maintains maps off this URL, it is important that | |
152 // changes to the URL is done through the bookmark model. | |
153 GURL url_; | |
154 | |
155 // Type of node. | |
156 Type type_; | |
157 | |
158 // Date we were created. | |
159 base::Time date_added_; | |
160 | |
161 // Time last modified. Only used for folders. | |
162 base::Time date_folder_modified_; | |
163 | |
164 DISALLOW_COPY_AND_ASSIGN(BookmarkNode); | 160 DISALLOW_COPY_AND_ASSIGN(BookmarkNode); |
165 }; | 161 }; |
166 | 162 |
167 // BookmarkModel -------------------------------------------------------------- | 163 // BookmarkModel -------------------------------------------------------------- |
168 | 164 |
169 // BookmarkModel provides a directed acyclic graph of the starred entries | 165 // BookmarkModel provides a directed acyclic graph of the starred entries |
170 // and folders. Two graphs are provided for the two entry points: those on | 166 // and folders. Two graphs are provided for the two entry points: those on |
171 // the bookmark bar, and those in the other folder. | 167 // the bookmark bar, and those in the other folder. |
172 // | 168 // |
173 // An observer may be attached to observer relevant events. | 169 // An observer may be attached to observer relevant events. |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 scoped_refptr<BookmarkStorage> store_; | 464 scoped_refptr<BookmarkStorage> store_; |
469 | 465 |
470 scoped_ptr<BookmarkIndex> index_; | 466 scoped_ptr<BookmarkIndex> index_; |
471 | 467 |
472 base::WaitableEvent loaded_signal_; | 468 base::WaitableEvent loaded_signal_; |
473 | 469 |
474 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); | 470 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); |
475 }; | 471 }; |
476 | 472 |
477 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_ | 473 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_ |
OLD | NEW |