OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_ANDROID_PARTNER_BOOKMARKS_SHIM_H_ | |
6 #define CHROME_BROWSER_ANDROID_PARTNER_BOOKMARKS_SHIM_H_ | |
7 | |
8 #include "base/android/jni_helper.h" | |
9 // scoped_ptr requires complete class BookmarkNode, so we don't forward declare | |
Yaron
2012/08/08 22:54:55
This comment seems unnecessary.
Ted C
2012/08/08 23:01:48
Done.
| |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "chrome/browser/bookmarks/bookmark_model.h" | |
12 | |
13 // A shim that lives on top of a BookmarkModel that allows the injection of | |
14 // Partner bookmarks without submitting changes to the user configured bookmark | |
15 // model. | |
16 // Partner bookmarks folder is pseudo-injected as a subfolder to "attach node". | |
17 // Because we cannot modify the BookmarkModel, the following needs to | |
18 // be done on a client side: | |
19 // 1. bookmark_node->is_root() -> shim->IsRootNode(bookmark_node) | |
20 // 2. bookmark_node->parent() -> shim->GetParentOf(bookmark_node) | |
21 // 3. bookmark_model->GetNodeByID(id) -> shim->GetNodeByID(id) | |
22 class PartnerBookmarksShim { | |
23 public: | |
24 // The mask used to determining if an ID is a partner bookmark. When | |
25 // constructing partner bookmarks, ensure the IDs are based on this value. | |
26 static const int64 kPartnerBookmarkIdBits; | |
27 | |
28 // Returns the active instance of the shim. | |
29 static PartnerBookmarksShim* GetInstance(); | |
30 | |
31 // Constructor is public for LazyInstance; DON'T CALL; use ::GetInstance(). | |
32 PartnerBookmarksShim(); | |
33 // Destructor is public for LazyInstance; | |
34 ~PartnerBookmarksShim(); | |
35 void Reset(); | |
36 | |
37 // Pseudo-injects partner bookmarks (if any) under the "attach_node". | |
38 void AttachTo(BookmarkModel* bookmark_model, | |
39 const BookmarkNode* attach_node); | |
40 // Returns true if everything got loaded and attached | |
41 bool IsLoaded() const; | |
42 // Returns true if there are partner bookmarks | |
43 bool HasPartnerBookmarks() const; | |
44 | |
45 // For "Loaded" and "ShimBeingDeleted" notifications | |
46 struct Observer { | |
47 // Called when everything is loaded and attached | |
48 virtual void PartnerShimLoaded(PartnerBookmarksShim*) {} | |
49 // Called just before everything got destroyed | |
50 virtual void ShimBeingDeleted(PartnerBookmarksShim*) {} | |
51 protected: | |
52 virtual ~Observer() {} | |
53 }; | |
54 void AddObserver(Observer* observer); | |
55 void RemoveObserver(Observer* observer); | |
56 | |
57 // Replacements for BookmarkModel/BookmarkNode methods | |
58 static bool IsBookmarkEditable(const BookmarkNode* node); | |
59 bool IsRootNode(const BookmarkNode* node) const; | |
60 const BookmarkNode* GetNodeByID(int64 id) const; | |
61 const BookmarkNode* GetParentOf(const BookmarkNode* node) const; | |
62 const BookmarkNode* GetAttachPoint() const { return attach_point_; } | |
63 static bool IsPartnerBookmarkId(int64 id); | |
64 const BookmarkNode* GetPartnerBookmarksRoot() const; | |
65 // Sets the root node of the partner bookmarks and notifies any observers that | |
66 // the shim has now been loaded. Takes ownership of |root_node|. | |
67 void SetPartnerBookmarksRoot(BookmarkNode* root_node); | |
68 | |
69 private: | |
70 const BookmarkNode* GetNodeByID(const BookmarkNode* parent, int64 id) const; | |
71 | |
72 scoped_ptr<BookmarkNode> partner_bookmarks_root_; | |
73 BookmarkModel* bookmark_model_; | |
74 const BookmarkNode* attach_point_; | |
75 bool loaded_; // Set only on UI thread | |
76 | |
77 // The observers. | |
78 ObserverList<Observer> observers_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(PartnerBookmarksShim); | |
81 }; | |
82 | |
83 #endif // CHROME_BROWSER_ANDROID_PARTNER_BOOKMARKS_SHIM_H_ | |
OLD | NEW |