OLD | NEW |
---|---|
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 Loading... | |
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 updates the store with it. Returns |
126 // the newly formed ImageRecord. This is typically called on |pool_|, the | 129 // the newly formed ImageRecord. This is typically called on |pool_|, the |
127 // background sequenced worker pool for this object. | 130 // background sequenced worker pool for this object. |
Kibeom Kim (inactive)
2015/02/17 21:32:59
nit: update comment to explain resize? Or I think
Ian Wen
2015/02/23 18:54:57
Done.
| |
128 ImageRecord StoreImage(const gfx::Image& image, | 131 ImageRecord ResizeAndStoreImage(const gfx::Image& image, |
129 const GURL& image_url, | 132 const GURL& image_url, |
130 const GURL& page_url); | 133 const GURL& page_url); |
131 | 134 |
132 // Calls |StoreImage| in the background. This should only be called from the | 135 // Calls |StoreImage| in the background. This should only be called from the |
133 // main thread. | 136 // main thread. |
134 void PostTaskToStoreImage(const gfx::Image& image, | 137 void PostTaskToStoreImage(const gfx::Image& image, |
135 const GURL& image_url, | 138 const GURL& image_url, |
136 const GURL& page_url); | 139 const GURL& page_url); |
137 | 140 |
138 // Called when |StoreImage| as been posted. This should only be called from | 141 // Called when |StoreImage| as been posted. This should only be called from |
139 // the main thread. | 142 // the main thread. |
140 void OnStoreImagePosted(const GURL& page_url, const ImageRecord& image); | 143 void OnStoreImagePosted(const GURL& page_url, const ImageRecord& image); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 | 179 |
177 // The worker pool to enqueue the requests onto. | 180 // The worker pool to enqueue the requests onto. |
178 scoped_refptr<base::SequencedWorkerPool> pool_; | 181 scoped_refptr<base::SequencedWorkerPool> pool_; |
179 DISALLOW_COPY_AND_ASSIGN(BookmarkImageService); | 182 DISALLOW_COPY_AND_ASSIGN(BookmarkImageService); |
180 }; | 183 }; |
181 | 184 |
182 } // namespace enhanced_bookmarks | 185 } // namespace enhanced_bookmarks |
183 | 186 |
184 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_IMAGE_SERVICE_H_ | 187 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_IMAGE_SERVICE_H_ |
185 | 188 |
OLD | NEW |