Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(493)

Side by Side Diff: chrome/browser/bookmarks/bookmark_model.h

Issue 242693003: Introduce BookmarkClient interface to abstract embedder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Work around STL android bug Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 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 "base/task/cancelable_task_tracker.h" 20 #include "components/bookmarks/core/browser/bookmark_client.h"
21 #include "components/bookmarks/core/browser/bookmark_node.h" 21 #include "components/bookmarks/core/browser/bookmark_node.h"
22 #include "components/bookmarks/core/browser/bookmark_service.h" 22 #include "components/bookmarks/core/browser/bookmark_service.h"
23 #include "components/favicon_base/favicon_types.h"
24 #include "components/keyed_service/core/keyed_service.h"
25 #include "content/public/browser/notification_observer.h"
26 #include "content/public/browser/notification_registrar.h"
27 #include "ui/gfx/image/image.h" 23 #include "ui/gfx/image/image.h"
28 #include "url/gurl.h" 24 #include "url/gurl.h"
29 25
30 class BookmarkExpandedStateTracker; 26 class BookmarkExpandedStateTracker;
31 class BookmarkIndex; 27 class BookmarkIndex;
32 class BookmarkLoadDetails; 28 class BookmarkLoadDetails;
33 class BookmarkModelObserver; 29 class BookmarkModelObserver;
34 class BookmarkStorage; 30 class BookmarkStorage;
35 struct BookmarkMatch; 31 struct BookmarkMatch;
36 class Profile; 32 class PrefService;
37 class ScopedGroupBookmarkActions; 33 class ScopedGroupBookmarkActions;
38 34
39 namespace base { 35 namespace base {
36 class FilePath;
40 class SequencedTaskRunner; 37 class SequencedTaskRunner;
41 } 38 }
42 39
43 namespace chrome { 40 namespace favicon_base {
44 struct FaviconImageResult; 41 struct FaviconImageResult;
45 } 42 }
46 43
44 namespace test {
45 class TestBookmarkClient;
46 }
47
47 // BookmarkModel -------------------------------------------------------------- 48 // BookmarkModel --------------------------------------------------------------
48 49
49 // BookmarkModel provides a directed acyclic graph of URLs and folders. 50 // BookmarkModel provides a directed acyclic graph of URLs and folders.
50 // Three graphs are provided for the three entry points: those on the 'bookmarks 51 // Three graphs are provided for the three entry points: those on the 'bookmarks
51 // bar', those in the 'other bookmarks' folder and those in the 'mobile' folder. 52 // bar', those in the 'other bookmarks' folder and those in the 'mobile' folder.
52 // 53 //
53 // An observer may be attached to observe relevant events. 54 // An observer may be attached to observe relevant events.
54 // 55 //
55 // You should NOT directly create a BookmarkModel, instead go through the 56 // You should NOT directly create a BookmarkModel, instead go through the
56 // BookmarkModelFactory. 57 // BookmarkModelFactory.
57 class BookmarkModel : public content::NotificationObserver, 58 class BookmarkModel : public BookmarkService {
58 public BookmarkService,
59 public KeyedService {
60 public: 59 public:
61 // |index_urls| says whether URLs should be stored in the BookmarkIndex 60 // |index_urls| says whether URLs should be stored in the BookmarkIndex
62 // in addition to bookmark titles. 61 // in addition to bookmark titles.
63 BookmarkModel(Profile* profile, bool index_urls); 62 BookmarkModel(BookmarkClient* client, bool index_urls);
64 virtual ~BookmarkModel(); 63 virtual ~BookmarkModel();
65 64
66 // Invoked prior to destruction to release any necessary resources. 65 // Invoked prior to destruction to release any necessary resources.
67 virtual void Shutdown() OVERRIDE; 66 void Shutdown();
68 67
69 // Loads the bookmarks. This is called upon creation of the 68 // Loads the bookmarks. This is called upon creation of the
70 // BookmarkModel. You need not invoke this directly. 69 // BookmarkModel. You need not invoke this directly.
71 // All load operations will be executed on |task_runner|. 70 // All load operations will be executed on |io_task_runner| and the completion
72 void Load(const scoped_refptr<base::SequencedTaskRunner>& task_runner); 71 // callback will be called from |ui_task_runner|.
72 void Load(PrefService* pref_service,
73 const std::string& accept_languages,
74 const base::FilePath& profile_path,
75 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
76 const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner);
73 77
74 // Returns true if the model finished loading. 78 // Returns true if the model finished loading.
75 bool loaded() const { return loaded_; } 79 bool loaded() const { return loaded_; }
76 80
77 // Returns the root node. The 'bookmark bar' node and 'other' node are 81 // Returns the root node. The 'bookmark bar' node and 'other' node are
78 // children of the root node. 82 // children of the root node.
79 const BookmarkNode* root_node() const { return &root_; } 83 const BookmarkNode* root_node() const { return &root_; }
80 84
81 // Returns the 'bookmark bar' node. This is NULL until loaded. 85 // Returns the 'bookmark bar' node. This is NULL until loaded.
82 const BookmarkNode* bookmark_bar_node() const { return bookmark_bar_node_; } 86 const BookmarkNode* bookmark_bar_node() const { return bookmark_bar_node_; }
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 const std::string& value); 255 const std::string& value);
252 void SetNodeMetaInfoMap(const BookmarkNode* node, 256 void SetNodeMetaInfoMap(const BookmarkNode* node,
253 const BookmarkNode::MetaInfoMap& meta_info_map); 257 const BookmarkNode::MetaInfoMap& meta_info_map);
254 void DeleteNodeMetaInfo(const BookmarkNode* node, 258 void DeleteNodeMetaInfo(const BookmarkNode* node,
255 const std::string& key); 259 const std::string& key);
256 260
257 // Sets the sync transaction version of |node|. 261 // Sets the sync transaction version of |node|.
258 void SetNodeSyncTransactionVersion(const BookmarkNode* node, 262 void SetNodeSyncTransactionVersion(const BookmarkNode* node,
259 int64 sync_transaction_version); 263 int64 sync_transaction_version);
260 264
261 // Returns the profile that corresponds to this BookmarkModel. 265 // Notify BookmarkModel that the favicons for |urls| have changed and have to
262 Profile* profile() { return profile_; } 266 // be refetched. This notification is sent by BookmarkClient.
267 void OnFaviconChanged(const std::set<GURL>& urls);
268
269 // Returns the client used by this BookmarkModel.
270 BookmarkClient* client() const { return client_; }
263 271
264 private: 272 private:
265 friend class BookmarkCodecTest; 273 friend class BookmarkCodecTest;
266 friend class BookmarkModelTest; 274 friend class BookmarkModelTest;
267 friend class BookmarkStorage; 275 friend class BookmarkStorage;
268 friend class ScopedGroupBookmarkActions; 276 friend class ScopedGroupBookmarkActions;
277 friend class test::TestBookmarkClient;
269 278
270 // Used to order BookmarkNodes by URL. 279 // Used to order BookmarkNodes by URL.
271 class NodeURLComparator { 280 class NodeURLComparator {
272 public: 281 public:
273 bool operator()(const BookmarkNode* n1, const BookmarkNode* n2) const { 282 bool operator()(const BookmarkNode* n1, const BookmarkNode* n2) const {
274 return n1->url() < n2->url(); 283 return n1->url() < n2->url();
275 } 284 }
276 }; 285 };
277 286
278 // Implementation of IsBookmarked. Before calling this the caller must obtain 287 // Implementation of IsBookmarked. Before calling this the caller must obtain
279 // a lock on |url_lock_|. 288 // a lock on |url_lock_|.
280 bool IsBookmarkedNoLock(const GURL& url); 289 bool IsBookmarkedNoLock(const GURL& url);
281 290
282 // Removes the node from internal maps and recurses through all children. If 291 // Removes the node from internal maps and recurses through all children. If
283 // the node is a url, its url is added to removed_urls. 292 // the node is a url, its url is added to removed_urls.
284 // 293 //
285 // This does NOT delete the node. 294 // This does NOT delete the node.
286 void RemoveNode(BookmarkNode* node, std::set<GURL>* removed_urls); 295 void RemoveNode(BookmarkNode* node, std::set<GURL>* removed_urls);
287 296
288 // Invoked when loading is finished. Sets |loaded_| and notifies observers. 297 // Invoked when loading is finished. Sets |loaded_| and notifies observers.
289 // BookmarkModel takes ownership of |details|. 298 // BookmarkModel takes ownership of |details|.
290 void DoneLoading(BookmarkLoadDetails* details); 299 void DoneLoading(scoped_ptr<BookmarkLoadDetails> details);
291 300
292 // Populates |nodes_ordered_by_url_set_| from root. 301 // Populates |nodes_ordered_by_url_set_| from root.
293 void PopulateNodesByURL(BookmarkNode* node); 302 void PopulateNodesByURL(BookmarkNode* node);
294 303
295 // Removes the node from its parent, but does not delete it. No notifications 304 // Removes the node from its parent, but does not delete it. No notifications
296 // are sent. |removed_urls| is populated with the urls which no longer have 305 // are sent. |removed_urls| is populated with the urls which no longer have
297 // any bookmarks associated with them. 306 // any bookmarks associated with them.
298 // This method should be called after acquiring |url_lock_|. 307 // This method should be called after acquiring |url_lock_|.
299 void RemoveNodeAndGetRemovedUrls(BookmarkNode* node, 308 void RemoveNodeAndGetRemovedUrls(BookmarkNode* node,
300 std::set<GURL>* removed_urls); 309 std::set<GURL>* removed_urls);
301 310
302 // Removes the node from its parent, sends notification, and deletes it. 311 // Removes the node from its parent, sends notification, and deletes it.
303 // type specifies how the node should be removed. 312 // type specifies how the node should be removed.
304 void RemoveAndDeleteNode(BookmarkNode* delete_me); 313 void RemoveAndDeleteNode(BookmarkNode* delete_me);
305 314
306 // Remove |node| from |nodes_ordered_by_url_set_|. 315 // Remove |node| from |nodes_ordered_by_url_set_|.
307 void RemoveNodeFromURLSet(BookmarkNode* node); 316 void RemoveNodeFromURLSet(BookmarkNode* node);
308 317
309 // Notifies the history backend about urls of removed bookmarks.
310 void NotifyHistoryAboutRemovedBookmarks(
311 const std::set<GURL>& removed_bookmark_urls) const;
312
313 // Adds the |node| at |parent| in the specified |index| and notifies its 318 // Adds the |node| at |parent| in the specified |index| and notifies its
314 // observers. 319 // observers.
315 BookmarkNode* AddNode(BookmarkNode* parent, 320 BookmarkNode* AddNode(BookmarkNode* parent,
316 int index, 321 int index,
317 BookmarkNode* node); 322 BookmarkNode* node);
318 323
319 // Returns true if the parent and index are valid. 324 // Returns true if the parent and index are valid.
320 bool IsValidIndex(const BookmarkNode* parent, int index, bool allow_end); 325 bool IsValidIndex(const BookmarkNode* parent, int index, bool allow_end);
321 326
322 // Creates one of the possible permanent nodes (bookmark bar node, other node 327 // Creates one of the possible permanent nodes (bookmark bar node, other node
(...skipping 14 matching lines...) Expand all
337 void FaviconLoaded(const BookmarkNode* node); 342 void FaviconLoaded(const BookmarkNode* node);
338 343
339 // If we're waiting on a favicon for node, the load request is canceled. 344 // If we're waiting on a favicon for node, the load request is canceled.
340 void CancelPendingFaviconLoadRequests(BookmarkNode* node); 345 void CancelPendingFaviconLoadRequests(BookmarkNode* node);
341 346
342 // Notifies the observers that a set of changes initiated by a single user 347 // Notifies the observers that a set of changes initiated by a single user
343 // action is about to happen and has completed. 348 // action is about to happen and has completed.
344 void BeginGroupedChanges(); 349 void BeginGroupedChanges();
345 void EndGroupedChanges(); 350 void EndGroupedChanges();
346 351
347 // content::NotificationObserver:
348 virtual void Observe(int type,
349 const content::NotificationSource& source,
350 const content::NotificationDetails& details) OVERRIDE;
351
352 // Generates and returns the next node ID. 352 // Generates and returns the next node ID.
353 int64 generate_next_node_id(); 353 int64 generate_next_node_id();
354 354
355 // Sets the maximum node ID to the given value. 355 // Sets the maximum node ID to the given value.
356 // This is used by BookmarkCodec to report the maximum ID after it's done 356 // This is used by BookmarkCodec to report the maximum ID after it's done
357 // decoding since during decoding codec assigns node IDs. 357 // decoding since during decoding codec assigns node IDs.
358 void set_next_node_id(int64 id) { next_node_id_ = id; } 358 void set_next_node_id(int64 id) { next_node_id_ = id; }
359 359
360 // Creates and returns a new BookmarkLoadDetails. It's up to the caller to 360 // Creates and returns a new BookmarkLoadDetails. It's up to the caller to
361 // delete the returned object. 361 // delete the returned object.
362 BookmarkLoadDetails* CreateLoadDetails(); 362 scoped_ptr<BookmarkLoadDetails> CreateLoadDetails(
363 const std::string& accept_languages);
363 364
364 content::NotificationRegistrar registrar_; 365 BookmarkClient* const client_;
365
366 Profile* profile_;
367 366
368 // Whether the initial set of data has been loaded. 367 // Whether the initial set of data has been loaded.
369 bool loaded_; 368 bool loaded_;
370 369
371 // The root node. This contains the bookmark bar node and the 'other' node as 370 // The root node. This contains the bookmark bar node and the 'other' node as
372 // children. 371 // children.
373 BookmarkNode root_; 372 BookmarkNode root_;
374 373
375 BookmarkPermanentNode* bookmark_bar_node_; 374 BookmarkPermanentNode* bookmark_bar_node_;
376 BookmarkPermanentNode* other_node_; 375 BookmarkPermanentNode* other_node_;
(...skipping 29 matching lines...) Expand all
406 405
407 // See description of IsDoingExtensiveChanges above. 406 // See description of IsDoingExtensiveChanges above.
408 int extensive_changes_; 407 int extensive_changes_;
409 408
410 scoped_ptr<BookmarkExpandedStateTracker> expanded_state_tracker_; 409 scoped_ptr<BookmarkExpandedStateTracker> expanded_state_tracker_;
411 410
412 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); 411 DISALLOW_COPY_AND_ASSIGN(BookmarkModel);
413 }; 412 };
414 413
415 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_ 414 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_index_unittest.cc ('k') | chrome/browser/bookmarks/bookmark_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698