Index: components/enhanced_bookmarks/enhanced_bookmark_model.h |
diff --git a/components/enhanced_bookmarks/enhanced_bookmark_model.h b/components/enhanced_bookmarks/enhanced_bookmark_model.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3f690b9a57cbd1c766c90f166740e83d7feadf05 |
--- /dev/null |
+++ b/components/enhanced_bookmarks/enhanced_bookmark_model.h |
@@ -0,0 +1,121 @@ |
+// Copyright 2014 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 COMPONENTS_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_MODEL_H_ |
+#define COMPONENTS_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_MODEL_H_ |
+ |
+#include <string> |
+ |
+#include "base/strings/string16.h" |
+#include "components/bookmarks/browser/bookmark_node.h" |
+#include "components/keyed_service/core/keyed_service.h" |
+ |
+namespace base { |
+class Time; |
+} // namespace base |
+ |
+class BookmarkModel; |
+class GURL; |
+ |
+namespace enhanced_bookmarks { |
+// Wrapper around BookmarkModel providing utility functions for enhanced |
+// bookmarks. |
Mark
2014/09/03 23:31:16
I'm assuming everything around stars.userEdits wil
Rune Fevang
2014/09/04 01:03:13
Added stars.userEdit handling.
|
+class EnhancedBookmarkModel : public KeyedService { |
+ public: |
+ explicit EnhancedBookmarkModel(BookmarkModel* bookmark_model); |
+ virtual ~EnhancedBookmarkModel(); |
+ |
+ void Initialize(const std::string& version); |
+ |
+ // Moves |node| to |new_parent| and inserts it at the given |index|. |
+ void Move(const BookmarkNode* node, |
+ const BookmarkNode* new_parent, |
+ int index); |
+ |
+ // Adds a new folder node at the specified position. |
+ const BookmarkNode* AddFolder(const BookmarkNode* parent, |
+ int index, |
+ const base::string16& title, |
+ const BookmarkNode::MetaInfoMap* meta_info); |
+ |
+ // Adds a url at the specified position. |
+ const BookmarkNode* AddURL(const BookmarkNode* parent, |
+ int index, |
+ const base::string16& title, |
+ const GURL& url, |
+ const base::Time& creation_time, |
+ const BookmarkNode::MetaInfoMap* meta_info); |
+ |
+ // Returns the remote id for a bookmark. |
+ std::string GetRemoteIdForNode(const BookmarkNode* node); |
+ |
+ // Sets the description of a bookmark. |
+ void SetDescriptionForNode(const BookmarkNode* node, |
+ const std::string& description); |
+ |
+ // Returns the description of a bookmark. |
+ std::string GetDescriptionForNode(const BookmarkNode* node); |
+ |
+ // Sets the URL of an image representative of the page. |
+ // Expects the URL to be valid and not empty. |
+ // Returns true if the metainfo is successfully populated. |
+ bool SetOriginalImageForNode(const BookmarkNode* node, |
+ const GURL& url, |
+ int width, |
+ int height); |
+ |
+ // Returns the url and dimensions of the original scraped image. |
+ // Returns true if the out variables are populated, false otherwise. |
+ bool GetOriginalImageForNode(const BookmarkNode* node, |
+ GURL* url, |
+ int* width, |
+ int* height); |
+ |
+ // Returns the url and dimensions of the server provided thumbnail image. |
+ // Returns true if the out variables are populated, false otherwise. |
+ bool GetThumbnailImageForNode(const BookmarkNode* node, |
+ GURL* url, |
+ int* width, |
+ int* height); |
+ |
+ // Returns a brief server provided synopsis of the bookmarked page. |
+ // Returns the empty string if the snippet could not be extracted. |
+ std::string GetSnippetForNode(const BookmarkNode* node); |
+ |
+ // Returns the version of the last enhanced bookmark client to change this |
+ // node. Returns the empty string if the node doesn't have one set. |
Mark
2014/09/03 23:31:16
This should ONLY be used for debugging. The serve
Rune Fevang
2014/09/04 01:03:13
Moved the function to the test class.
|
+ std::string GetVersionForNode(const BookmarkNode* node); |
Mark
2014/09/03 23:31:16
Clients should be agnostic to this and this should
Rune Fevang
2014/09/04 01:03:13
Acknowledged.
|
+ |
+ // Used for testing, simulates the process that creates the thumnails. Will |
Mark
2014/09/03 23:31:16
Nit: s/thumnails/thumbnails
Rune Fevang
2014/09/04 01:03:13
Done.
|
+ // remove existing entries for empty urls or set them if the url is not empty. |
+ // expects valid or empty urls. Returns true if the metainfo is successfully |
Mark
2014/09/03 23:31:16
s/expects/Expects
Rune Fevang
2014/09/04 01:03:13
Done.
|
+ // populated. |
+ // TODO(rfevang): Move this to a testing only utility file. |
+ static bool SetAllImagesForBookmark(BookmarkModel* bookmark_model, |
+ const BookmarkNode* node, |
+ const GURL& image_url, |
+ int image_width, |
+ int image_height, |
+ const GURL& thumbnail_url, |
+ int thumbnail_width, |
+ int thumbnail_height); |
+ |
Mark
2014/09/03 23:31:16
Add TODO to add method for setting and getting the
Rune Fevang
2014/09/04 01:03:13
Getting and setting which flags?
Mark
2014/09/04 01:52:10
stars.flag. This could be handled by generic SetN
|
+ private: |
+ // Generates and sets a remote id for the given bookmark. Returns the id set. |
+ std::string SetRemoteIdForNode(const BookmarkNode* node); |
+ |
+ // Helper method for setting a meta info field on a node. Also updates the |
+ // version field. |
+ void SetNodeMetaInfo(const BookmarkNode* node, |
+ const std::string& field, |
+ const std::string& value); |
+ |
+ BookmarkModel* bookmark_model_; |
+ bool initialized_; |
+ std::string version_; |
+}; |
+ |
+} // namespace enhanced_bookmarks |
+ |
+#endif // COMPONENTS_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_MODEL_H_ |