OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ | 5 #ifndef COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ |
6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ | 6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
19 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
20 #include "components/bookmarks/browser/bookmark_client.h" | 20 #include "components/bookmarks/browser/bookmark_client.h" |
21 #include "components/bookmarks/browser/bookmark_node.h" | 21 #include "components/bookmarks/browser/bookmark_node.h" |
22 #include "components/bookmarks/browser/bookmark_service.h" | |
23 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
24 #include "url/gurl.h" | 23 #include "url/gurl.h" |
25 | 24 |
26 class BookmarkExpandedStateTracker; | 25 class BookmarkExpandedStateTracker; |
27 class BookmarkModelObserver; | 26 class BookmarkModelObserver; |
28 struct BookmarkMatch; | 27 struct BookmarkMatch; |
29 class PrefService; | 28 class PrefService; |
30 class ScopedGroupBookmarkActions; | 29 class ScopedGroupBookmarkActions; |
31 | 30 |
32 namespace base { | 31 namespace base { |
(...skipping 19 matching lines...) Expand all Loading... |
52 // BookmarkModel -------------------------------------------------------------- | 51 // BookmarkModel -------------------------------------------------------------- |
53 | 52 |
54 // BookmarkModel provides a directed acyclic graph of URLs and folders. | 53 // BookmarkModel provides a directed acyclic graph of URLs and folders. |
55 // Three graphs are provided for the three entry points: those on the 'bookmarks | 54 // Three graphs are provided for the three entry points: those on the 'bookmarks |
56 // bar', those in the 'other bookmarks' folder and those in the 'mobile' folder. | 55 // bar', those in the 'other bookmarks' folder and those in the 'mobile' folder. |
57 // | 56 // |
58 // An observer may be attached to observe relevant events. | 57 // An observer may be attached to observe relevant events. |
59 // | 58 // |
60 // You should NOT directly create a BookmarkModel, instead go through the | 59 // You should NOT directly create a BookmarkModel, instead go through the |
61 // BookmarkModelFactory. | 60 // BookmarkModelFactory. |
62 class BookmarkModel : public BookmarkService { | 61 class BookmarkModel { |
63 public: | 62 public: |
| 63 struct URLAndTitle { |
| 64 GURL url; |
| 65 base::string16 title; |
| 66 }; |
| 67 |
64 // |index_urls| says whether URLs should be stored in the BookmarkIndex | 68 // |index_urls| says whether URLs should be stored in the BookmarkIndex |
65 // in addition to bookmark titles. | 69 // in addition to bookmark titles. |
66 BookmarkModel(BookmarkClient* client, bool index_urls); | 70 BookmarkModel(BookmarkClient* client, bool index_urls); |
67 virtual ~BookmarkModel(); | 71 ~BookmarkModel(); |
68 | 72 |
69 // Invoked prior to destruction to release any necessary resources. | 73 // Invoked prior to destruction to release any necessary resources. |
70 void Shutdown(); | 74 void Shutdown(); |
71 | 75 |
72 // Loads the bookmarks. This is called upon creation of the | 76 // Loads the bookmarks. This is called upon creation of the |
73 // BookmarkModel. You need not invoke this directly. | 77 // BookmarkModel. You need not invoke this directly. |
74 // All load operations will be executed on |io_task_runner| and the completion | 78 // All load operations will be executed on |io_task_runner| and the completion |
75 // callback will be called from |ui_task_runner|. | 79 // callback will be called from |ui_task_runner|. |
76 void Load(PrefService* pref_service, | 80 void Load(PrefService* pref_service, |
77 const std::string& accept_languages, | 81 const std::string& accept_languages, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 void GetNodesByURL(const GURL& url, std::vector<const BookmarkNode*>* nodes); | 169 void GetNodesByURL(const GURL& url, std::vector<const BookmarkNode*>* nodes); |
166 | 170 |
167 // Returns the most recently added node for the |url|. Returns NULL if |url| | 171 // Returns the most recently added node for the |url|. Returns NULL if |url| |
168 // is not bookmarked. | 172 // is not bookmarked. |
169 const BookmarkNode* GetMostRecentlyAddedNodeForURL(const GURL& url); | 173 const BookmarkNode* GetMostRecentlyAddedNodeForURL(const GURL& url); |
170 | 174 |
171 // Returns true if there are bookmarks, otherwise returns false. | 175 // Returns true if there are bookmarks, otherwise returns false. |
172 // This method is thread safe. | 176 // This method is thread safe. |
173 bool HasBookmarks(); | 177 bool HasBookmarks(); |
174 | 178 |
175 // Returns true if there is a bookmark with the |url|. | 179 // Returns true if the specified URL is bookmarked. |
176 // This method is thread safe. | 180 // |
177 // See BookmarkService for more details on this. | 181 // If not on the main thread you *must* invoke BlockTillLoaded first. |
178 virtual bool IsBookmarked(const GURL& url) OVERRIDE; | 182 bool IsBookmarked(const GURL& url); |
179 | 183 |
180 // Returns all the bookmarked urls and their titles. | 184 // Returns, by reference in |bookmarks|, the set of bookmarked urls and their |
181 // This method is thread safe. | 185 // titles. This returns the unique set of URLs. For example, if two bookmarks |
182 // See BookmarkService for more details on this. | 186 // reference the same URL only one entry is added not matter the titles are |
183 virtual void GetBookmarks( | 187 // same or not. |
184 std::vector<BookmarkService::URLAndTitle>* urls) OVERRIDE; | 188 // |
| 189 // If not on the main thread you *must* invoke BlockTillLoaded first. |
| 190 void GetBookmarks(std::vector<BookmarkModel::URLAndTitle>* urls); |
185 | 191 |
186 // Blocks until loaded; this is NOT invoked on the main thread. | 192 // Blocks until loaded. This is intended for usage on a thread other than |
187 // See BookmarkService for more details on this. | 193 // the main thread. |
188 virtual void BlockTillLoaded() OVERRIDE; | 194 void BlockTillLoaded(); |
189 | 195 |
190 // Adds a new folder node at the specified position. | 196 // Adds a new folder node at the specified position. |
191 const BookmarkNode* AddFolder(const BookmarkNode* parent, | 197 const BookmarkNode* AddFolder(const BookmarkNode* parent, |
192 int index, | 198 int index, |
193 const base::string16& title); | 199 const base::string16& title); |
194 | 200 |
195 // Adds a new folder with meta info. | 201 // Adds a new folder with meta info. |
196 const BookmarkNode* AddFolderWithMetaInfo( | 202 const BookmarkNode* AddFolderWithMetaInfo( |
197 const BookmarkNode* parent, | 203 const BookmarkNode* parent, |
198 int index, | 204 int index, |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 | 425 |
420 // See description of IsDoingExtensiveChanges above. | 426 // See description of IsDoingExtensiveChanges above. |
421 int extensive_changes_; | 427 int extensive_changes_; |
422 | 428 |
423 scoped_ptr<BookmarkExpandedStateTracker> expanded_state_tracker_; | 429 scoped_ptr<BookmarkExpandedStateTracker> expanded_state_tracker_; |
424 | 430 |
425 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); | 431 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); |
426 }; | 432 }; |
427 | 433 |
428 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ | 434 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ |
OLD | NEW |