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 16 matching lines...) Expand all Loading... |
27 public BookmarkModelObserver, | 27 public 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 virtual ~BookmarkImageService(); | 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 virtual 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 // BookmarkModelObserver methods. |
52 virtual 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; |
| 57 void BookmarkModelLoaded(BookmarkModel* model, bool ids_reassigned) override; |
| 58 void BookmarkNodeMoved(BookmarkModel* model, |
| 59 const BookmarkNode* old_parent, |
| 60 int old_index, |
| 61 const BookmarkNode* new_parent, |
| 62 int new_index) override; |
| 63 void BookmarkNodeAdded(BookmarkModel* model, |
| 64 const BookmarkNode* parent, |
| 65 int index) override; |
| 66 void OnWillChangeBookmarkNode(BookmarkModel* model, |
| 67 const BookmarkNode* node) override; |
| 68 void BookmarkNodeChanged(BookmarkModel* model, |
| 69 const BookmarkNode* node) override; |
| 70 void BookmarkNodeFaviconChanged(BookmarkModel* model, |
| 71 const BookmarkNode* node) override; |
| 72 void BookmarkNodeChildrenReordered(BookmarkModel* model, |
| 73 const BookmarkNode* node) override; |
| 74 void BookmarkAllUserNodesRemoved(BookmarkModel* model, |
56 const std::set<GURL>& removed_urls) override; | 75 const std::set<GURL>& removed_urls) override; |
57 virtual void BookmarkModelLoaded(BookmarkModel* model, | |
58 bool ids_reassigned) override; | |
59 virtual void BookmarkNodeMoved(BookmarkModel* model, | |
60 const BookmarkNode* old_parent, | |
61 int old_index, | |
62 const BookmarkNode* new_parent, | |
63 int new_index) override; | |
64 virtual void BookmarkNodeAdded(BookmarkModel* model, | |
65 const BookmarkNode* parent, | |
66 int index) override; | |
67 virtual void OnWillChangeBookmarkNode(BookmarkModel* model, | |
68 const BookmarkNode* node) override; | |
69 virtual void BookmarkNodeChanged(BookmarkModel* model, | |
70 const BookmarkNode* node) override; | |
71 virtual void BookmarkNodeFaviconChanged(BookmarkModel* model, | |
72 const BookmarkNode* node) override; | |
73 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, | |
74 const BookmarkNode* node) override; | |
75 virtual void BookmarkAllUserNodesRemoved( | |
76 BookmarkModel* model, | |
77 const std::set<GURL>& removed_urls) override; | |
78 | 76 |
79 protected: | 77 protected: |
80 // Returns true if the image for the page_url is currently being fetched. | 78 // Returns true if the image for the page_url is currently being fetched. |
81 bool IsPageUrlInProgress(const GURL& page_url); | 79 bool IsPageUrlInProgress(const GURL& page_url); |
82 | 80 |
83 // Once an image has been retrieved, store the image and notify all the | 81 // Once an image has been retrieved, store the image and notify all the |
84 // consumers that were waiting on it. | 82 // consumers that were waiting on it. |
85 void ProcessNewImage(const GURL& page_url, | 83 void ProcessNewImage(const GURL& page_url, |
86 bool update_bookmarks, | 84 bool update_bookmarks, |
87 const gfx::Image& image, | 85 const gfx::Image& image, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 GURL previous_url_; | 161 GURL previous_url_; |
164 | 162 |
165 // The worker pool to enqueue the store requests onto. | 163 // The worker pool to enqueue the store requests onto. |
166 scoped_refptr<base::SequencedWorkerPool> pool_; | 164 scoped_refptr<base::SequencedWorkerPool> pool_; |
167 DISALLOW_COPY_AND_ASSIGN(BookmarkImageService); | 165 DISALLOW_COPY_AND_ASSIGN(BookmarkImageService); |
168 }; | 166 }; |
169 | 167 |
170 } // namespace enhanced_bookmarks | 168 } // namespace enhanced_bookmarks |
171 | 169 |
172 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_IMAGE_SERVICE_H_ | 170 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_IMAGE_SERVICE_H_ |
OLD | NEW |