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