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

Side by Side Diff: chrome/browser/ui/webui/ntp/android/partner_bookmarks_shim.h

Issue 10834237: Add the android partner bookmark shim. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved shim to android/ntp and removed the conflicting ID namespace issue. Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/webui/ntp/android/partner_bookmarks_shim.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_UI_WEBUI_NTP_ANDROID_PARTNER_BOOKMARKS_SHIM_H_
6 #define CHROME_BROWSER_UI_WEBUI_NTP_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 // Constructor is public for LazyInstance; DON'T CALL; use ::GetInstance().
24 PartnerBookmarksShim();
25 // Destructor is public for LazyInstance;
26 ~PartnerBookmarksShim();
27
28 // Returns the active instance of the shim.
29 static PartnerBookmarksShim* GetInstance();
30
31 // Resets back to the initial state. Clears any attached observers, deletes
32 // the partner bookmarks if any, and returns back to the unloaded state.
33 void Reset();
34
35 // Pseudo-injects partner bookmarks (if any) under the "attach_node".
36 void AttachTo(BookmarkModel* bookmark_model,
37 const BookmarkNode* attach_node);
38 // Returns true if everything got loaded and attached
39 bool IsLoaded() const;
40 // Returns true if there are partner bookmarks
41 bool HasPartnerBookmarks() const;
42
43 // For "Loaded" and "ShimBeingDeleted" notifications
44 class Observer {
45 public:
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 bool IsBookmarkEditable(const BookmarkNode* node);
58 bool IsRootNode(const BookmarkNode* node) const;
59 const BookmarkNode* GetNodeByID(int64 id, bool is_partner) const;
60 const BookmarkNode* GetParentOf(const BookmarkNode* node) const;
61 const BookmarkNode* get_attach_point() const { return attach_point_; }
62 bool IsPartnerBookmark(const BookmarkNode* node);
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_UI_WEBUI_NTP_ANDROID_PARTNER_BOOKMARKS_SHIM_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/ntp/android/partner_bookmarks_shim.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698