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" |
11 #include "components/enhanced_bookmarks/image_store.h" | 11 #include "components/enhanced_bookmarks/image_store.h" |
12 #include "components/keyed_service/core/keyed_service.h" | 12 #include "components/keyed_service/core/keyed_service.h" |
13 #include "net/url_request/url_request.h" | 13 #include "net/url_request/url_request.h" |
14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 class SingleThreadTaskRunner; | 17 class SingleThreadTaskRunner; |
18 } | 18 } |
19 class BookmarkNode; | 19 class BookmarkNode; |
20 | 20 |
21 namespace enhanced_bookmarks { | 21 namespace enhanced_bookmarks { |
22 | 22 |
| 23 class EnhancedBookmarkModel; |
| 24 |
23 // The BookmarkImageService stores salient images for bookmarks. | 25 // The BookmarkImageService stores salient images for bookmarks. |
24 class BookmarkImageService : public KeyedService, | 26 class BookmarkImageService : public KeyedService, |
25 public BookmarkModelObserver, | 27 public BookmarkModelObserver, |
26 public base::NonThreadSafe { | 28 public base::NonThreadSafe { |
27 public: | 29 public: |
28 explicit BookmarkImageService(const base::FilePath& path, | 30 BookmarkImageService(const base::FilePath& path, |
29 BookmarkModel* bookmark_model, | 31 EnhancedBookmarkModel* enhanced_bookmark_model, |
30 scoped_refptr<base::SequencedWorkerPool> pool); | 32 scoped_refptr<base::SequencedWorkerPool> pool); |
31 BookmarkImageService(scoped_ptr<ImageStore> store, | 33 BookmarkImageService(scoped_ptr<ImageStore> store, |
32 BookmarkModel* bookmark_model, | 34 EnhancedBookmarkModel* enhanced_bookmark_model, |
33 scoped_refptr<base::SequencedWorkerPool> pool); | 35 scoped_refptr<base::SequencedWorkerPool> pool); |
34 | 36 |
35 virtual ~BookmarkImageService(); | 37 virtual ~BookmarkImageService(); |
36 | 38 |
37 typedef base::Callback<void(const gfx::Image&, const GURL& url)> Callback; | 39 typedef base::Callback<void(const gfx::Image&, const GURL& url)> Callback; |
38 | 40 |
39 // Returns a salient image for a URL. This may trigger a network request for | 41 // Returns a salient image for a URL. This may trigger a network request for |
40 // the image if the image was not retrieved before and if a bookmark node has | 42 // the image if the image was not retrieved before and if a bookmark node has |
41 // a URL for this salient image available. The image (which may be empty) is | 43 // a URL for this salient image available. The image (which may be empty) is |
42 // sent via the callback. The callback may be called synchronously if it is | 44 // sent via the callback. The callback may be called synchronously if it is |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 net::URLRequest::ReferrerPolicy referrer_policy, | 95 net::URLRequest::ReferrerPolicy referrer_policy, |
94 bool update_bookmark) = 0; | 96 bool update_bookmark) = 0; |
95 | 97 |
96 // Retrieves a salient image for a given page_url by downloading the image in | 98 // Retrieves a salient image for a given page_url by downloading the image in |
97 // one of the bookmark. | 99 // one of the bookmark. |
98 virtual void RetrieveSalientImageForPageUrl(const GURL& page_url); | 100 virtual void RetrieveSalientImageForPageUrl(const GURL& page_url); |
99 | 101 |
100 // PageUrls currently in the progress of being retrieved. | 102 // PageUrls currently in the progress of being retrieved. |
101 std::set<GURL> in_progress_page_urls_; | 103 std::set<GURL> in_progress_page_urls_; |
102 | 104 |
103 // Cached pointer to the bookmarks model. | 105 // Cached pointer to the bookmark model. |
104 BookmarkModel* bookmark_model_; // weak | 106 EnhancedBookmarkModel* enhanced_bookmark_model_; |
105 | 107 |
106 private: | 108 private: |
107 // Same as SalientImageForUrl(const GURL&, Callback) but can prevent the | 109 // Same as SalientImageForUrl(const GURL&, Callback) but can prevent the |
108 // network request if fetch_from_bookmark is false. | 110 // network request if fetch_from_bookmark is false. |
109 void SalientImageForUrl(const GURL& page_url, | 111 void SalientImageForUrl(const GURL& page_url, |
110 bool fetch_from_bookmark, | 112 bool fetch_from_bookmark, |
111 Callback stack_callback); | 113 Callback stack_callback); |
112 | 114 |
113 // Processes the requests that have been waiting on an image. | 115 // Processes the requests that have been waiting on an image. |
114 void ProcessRequests(const GURL& page_url, | 116 void ProcessRequests(const GURL& page_url, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 GURL previous_url_; | 160 GURL previous_url_; |
159 | 161 |
160 // The worker pool to enqueue the store requests onto. | 162 // The worker pool to enqueue the store requests onto. |
161 scoped_refptr<base::SequencedWorkerPool> pool_; | 163 scoped_refptr<base::SequencedWorkerPool> pool_; |
162 DISALLOW_COPY_AND_ASSIGN(BookmarkImageService); | 164 DISALLOW_COPY_AND_ASSIGN(BookmarkImageService); |
163 }; | 165 }; |
164 | 166 |
165 } // namespace enhanced_bookmarks | 167 } // namespace enhanced_bookmarks |
166 | 168 |
167 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_IMAGE_SERVICE_H_ | 169 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_IMAGE_SERVICE_H_ |
OLD | NEW |