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

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

Issue 916783003: Restrict salient image size before storing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comments 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 void BookmarkNodeChildrenReordered( 77 void BookmarkNodeChildrenReordered(
78 bookmarks::BookmarkModel* model, 78 bookmarks::BookmarkModel* model,
79 const bookmarks::BookmarkNode* node) override; 79 const bookmarks::BookmarkNode* node) override;
80 void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel* model, 80 void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel* model,
81 const std::set<GURL>& removed_urls) override; 81 const std::set<GURL>& removed_urls) override;
82 82
83 protected: 83 protected:
84 // Returns true if the image for the page_url is currently being fetched. 84 // Returns true if the image for the page_url is currently being fetched.
85 bool IsPageUrlInProgress(const GURL& page_url); 85 bool IsPageUrlInProgress(const GURL& page_url);
86 86
87 // Stores the image to local storage. If update_bookmarks is true, relates the 87 // Stores the new image to local storage. If update_bookmarks is true, relates
88 // corresponding bookmark to image_url. 88 // the corresponding bookmark to image_url.
89 void ProcessNewImage(const GURL& page_url, 89 void ProcessNewImage(const GURL& page_url,
90 bool update_bookmarks, 90 bool update_bookmarks,
91 const gfx::Image& image, 91 const GURL& image_url,
92 const GURL& image_url); 92 const gfx::Image& image);
93
94 // Resizes large images to proper size that fits device display. This method
95 // should _not_ run on the UI thread.
96 virtual gfx::Image ResizeImage(gfx::Image image) = 0;
93 97
94 // Sets a new image for a bookmark. If the given page_url is bookmarked and 98 // Sets a new image for a bookmark. If the given page_url is bookmarked and
95 // the image is retrieved from the image_url, then the image is locally 99 // the image is retrieved from the image_url, then the image is locally
96 // stored. If update_bookmark is true the URL is also added to the bookmark. 100 // stored. If update_bookmark is true the URL is also added to the bookmark.
97 // This is the only method subclass needs to implement.
98 virtual void RetrieveSalientImage( 101 virtual void RetrieveSalientImage(
99 const GURL& page_url, 102 const GURL& page_url,
100 const GURL& image_url, 103 const GURL& image_url,
101 const std::string& referrer, 104 const std::string& referrer,
102 net::URLRequest::ReferrerPolicy referrer_policy, 105 net::URLRequest::ReferrerPolicy referrer_policy,
103 bool update_bookmark) = 0; 106 bool update_bookmark) = 0;
104 107
105 // Retrieves a salient image for a given page_url by downloading the image in 108 // Retrieves a salient image for a given page_url by downloading the image in
106 // one of the bookmark. 109 // one of the bookmark.
107 virtual void RetrieveSalientImageForPageUrl(const GURL& page_url); 110 virtual void RetrieveSalientImageForPageUrl(const GURL& page_url);
108 111
109 // PageUrls currently in the progress of being retrieved. 112 // PageUrls currently in the progress of being retrieved.
110 std::set<GURL> in_progress_page_urls_; 113 std::set<GURL> in_progress_page_urls_;
111 114
112 // Cached pointer to the bookmark model. 115 // Cached pointer to the bookmark model.
113 EnhancedBookmarkModel* enhanced_bookmark_model_; 116 EnhancedBookmarkModel* enhanced_bookmark_model_;
114 117
115 private: 118 private:
116 // If fetch_from_web is true, retrieves the salient image via a network 119 // If fetch_from_web is true, retrieves the salient image via a network
117 // request; else only gets the image from local storage. 120 // request; else only gets the image from local storage.
118 void SalientImageForUrl(const GURL& page_url, 121 void SalientImageForUrl(const GURL& page_url,
119 bool fetch_from_web, 122 bool fetch_from_web,
120 ImageCallback stack_callback); 123 ImageCallback stack_callback);
121 124
122 // Processes the requests that have been waiting on an image. 125 // Processes the requests that have been waiting on an image.
123 void ProcessRequests(const GURL& page_url, const ImageRecord& image); 126 void ProcessRequests(const GURL& page_url, const ImageRecord& image);
124 127
125 // Once an image is retrieved this method updates the store with it. Returns 128 // Once an image is retrieved this method calls ResizeImage() and updates the
126 // the newly formed ImageRecord. This is typically called on |pool_|, the 129 // store with the smaller image, then returns the newly formed ImageRecord.
127 // background sequenced worker pool for this object. 130 // This is typically called on |pool_|, the background sequenced worker pool
128 ImageRecord StoreImage(const gfx::Image& image, 131 // for this object.
129 const GURL& image_url, 132 ImageRecord ResizeAndStoreImage(const gfx::Image& image,
130 const GURL& page_url); 133 const GURL& image_url,
134 const GURL& page_url);
131 135
132 // Calls |StoreImage| in the background. This should only be called from the 136 // Calls |StoreImage| in the background. This should only be called from the
133 // main thread. 137 // main thread.
134 void PostTaskToStoreImage(const gfx::Image& image, 138 void PostTaskToStoreImage(const gfx::Image& image,
135 const GURL& image_url, 139 const GURL& image_url,
136 const GURL& page_url); 140 const GURL& page_url);
137 141
138 // Called when |StoreImage| as been posted. This should only be called from 142 // Called when |StoreImage| as been posted. This should only be called from
139 // the main thread. 143 // the main thread.
140 void OnStoreImagePosted(const GURL& page_url, const ImageRecord& image); 144 void OnStoreImagePosted(const GURL& page_url, const ImageRecord& image);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 180
177 // The worker pool to enqueue the requests onto. 181 // The worker pool to enqueue the requests onto.
178 scoped_refptr<base::SequencedWorkerPool> pool_; 182 scoped_refptr<base::SequencedWorkerPool> pool_;
179 DISALLOW_COPY_AND_ASSIGN(BookmarkImageService); 183 DISALLOW_COPY_AND_ASSIGN(BookmarkImageService);
180 }; 184 };
181 185
182 } // namespace enhanced_bookmarks 186 } // namespace enhanced_bookmarks
183 187
184 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_IMAGE_SERVICE_H_ 188 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_IMAGE_SERVICE_H_
185 189
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698