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..15c7fc5d0bd4dbb83022fcbdfd2583fcd09cc08a |
--- /dev/null |
+++ b/components/enhanced_bookmarks/enhanced_bookmark_model.h |
@@ -0,0 +1,130 @@ |
+// 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. |
+class EnhancedBookmarkModel : public KeyedService { |
noyau (Ping after 24h)
2014/09/05 12:04:43
This doesn't track changes in the model, and as su
Rune Fevang
2014/09/06 00:01:56
Right, that will come in a later CL (task 4 in the
noyau (Ping after 24h)
2014/09/08 09:04:18
Acknowledged.
|
+ public: |
+ EnhancedBookmarkModel(BookmarkModel* bookmark_model, |
+ const std::string& version); |
+ virtual ~EnhancedBookmarkModel(); |
+ |
+ // 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); |
noyau (Ping after 24h)
2014/09/05 12:04:43
Why does this takes a metainfo? I thought the whol
Rune Fevang
2014/09/06 00:01:56
Yes that is the (at least long term) point, but as
|
+ |
+ // 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); |
noyau (Ping after 24h)
2014/09/05 12:04:43
Same here. I'd expect addURL to take an optional d
Rune Fevang
2014/09/06 00:01:56
That's fine, the main things that need to be set o
|
+ |
+ // Returns the remote id for a bookmark. |
+ std::string GetRemoteIdForNode(const BookmarkNode* node); |
+ |
+ // Sets the description of a bookmark. |user_edit| should be true if |
+ // setting the description is the direct result of a user action. |
+ void SetDescriptionForNode(const BookmarkNode* node, |
+ const std::string& description, |
+ bool user_edit); |
noyau (Ping after 24h)
2014/09/05 12:04:43
I don't understand user_edit. I thought the descri
Rune Fevang
2014/09/06 00:01:56
Discussed userEdit with mcolbert@. Decided that it
|
+ |
+ // 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. |user_edit| should be true if |
+ // setting the image is the direct result of a user action. |
+ // Returns true if the metainfo is successfully populated. |
+ bool SetOriginalImageForNode(const BookmarkNode* node, |
+ const GURL& url, |
+ int width, |
+ int height, |
+ bool user_edit); |
noyau (Ping after 24h)
2014/09/05 12:04:43
Here user_edit is confusing, this is always the re
|
+ |
+ // 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); |
+ |
+ // Sets a custom suffix to be added to the version field when writing meta |
+ // info fields. |
+ void SetVersionSuffix(const std::string& version_suffix); |
+ |
+ // TODO(rfevang): Add method + enum for accessing/writing flags. |
+ |
+ // Used for testing, simulates the process that creates the thumbnails. Will |
+ // 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 |
+ // populated. |
+ // TODO(rfevang): Move this to a testing only utility file. |
+ static bool SetAllImagesForBookmark(BookmarkModel* bookmark_model, |
noyau (Ping after 24h)
2014/09/05 12:04:43
The bookmark_model argument is not needed here any
Rune Fevang
2014/09/06 00:01:56
Done.
|
+ const BookmarkNode* node, |
+ const GURL& image_url, |
+ int image_width, |
+ int image_height, |
+ const GURL& thumbnail_url, |
+ int thumbnail_width, |
+ int thumbnail_height); |
+ |
+ 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 and userEdits fields. |
+ void SetNodeMetaInfo(const BookmarkNode* node, |
+ const std::string& field, |
+ const std::string& value, |
+ bool user_edit); |
+ |
+ // Returns the version string to use when setting stars.version. |
+ std::string GetVersionString(); |
+ |
+ BookmarkModel* bookmark_model_; |
+ std::string version_; |
+ std::string version_suffix_; |
+}; |
+ |
+} // namespace enhanced_bookmarks |
+ |
+#endif // COMPONENTS_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_MODEL_H_ |