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

Unified Diff: chrome/browser/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: Remove unnecessary conditional. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/partner_bookmarks_shim.h
diff --git a/chrome/browser/android/partner_bookmarks_shim.h b/chrome/browser/android/partner_bookmarks_shim.h
new file mode 100644
index 0000000000000000000000000000000000000000..7118cef64c0ff7b6f9f04efae2841b07e3acf478
--- /dev/null
+++ b/chrome/browser/android/partner_bookmarks_shim.h
@@ -0,0 +1,82 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_ANDROID_PARTNER_BOOKMARKS_SHIM_H_
+#define CHROME_BROWSER_ANDROID_PARTNER_BOOKMARKS_SHIM_H_
+
+#include "base/android/jni_helper.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/bookmarks/bookmark_model.h"
+
+// A shim that lives on top of a BookmarkModel that allows the injection of
+// Partner bookmarks without submitting changes to the user configured bookmark
+// model.
+// Partner bookmarks folder is pseudo-injected as a subfolder to "attach node".
+// Because we cannot modify the BookmarkModel, the following needs to
+// be done on a client side:
+// 1. bookmark_node->is_root() -> shim->IsRootNode(bookmark_node)
+// 2. bookmark_node->parent() -> shim->GetParentOf(bookmark_node)
+// 3. bookmark_model->GetNodeByID(id) -> shim->GetNodeByID(id)
+class PartnerBookmarksShim {
+ public:
+ // The mask used to determining if an ID is a partner bookmark. When
+ // constructing partner bookmarks, ensure the IDs are based on this value.
+ 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.
+
+ // Returns the active instance of the shim.
+ static PartnerBookmarksShim* GetInstance();
sky 2012/08/09 15:48:19 constructor/destructor before other methods.
Ted C 2012/08/09 16:47:01 Done.
+
+ // Constructor is public for LazyInstance; DON'T CALL; use ::GetInstance().
+ PartnerBookmarksShim();
+ // Destructor is public for LazyInstance;
+ ~PartnerBookmarksShim();
+ void Reset();
sky 2012/08/09 15:48:19 Add documentation.
Ted C 2012/08/09 16:47:01 Done.
+
+ // Pseudo-injects partner bookmarks (if any) under the "attach_node".
+ 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.
+ const BookmarkNode* attach_node);
+ // Returns true if everything got loaded and attached
+ bool IsLoaded() const;
+ // Returns true if there are partner bookmarks
+ bool HasPartnerBookmarks() const;
+
+ // For "Loaded" and "ShimBeingDeleted" notifications
+ struct Observer {
sky 2012/08/09 15:48:19 This should be a class.
Ted C 2012/08/09 16:47:01 Done.
+ // Called when everything is loaded and attached
+ virtual void PartnerShimLoaded(PartnerBookmarksShim*) {}
+ // Called just before everything got destroyed
+ virtual void ShimBeingDeleted(PartnerBookmarksShim*) {}
+ protected:
+ virtual ~Observer() {}
+ };
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ // Replacements for BookmarkModel/BookmarkNode methods
+ static bool IsBookmarkEditable(const BookmarkNode* node);
+ bool IsRootNode(const BookmarkNode* node) const;
+ const BookmarkNode* GetNodeByID(int64 id) const;
+ const BookmarkNode* GetParentOf(const BookmarkNode* node) const;
+ 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.
+ static bool IsPartnerBookmarkId(int64 id);
+ const BookmarkNode* GetPartnerBookmarksRoot() const;
+ // Sets the root node of the partner bookmarks and notifies any observers that
+ // the shim has now been loaded. Takes ownership of |root_node|.
+ void SetPartnerBookmarksRoot(BookmarkNode* root_node);
+
+ private:
+ const BookmarkNode* GetNodeByID(const BookmarkNode* parent, int64 id) const;
+
+ scoped_ptr<BookmarkNode> partner_bookmarks_root_;
+ BookmarkModel* bookmark_model_;
+ const BookmarkNode* attach_point_;
+ bool loaded_; // Set only on UI thread
+
+ // The observers.
+ ObserverList<Observer> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(PartnerBookmarksShim);
+};
+
+#endif // CHROME_BROWSER_ANDROID_PARTNER_BOOKMARKS_SHIM_H_
« no previous file with comments | « no previous file | chrome/browser/android/partner_bookmarks_shim.cc » ('j') | chrome/browser/android/partner_bookmarks_shim.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698