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

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: Fix compilation of unit tests 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
« no previous file with comments | « chrome/browser/bookmarks/bookmark_index.cc ('k') | chrome/browser/bookmarks/bookmark_model.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/task/cancelable_task_tracker.h"
21 #include "chrome/browser/bookmarks/bookmark_service.h" 21 #include "chrome/browser/bookmarks/bookmark_service.h"
22 #include "components/bookmarks/core/browser/bookmark_client.h"
22 #include "components/bookmarks/core/browser/bookmark_node.h" 23 #include "components/bookmarks/core/browser/bookmark_node.h"
23 #include "components/favicon_base/favicon_types.h"
24 #include "components/keyed_service/core/keyed_service.h" 24 #include "components/keyed_service/core/keyed_service.h"
25 #include "content/public/browser/notification_observer.h" 25 #include "content/public/browser/notification_observer.h"
26 #include "content/public/browser/notification_registrar.h" 26 #include "content/public/browser/notification_registrar.h"
27 #include "ui/gfx/image/image.h" 27 #include "ui/gfx/image/image.h"
28 #include "url/gurl.h" 28 #include "url/gurl.h"
29 29
30 class BookmarkExpandedStateTracker; 30 class BookmarkExpandedStateTracker;
31 class BookmarkIndex; 31 class BookmarkIndex;
32 class BookmarkLoadDetails; 32 class BookmarkLoadDetails;
33 class BookmarkModelObserver; 33 class BookmarkModelObserver;
34 class BookmarkStorage; 34 class BookmarkStorage;
35 struct BookmarkTitleMatch; 35 struct BookmarkTitleMatch;
36 class PrefService;
36 class Profile; 37 class Profile;
37 class ScopedGroupBookmarkActions; 38 class ScopedGroupBookmarkActions;
38 39
39 namespace base { 40 namespace base {
41 class FilePath;
40 class SequencedTaskRunner; 42 class SequencedTaskRunner;
41 } 43 }
42 44
43 namespace chrome {
44 struct FaviconImageResult;
45 }
46
47 // BookmarkModel -------------------------------------------------------------- 45 // BookmarkModel --------------------------------------------------------------
48 46
49 // BookmarkModel provides a directed acyclic graph of URLs and folders. 47 // BookmarkModel provides a directed acyclic graph of URLs and folders.
50 // Three graphs are provided for the three entry points: those on the 'bookmarks 48 // 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. 49 // bar', those in the 'other bookmarks' folder and those in the 'mobile' folder.
52 // 50 //
53 // An observer may be attached to observe relevant events. 51 // An observer may be attached to observe relevant events.
54 // 52 //
55 // You should NOT directly create a BookmarkModel, instead go through the 53 // You should NOT directly create a BookmarkModel, instead go through the
56 // BookmarkModelFactory. 54 // BookmarkModelFactory.
57 class BookmarkModel : public content::NotificationObserver, 55 class BookmarkModel : public BookmarkService {
58 public BookmarkService,
59 public KeyedService {
60 public: 56 public:
61 explicit BookmarkModel(Profile* profile); 57 explicit BookmarkModel(BookmarkClient* client);
62 virtual ~BookmarkModel(); 58 virtual ~BookmarkModel();
63 59
64 // Invoked prior to destruction to release any necessary resources. 60 // Invoked prior to destruction to release any necessary resources.
65 virtual void Shutdown() OVERRIDE; 61 void Shutdown();
66 62
67 // Loads the bookmarks. This is called upon creation of the 63 // Loads the bookmarks. This is called upon creation of the
68 // BookmarkModel. You need not invoke this directly. 64 // BookmarkModel. You need not invoke this directly.
69 // All load operations will be executed on |task_runner|. 65 // All load operations will be executed on |io_task_runner|, and callback
70 void Load(const scoped_refptr<base::SequencedTaskRunner>& task_runner); 66 // will be called from |io_task_runner|.
67 void Load(PrefService* pref_service,
68 const base::FilePath& profile_path,
69 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
70 const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner);
71 71
72 // Returns true if the model finished loading. 72 // Returns true if the model finished loading.
73 bool loaded() const { return loaded_; } 73 bool loaded() const { return loaded_; }
74 74
75 // Returns the root node. The 'bookmark bar' node and 'other' node are 75 // Returns the root node. The 'bookmark bar' node and 'other' node are
76 // children of the root node. 76 // children of the root node.
77 const BookmarkNode* root_node() { return &root_; } 77 const BookmarkNode* root_node() { return &root_; }
78 78
79 // Returns the 'bookmark bar' node. This is NULL until loaded. 79 // Returns the 'bookmark bar' node. This is NULL until loaded.
80 const BookmarkNode* bookmark_bar_node() { return bookmark_bar_node_; } 80 const BookmarkNode* bookmark_bar_node() { return bookmark_bar_node_; }
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 const std::string& value); 241 const std::string& value);
242 void SetNodeMetaInfoMap(const BookmarkNode* node, 242 void SetNodeMetaInfoMap(const BookmarkNode* node,
243 const BookmarkNode::MetaInfoMap& meta_info_map); 243 const BookmarkNode::MetaInfoMap& meta_info_map);
244 void DeleteNodeMetaInfo(const BookmarkNode* node, 244 void DeleteNodeMetaInfo(const BookmarkNode* node,
245 const std::string& key); 245 const std::string& key);
246 246
247 // Sets the sync transaction version of |node|. 247 // Sets the sync transaction version of |node|.
248 void SetNodeSyncTransactionVersion(const BookmarkNode* node, 248 void SetNodeSyncTransactionVersion(const BookmarkNode* node,
249 int64 sync_transaction_version); 249 int64 sync_transaction_version);
250 250
251 // Returns the profile that corresponds to this BookmarkModel. 251 // Returns the BookmarkClient that corresponds to this BookmarkModel.
252 Profile* profile() { return profile_; } 252 BookmarkClient* client() { return client_; }
253
254 void OnFaviconChanged(const std::set<GURL>& urls);
253 255
254 private: 256 private:
255 friend class BookmarkCodecTest; 257 friend class BookmarkCodecTest;
256 friend class BookmarkModelTest; 258 friend class BookmarkModelTest;
257 friend class BookmarkStorage; 259 friend class BookmarkStorage;
258 friend class ScopedGroupBookmarkActions; 260 friend class ScopedGroupBookmarkActions;
259 261
260 // Used to order BookmarkNodes by URL. 262 // Used to order BookmarkNodes by URL.
261 class NodeURLComparator { 263 class NodeURLComparator {
262 public: 264 public:
(...skipping 26 matching lines...) Expand all
289 void RemoveNodeAndGetRemovedUrls(BookmarkNode* node, 291 void RemoveNodeAndGetRemovedUrls(BookmarkNode* node,
290 std::set<GURL>* removed_urls); 292 std::set<GURL>* removed_urls);
291 293
292 // Removes the node from its parent, sends notification, and deletes it. 294 // Removes the node from its parent, sends notification, and deletes it.
293 // type specifies how the node should be removed. 295 // type specifies how the node should be removed.
294 void RemoveAndDeleteNode(BookmarkNode* delete_me); 296 void RemoveAndDeleteNode(BookmarkNode* delete_me);
295 297
296 // Remove |node| from |nodes_ordered_by_url_set_|. 298 // Remove |node| from |nodes_ordered_by_url_set_|.
297 void RemoveNodeFromURLSet(BookmarkNode* node); 299 void RemoveNodeFromURLSet(BookmarkNode* node);
298 300
299 // Notifies the history backend about urls of removed bookmarks.
300 void NotifyHistoryAboutRemovedBookmarks(
301 const std::set<GURL>& removed_bookmark_urls) const;
302
303 // Adds the |node| at |parent| in the specified |index| and notifies its 301 // Adds the |node| at |parent| in the specified |index| and notifies its
304 // observers. 302 // observers.
305 BookmarkNode* AddNode(BookmarkNode* parent, 303 BookmarkNode* AddNode(BookmarkNode* parent,
306 int index, 304 int index,
307 BookmarkNode* node); 305 BookmarkNode* node);
308 306
309 // Implementation of GetNodeByID. 307 // Implementation of GetNodeByID.
310 const BookmarkNode* GetNodeByID(const BookmarkNode* node, int64 id) const; 308 const BookmarkNode* GetNodeByID(const BookmarkNode* node, int64 id) const;
311 309
312 // Returns true if the parent and index are valid. 310 // Returns true if the parent and index are valid.
(...skipping 17 matching lines...) Expand all
330 void FaviconLoaded(const BookmarkNode* node); 328 void FaviconLoaded(const BookmarkNode* node);
331 329
332 // If we're waiting on a favicon for node, the load request is canceled. 330 // If we're waiting on a favicon for node, the load request is canceled.
333 void CancelPendingFaviconLoadRequests(BookmarkNode* node); 331 void CancelPendingFaviconLoadRequests(BookmarkNode* node);
334 332
335 // Notifies the observers that a set of changes initiated by a single user 333 // Notifies the observers that a set of changes initiated by a single user
336 // action is about to happen and has completed. 334 // action is about to happen and has completed.
337 void BeginGroupedChanges(); 335 void BeginGroupedChanges();
338 void EndGroupedChanges(); 336 void EndGroupedChanges();
339 337
340 // content::NotificationObserver:
341 virtual void Observe(int type,
342 const content::NotificationSource& source,
343 const content::NotificationDetails& details) OVERRIDE;
344
345 // Generates and returns the next node ID. 338 // Generates and returns the next node ID.
346 int64 generate_next_node_id(); 339 int64 generate_next_node_id();
347 340
348 // Sets the maximum node ID to the given value. 341 // Sets the maximum node ID to the given value.
349 // This is used by BookmarkCodec to report the maximum ID after it's done 342 // This is used by BookmarkCodec to report the maximum ID after it's done
350 // decoding since during decoding codec assigns node IDs. 343 // decoding since during decoding codec assigns node IDs.
351 void set_next_node_id(int64 id) { next_node_id_ = id; } 344 void set_next_node_id(int64 id) { next_node_id_ = id; }
352 345
353 // Creates and returns a new BookmarkLoadDetails. It's up to the caller to 346 // Creates and returns a new BookmarkLoadDetails. It's up to the caller to
354 // delete the returned object. 347 // delete the returned object.
355 BookmarkLoadDetails* CreateLoadDetails(); 348 BookmarkLoadDetails* CreateLoadDetails();
356 349
357 content::NotificationRegistrar registrar_; 350 BookmarkClient* client_;
358
359 Profile* profile_;
360 351
361 // Whether the initial set of data has been loaded. 352 // Whether the initial set of data has been loaded.
362 bool loaded_; 353 bool loaded_;
363 354
364 // The root node. This contains the bookmark bar node and the 'other' node as 355 // The root node. This contains the bookmark bar node and the 'other' node as
365 // children. 356 // children.
366 BookmarkNode root_; 357 BookmarkNode root_;
367 358
368 BookmarkPermanentNode* bookmark_bar_node_; 359 BookmarkPermanentNode* bookmark_bar_node_;
369 BookmarkPermanentNode* other_node_; 360 BookmarkPermanentNode* other_node_;
(...skipping 24 matching lines...) Expand all
394 base::WaitableEvent loaded_signal_; 385 base::WaitableEvent loaded_signal_;
395 386
396 // See description of IsDoingExtensiveChanges above. 387 // See description of IsDoingExtensiveChanges above.
397 int extensive_changes_; 388 int extensive_changes_;
398 389
399 scoped_ptr<BookmarkExpandedStateTracker> expanded_state_tracker_; 390 scoped_ptr<BookmarkExpandedStateTracker> expanded_state_tracker_;
400 391
401 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); 392 DISALLOW_COPY_AND_ASSIGN(BookmarkModel);
402 }; 393 };
403 394
395 class ChromeBookmarkClient : public content::NotificationObserver,
tfarina 2014/04/22 17:22:34 No, don't do that. Instead move this class declara
sdefresne 2014/04/22 20:25:49 Done.
396 public BookmarkClient,
tfarina 2014/04/22 17:22:34 Can you make BookmarkClient be the first in the in
sdefresne 2014/04/22 20:25:49 Done.
397 public KeyedService {
398 public:
399 ChromeBookmarkClient(Profile* profile);
tfarina 2014/04/22 17:22:34 explicit
sdefresne 2014/04/22 20:25:49 Done.
400 virtual ~ChromeBookmarkClient();
401
402 // Returns the BookmarkModel that corresponds to this ChromeBookmarkClient.
403 BookmarkModel* model() { return model_.get(); }
404
405 // Returns the Profile that corresponds to this ChromeBookmarkClient.
406 Profile* profile() { return profile_; }
407
408 // KeyedService:
409 virtual void Shutdown() OVERRIDE;
tfarina 2014/04/22 17:22:34 Please, make sure the overrides follow the same se
sdefresne 2014/04/22 20:25:49 Done.
410
411 // content::NotificationObserver:
412 virtual void Observe(int type,
413 const content::NotificationSource& source,
414 const content::NotificationDetails& details) OVERRIDE;
415
416 // BookmarkClient:
417 virtual void OnLoad() OVERRIDE;
418
tfarina 2014/04/22 17:22:34 Do not put blank lines between these overrides. We
sdefresne 2014/04/22 20:25:49 Done.
419 virtual void OnClearStore() OVERRIDE;
420
421 virtual void NotifyHistoryAboutRemovedBookmarks(
422 const std::set<GURL>& removed_bookmarks_urls) const OVERRIDE;
423
424 virtual base::CancelableTaskTracker::TaskId GetFaviconImageForURL(
425 const GURL& page_url,
426 int icon_types,
427 int desired_size_in_dip,
428 const FaviconImageCallback& callback,
429 base::CancelableTaskTracker* tracker) OVERRIDE;
430
431 virtual bool SupportsTypedCountForNodes() OVERRIDE;
432
433 virtual void GetTypedCountForNodes(
434 const NodeSet& nodes,
435 NodeTypedCountPairs* node_typed_count_pairs) OVERRIDE;
436
437 virtual void RecordAction(const base::UserMetricsAction& action) OVERRIDE;
438
439 private:
440 Profile* profile_;
441
442 content::NotificationRegistrar registrar_;
443
444 scoped_ptr<BookmarkModel> model_;
445
446 DISALLOW_COPY_AND_ASSIGN(ChromeBookmarkClient);
447 };
448
404 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_ 449 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_index.cc ('k') | chrome/browser/bookmarks/bookmark_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698