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

Side by Side Diff: components/enhanced_bookmarks/bookmark_image_service.h

Issue 899653003: [Enhanced Bookmark]Upstream image fetching code in android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #ifndef COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_IMAGE_SERVICE_H_ 4 #ifndef COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_IMAGE_SERVICE_H_
5 #define COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_IMAGE_SERVICE_H_ 5 #define COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_IMAGE_SERVICE_H_
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "components/bookmarks/browser/bookmark_model_observer.h" 10 #include "components/bookmarks/browser/bookmark_model_observer.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 const BookmarkNode* node) override; 73 const BookmarkNode* node) override;
74 void BookmarkNodeChildrenReordered(bookmarks::BookmarkModel* model, 74 void BookmarkNodeChildrenReordered(bookmarks::BookmarkModel* model,
75 const BookmarkNode* node) override; 75 const BookmarkNode* node) override;
76 void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel* model, 76 void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel* model,
77 const std::set<GURL>& removed_urls) override; 77 const std::set<GURL>& removed_urls) override;
78 78
79 protected: 79 protected:
80 // Returns true if the image for the page_url is currently being fetched. 80 // Returns true if the image for the page_url is currently being fetched.
81 bool IsPageUrlInProgress(const GURL& page_url); 81 bool IsPageUrlInProgress(const GURL& page_url);
82 82
83 // Once an image has been retrieved, store the image and notify all the 83 // Stores the image to local. If update_bookmarks is true, relates the
lpromero 2015/02/04 13:54:51 s/local/local storage.
Ian Wen 2015/02/05 18:33:17 Done.
84 // consumers that were waiting on it. 84 // corresponding bookmark to image_url.
85 void ProcessNewImage(const GURL& page_url, 85 void ProcessNewImage(const GURL& page_url,
86 bool update_bookmarks, 86 bool update_bookmarks,
87 const gfx::Image& image, 87 const gfx::Image& image,
88 const GURL& image_url); 88 const GURL& image_url);
89 89
90 // Sets a new image for a bookmark. If the given page_url is bookmarked and 90 // Sets a new image for a bookmark. If the given page_url is bookmarked and
91 // the image is retrieved from the image_url, then the image is locally 91 // the image is retrieved from the image_url, then the image is locally
92 // stored. If update_bookmark is true the URL is also added to the bookmark. 92 // stored. If update_bookmark is true the URL is also added to the bookmark.
93 // This is the only method subclass needs to implement. 93 // This is the only method subclass needs to implement.
94 virtual void RetrieveSalientImage( 94 virtual void RetrieveSalientImage(
95 const GURL& page_url, 95 const GURL& page_url,
96 const GURL& image_url, 96 const GURL& image_url,
97 const std::string& referrer, 97 const std::string& referrer,
98 net::URLRequest::ReferrerPolicy referrer_policy, 98 net::URLRequest::ReferrerPolicy referrer_policy,
99 bool update_bookmark) = 0; 99 bool update_bookmark) = 0;
100 100
101 // Retrieves a salient image for a given page_url by downloading the image in 101 // Retrieves a salient image for a given page_url by downloading the image in
102 // one of the bookmark. 102 // one of the bookmark.
103 virtual void RetrieveSalientImageForPageUrl(const GURL& page_url); 103 virtual void RetrieveSalientImageForPageUrl(const GURL& page_url);
104 104
105 // PageUrls currently in the progress of being retrieved. 105 // PageUrls currently in the progress of being retrieved.
106 std::set<GURL> in_progress_page_urls_; 106 std::set<GURL> in_progress_page_urls_;
107 107
108 // Cached pointer to the bookmark model. 108 // Cached pointer to the bookmark model.
109 EnhancedBookmarkModel* enhanced_bookmark_model_; 109 EnhancedBookmarkModel* enhanced_bookmark_model_;
110 110
111 private: 111 private:
112 // Same as SalientImageForUrl(const GURL&, ImageCallback) but can 112 // Retrieve the salient image associated with page_url from local storage.
lpromero 2015/02/04 13:54:51 s/Retrieve/Retrieves
Ian Wen 2015/02/05 18:33:17 Done.
113 // prevent the network request if fetch_from_bookmark is false. 113 void SalientImageFromLocal(const GURL& page_url, ImageCallback callback);
114 void SalientImageForUrl(const GURL& page_url, 114
115 bool fetch_from_bookmark, 115 // If the salient image of the page_url has already been stored locally, this
116 ImageCallback stack_callback); 116 // method is identical to SalientImageFromLocal. Otherwise, it first downloads
117 // the image (if any), stores it to local storage, then call
118 // SalientImageFromLocal.
119 void SalientImageFromWeb(const GURL& page_url, ImageCallback callback);
117 120
118 // Processes the requests that have been waiting on an image. 121 // Processes the requests that have been waiting on an image.
119 void ProcessRequests(const GURL& page_url, const ImageRecord& image); 122 void ProcessRequests(const GURL& page_url, const ImageRecord& image);
120 123
121 // Once an image is retrieved this method updates the store with it. Returns 124 // Once an image is retrieved this method updates the store with it. Returns
122 // the newly formed ImageRecord. This is typically called on |pool_|, the 125 // the newly formed ImageRecord. This is typically called on |pool_|, the
123 // background sequenced worker pool for this object. 126 // background sequenced worker pool for this object.
124 ImageRecord StoreImage(const gfx::Image& image, 127 ImageRecord StoreImage(const gfx::Image& image,
125 const GURL& image_url, 128 const GURL& image_url,
126 const GURL& page_url); 129 const GURL& page_url);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 GURL previous_url_; 174 GURL previous_url_;
172 175
173 // The worker pool to enqueue the requests onto. 176 // The worker pool to enqueue the requests onto.
174 scoped_refptr<base::SequencedWorkerPool> pool_; 177 scoped_refptr<base::SequencedWorkerPool> pool_;
175 DISALLOW_COPY_AND_ASSIGN(BookmarkImageService); 178 DISALLOW_COPY_AND_ASSIGN(BookmarkImageService);
176 }; 179 };
177 180
178 } // namespace enhanced_bookmarks 181 } // namespace enhanced_bookmarks
179 182
180 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_IMAGE_SERVICE_H_ 183 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_IMAGE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698