OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 4 |
5 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_HTML_WRITER_H_ | 5 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_HTML_WRITER_H_ |
6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_HTML_WRITER_H_ | 6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_HTML_WRITER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/ref_counted_memory.h" | 15 #include "base/memory/ref_counted_memory.h" |
16 #include "base/task/cancelable_task_tracker.h" | 16 #include "base/task/cancelable_task_tracker.h" |
| 17 #include "base/task_scheduler/post_task.h" |
17 #include "components/favicon_base/favicon_types.h" | 18 #include "components/favicon_base/favicon_types.h" |
18 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
20 | 21 |
21 class Profile; | 22 class Profile; |
22 | 23 |
23 namespace bookmarks { | 24 namespace bookmarks { |
24 class BookmarkNode; | 25 class BookmarkNode; |
25 } | 26 } |
26 | 27 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 67 |
67 // Executes Writer task that writes bookmarks data to html file. | 68 // Executes Writer task that writes bookmarks data to html file. |
68 void ExecuteWriter(); | 69 void ExecuteWriter(); |
69 | 70 |
70 // Starts async fetch for the next bookmark favicon. | 71 // Starts async fetch for the next bookmark favicon. |
71 // Takes single url from bookmark_urls_ and removes it from the list. | 72 // Takes single url from bookmark_urls_ and removes it from the list. |
72 // Returns true if there are more favicons to extract. | 73 // Returns true if there are more favicons to extract. |
73 bool FetchNextFavicon(); | 74 bool FetchNextFavicon(); |
74 | 75 |
75 // Favicon fetch callback. After all favicons are fetched executes | 76 // Favicon fetch callback. After all favicons are fetched executes |
76 // html output on the file thread. | 77 // html output with |background_io_task_runner_|. |
77 void OnFaviconDataAvailable( | 78 void OnFaviconDataAvailable( |
78 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 79 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
79 | 80 |
80 // The Profile object used for accessing FaviconService, bookmarks model. | 81 // The Profile object used for accessing FaviconService, bookmarks model. |
81 Profile* profile_; | 82 Profile* profile_; |
82 | 83 |
83 // All URLs that are extracted from bookmarks. Used to fetch favicons | 84 // All URLs that are extracted from bookmarks. Used to fetch favicons |
84 // for each of them. After favicon is fetched top url is removed from list. | 85 // for each of them. After favicon is fetched top url is removed from list. |
85 std::list<std::string> bookmark_urls_; | 86 std::list<std::string> bookmark_urls_; |
86 | 87 |
87 // Tracks favicon tasks. | 88 // Tracks favicon tasks. |
88 base::CancelableTaskTracker cancelable_task_tracker_; | 89 base::CancelableTaskTracker cancelable_task_tracker_; |
89 | 90 |
90 // Map that stores favicon per URL. | 91 // Map that stores favicon per URL. |
91 std::unique_ptr<URLFaviconMap> favicons_map_; | 92 std::unique_ptr<URLFaviconMap> favicons_map_; |
92 | 93 |
93 // Path where html output is stored. | 94 // Path where html output is stored. |
94 base::FilePath path_; | 95 base::FilePath path_; |
95 | 96 |
96 BookmarksExportObserver* observer_; | 97 BookmarksExportObserver* observer_; |
97 | 98 |
98 content::NotificationRegistrar registrar_; | 99 content::NotificationRegistrar registrar_; |
99 | 100 |
| 101 scoped_refptr<base::SequencedTaskRunner> background_io_task_runner_ = |
| 102 base::CreateSequencedTaskRunnerWithTraits( |
| 103 {base::MayBlock(), base::TaskPriority::BACKGROUND}); |
| 104 |
100 DISALLOW_COPY_AND_ASSIGN(BookmarkFaviconFetcher); | 105 DISALLOW_COPY_AND_ASSIGN(BookmarkFaviconFetcher); |
101 }; | 106 }; |
102 | 107 |
103 namespace bookmark_html_writer { | 108 namespace bookmark_html_writer { |
104 | 109 |
105 // Writes the bookmarks out in the 'bookmarks.html' format understood by | 110 // Writes the bookmarks out in the 'bookmarks.html' format understood by |
106 // Firefox and IE. The results are written to the file at |path|. The file | 111 // Firefox and IE. The results are written asynchronously to the file at |path|. |
107 // thread is used. | |
108 // Before writing to the file favicons are fetched on the main thread. | 112 // Before writing to the file favicons are fetched on the main thread. |
109 // TODO(sky): need a callback on failure. | 113 // TODO(sky): need a callback on failure. |
110 void WriteBookmarks(Profile* profile, | 114 void WriteBookmarks(Profile* profile, |
111 const base::FilePath& path, | 115 const base::FilePath& path, |
112 BookmarksExportObserver* observer); | 116 BookmarksExportObserver* observer); |
113 | 117 |
114 } // namespace bookmark_html_writer | 118 } // namespace bookmark_html_writer |
115 | 119 |
116 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_HTML_WRITER_H_ | 120 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_HTML_WRITER_H_ |
OLD | NEW |