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