| 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 #include "chrome/browser/bookmarks/bookmark_html_writer.h" | 5 #include "chrome/browser/bookmarks/bookmark_html_writer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 const char kFolderChildren[] = "<DL><p>"; | 89 const char kFolderChildren[] = "<DL><p>"; |
| 90 // End of the children for a folder. | 90 // End of the children for a folder. |
| 91 const char kFolderChildrenEnd[] = "</DL><p>"; | 91 const char kFolderChildrenEnd[] = "</DL><p>"; |
| 92 | 92 |
| 93 // Number of characters to indent by. | 93 // Number of characters to indent by. |
| 94 const size_t kIndentSize = 4; | 94 const size_t kIndentSize = 4; |
| 95 | 95 |
| 96 // Class responsible for the actual writing. Takes ownership of favicons_map. | 96 // Class responsible for the actual writing. Takes ownership of favicons_map. |
| 97 class Writer : public base::RefCountedThreadSafe<Writer> { | 97 class Writer : public base::RefCountedThreadSafe<Writer> { |
| 98 public: | 98 public: |
| 99 Writer(base::Value* bookmarks, | 99 Writer(std::unique_ptr<base::Value> bookmarks, |
| 100 const base::FilePath& path, | 100 const base::FilePath& path, |
| 101 BookmarkFaviconFetcher::URLFaviconMap* favicons_map, | 101 BookmarkFaviconFetcher::URLFaviconMap* favicons_map, |
| 102 BookmarksExportObserver* observer) | 102 BookmarksExportObserver* observer) |
| 103 : bookmarks_(bookmarks), | 103 : bookmarks_(std::move(bookmarks)), |
| 104 path_(path), | 104 path_(path), |
| 105 favicons_map_(favicons_map), | 105 favicons_map_(favicons_map), |
| 106 observer_(observer) { | 106 observer_(observer) {} |
| 107 } | |
| 108 | 107 |
| 109 // Writing bookmarks and favicons data to file. | 108 // Writing bookmarks and favicons data to file. |
| 110 void DoWrite() { | 109 void DoWrite() { |
| 111 if (!OpenFile()) | 110 if (!OpenFile()) |
| 112 return; | 111 return; |
| 113 | 112 |
| 114 base::Value* roots = NULL; | 113 base::Value* roots = NULL; |
| 115 if (!Write(kHeader) || | 114 if (!Write(kHeader) || |
| 116 bookmarks_->GetType() != base::Value::Type::DICTIONARY || | 115 bookmarks_->GetType() != base::Value::Type::DICTIONARY || |
| 117 !static_cast<base::DictionaryValue*>(bookmarks_.get())->Get( | 116 !static_cast<base::DictionaryValue*>(bookmarks_.get())->Get( |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 // BookmarkModel isn't thread safe (nor would we want to lock it down | 514 // BookmarkModel isn't thread safe (nor would we want to lock it down |
| 516 // for the duration of the write), as such we make a copy of the | 515 // for the duration of the write), as such we make a copy of the |
| 517 // BookmarkModel using BookmarkCodec then write from that. | 516 // BookmarkModel using BookmarkCodec then write from that. |
| 518 if (!g_fetcher) { | 517 if (!g_fetcher) { |
| 519 g_fetcher = new BookmarkFaviconFetcher(profile, path, observer); | 518 g_fetcher = new BookmarkFaviconFetcher(profile, path, observer); |
| 520 g_fetcher->ExportBookmarks(); | 519 g_fetcher->ExportBookmarks(); |
| 521 } | 520 } |
| 522 } | 521 } |
| 523 | 522 |
| 524 } // namespace bookmark_html_writer | 523 } // namespace bookmark_html_writer |
| OLD | NEW |