| 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; | 23 class EnhancedBookmarkModel; |
| 24 | 24 |
| 25 // The BookmarkImageService stores salient images for bookmarks. | 25 // The BookmarkImageService stores salient images for bookmarks. |
| 26 class BookmarkImageService : public KeyedService, | 26 class BookmarkImageService : public KeyedService, |
| 27 public BookmarkModelObserver, | 27 public bookmarks::BookmarkModelObserver, |
| 28 public base::NonThreadSafe { | 28 public base::NonThreadSafe { |
| 29 public: | 29 public: |
| 30 BookmarkImageService(const base::FilePath& path, | 30 BookmarkImageService(const base::FilePath& path, |
| 31 EnhancedBookmarkModel* enhanced_bookmark_model, | 31 EnhancedBookmarkModel* enhanced_bookmark_model, |
| 32 scoped_refptr<base::SequencedWorkerPool> pool); | 32 scoped_refptr<base::SequencedWorkerPool> pool); |
| 33 BookmarkImageService(scoped_ptr<ImageStore> store, | 33 BookmarkImageService(scoped_ptr<ImageStore> store, |
| 34 EnhancedBookmarkModel* enhanced_bookmark_model, | 34 EnhancedBookmarkModel* enhanced_bookmark_model, |
| 35 scoped_refptr<base::SequencedWorkerPool> pool); | 35 scoped_refptr<base::SequencedWorkerPool> pool); |
| 36 | 36 |
| 37 ~BookmarkImageService() override; | 37 ~BookmarkImageService() override; |
| 38 | 38 |
| 39 typedef base::Callback<void(const gfx::Image&, const GURL& url)> Callback; | 39 typedef base::Callback<void(const gfx::Image&, const GURL& url)> Callback; |
| 40 | 40 |
| 41 // KeyedService: | 41 // KeyedService: |
| 42 void Shutdown() override; | 42 void Shutdown() override; |
| 43 | 43 |
| 44 // Returns a salient image for a URL. This may trigger a network request for | 44 // Returns a salient image for a URL. This may trigger a network request for |
| 45 // the image if the image was not retrieved before and if a bookmark node has | 45 // the image if the image was not retrieved before and if a bookmark node has |
| 46 // a URL for this salient image available. The image (which may be empty) is | 46 // a URL for this salient image available. The image (which may be empty) is |
| 47 // sent via the callback. The callback may be called synchronously if it is | 47 // sent via the callback. The callback may be called synchronously if it is |
| 48 // possible. The callback is always triggered on the main thread. | 48 // possible. The callback is always triggered on the main thread. |
| 49 void SalientImageForUrl(const GURL& page_url, Callback callback); | 49 void SalientImageForUrl(const GURL& page_url, Callback callback); |
| 50 | 50 |
| 51 // BookmarkModelObserver methods. | 51 // bookmarks::BookmarkModelObserver: |
| 52 void BookmarkNodeRemoved(BookmarkModel* model, | 52 void BookmarkNodeRemoved(BookmarkModel* model, |
| 53 const BookmarkNode* parent, | 53 const BookmarkNode* parent, |
| 54 int old_index, | 54 int old_index, |
| 55 const BookmarkNode* node, | 55 const BookmarkNode* node, |
| 56 const std::set<GURL>& removed_urls) override; | 56 const std::set<GURL>& removed_urls) override; |
| 57 void BookmarkModelLoaded(BookmarkModel* model, bool ids_reassigned) override; | 57 void BookmarkModelLoaded(BookmarkModel* model, bool ids_reassigned) override; |
| 58 void BookmarkNodeMoved(BookmarkModel* model, | 58 void BookmarkNodeMoved(BookmarkModel* model, |
| 59 const BookmarkNode* old_parent, | 59 const BookmarkNode* old_parent, |
| 60 int old_index, | 60 int old_index, |
| 61 const BookmarkNode* new_parent, | 61 const BookmarkNode* new_parent, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 GURL previous_url_; | 161 GURL previous_url_; |
| 162 | 162 |
| 163 // The worker pool to enqueue the store requests onto. | 163 // The worker pool to enqueue the store requests onto. |
| 164 scoped_refptr<base::SequencedWorkerPool> pool_; | 164 scoped_refptr<base::SequencedWorkerPool> pool_; |
| 165 DISALLOW_COPY_AND_ASSIGN(BookmarkImageService); | 165 DISALLOW_COPY_AND_ASSIGN(BookmarkImageService); |
| 166 }; | 166 }; |
| 167 | 167 |
| 168 } // namespace enhanced_bookmarks | 168 } // namespace enhanced_bookmarks |
| 169 | 169 |
| 170 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_IMAGE_SERVICE_H_ | 170 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_IMAGE_SERVICE_H_ |
| OLD | NEW |