Chromium Code Reviews| 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..dea0797822243f02f0a4f53b7ba8275dfd26ea99 |
| --- /dev/null |
| +++ b/chrome/browser/android/partner_bookmarks_shim.h |
| @@ -0,0 +1,83 @@ |
| +// 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" |
| +// 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.
|
| +#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; |
| + |
| + // Returns the active instance of the shim. |
| + static PartnerBookmarksShim* GetInstance(); |
| + |
| + // Constructor is public for LazyInstance; DON'T CALL; use ::GetInstance(). |
| + PartnerBookmarksShim(); |
| + // Destructor is public for LazyInstance; |
| + ~PartnerBookmarksShim(); |
| + void Reset(); |
| + |
| + // Pseudo-injects partner bookmarks (if any) under the "attach_node". |
| + void AttachTo(BookmarkModel* bookmark_model, |
| + 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 { |
| + // 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_; } |
| + 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_ |