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> |
11 | 11 |
12 #include "base/base64.h" | 12 #include "base/base64.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/files/file.h" | 16 #include "base/files/file.h" |
17 #include "base/location.h" | 17 #include "base/location.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
22 #include "base/task_scheduler/post_task.h" | |
22 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
23 #include "base/time/time.h" | 24 #include "base/time/time.h" |
24 #include "base/values.h" | 25 #include "base/values.h" |
25 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 26 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
26 #include "chrome/browser/chrome_notification_types.h" | 27 #include "chrome/browser/chrome_notification_types.h" |
27 #include "chrome/browser/favicon/favicon_service_factory.h" | 28 #include "chrome/browser/favicon/favicon_service_factory.h" |
28 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
29 #include "components/bookmarks/browser/bookmark_codec.h" | 30 #include "components/bookmarks/browser/bookmark_codec.h" |
30 #include "components/bookmarks/browser/bookmark_model.h" | 31 #include "components/bookmarks/browser/bookmark_model.h" |
31 #include "components/favicon/core/favicon_service.h" | 32 #include "components/favicon/core/favicon_service.h" |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 for (int i = 0; i < node->child_count(); ++i) | 443 for (int i = 0; i < node->child_count(); ++i) |
443 ExtractUrls(node->GetChild(i)); | 444 ExtractUrls(node->GetChild(i)); |
444 } | 445 } |
445 } | 446 } |
446 | 447 |
447 void BookmarkFaviconFetcher::ExecuteWriter() { | 448 void BookmarkFaviconFetcher::ExecuteWriter() { |
448 // BookmarkModel isn't thread safe (nor would we want to lock it down | 449 // BookmarkModel isn't thread safe (nor would we want to lock it down |
449 // for the duration of the write), as such we make a copy of the | 450 // for the duration of the write), as such we make a copy of the |
450 // BookmarkModel using BookmarkCodec then write from that. | 451 // BookmarkModel using BookmarkCodec then write from that. |
451 BookmarkCodec codec; | 452 BookmarkCodec codec; |
452 BrowserThread::PostTask( | 453 // TODO(https://crbug.com/676387) make this sequenced when 676387 is fixed. |
453 BrowserThread::FILE, FROM_HERE, | 454 scoped_refptr<base::SingleThreadTaskRunner> task_runner_ = |
sky
2017/05/22 16:40:46
Forgive my ignorance, but what happens if ExecuteW
Sébastien Marchand
2017/05/22 17:19:17
+fdoray@/robliao@ as I'm not entirely sure, one so
robliao
2017/05/22 17:27:25
As coded here, if ExecuteRunner is executed twice
sky
2017/05/22 17:33:55
While likely rare, we should make sure there aren'
Sébastien Marchand
2017/05/23 16:56:48
One way to do this would be to add a SequencedTask
gab
2017/05/23 17:17:00
I agree with sky that although there's only one ca
| |
455 base::CreateSingleThreadTaskRunnerWithTraits( | |
456 {base::MayBlock(), base::TaskPriority::BACKGROUND}); | |
457 task_runner_->PostTask( | |
458 FROM_HERE, | |
454 base::BindOnce( | 459 base::BindOnce( |
455 &Writer::DoWrite, | 460 &Writer::DoWrite, |
456 new Writer(codec.Encode( | 461 new Writer(codec.Encode( |
457 BookmarkModelFactory::GetForBrowserContext(profile_)), | 462 BookmarkModelFactory::GetForBrowserContext(profile_)), |
458 path_, favicons_map_.release(), observer_))); | 463 path_, favicons_map_.release(), observer_))); |
459 if (g_fetcher) { | 464 if (g_fetcher) { |
460 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, g_fetcher); | 465 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, g_fetcher); |
461 g_fetcher = nullptr; | 466 g_fetcher = nullptr; |
462 } | 467 } |
463 } | 468 } |
(...skipping 51 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 | 520 // 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 | 521 // for the duration of the write), as such we make a copy of the |
517 // BookmarkModel using BookmarkCodec then write from that. | 522 // BookmarkModel using BookmarkCodec then write from that. |
518 if (!g_fetcher) { | 523 if (!g_fetcher) { |
519 g_fetcher = new BookmarkFaviconFetcher(profile, path, observer); | 524 g_fetcher = new BookmarkFaviconFetcher(profile, path, observer); |
520 g_fetcher->ExportBookmarks(); | 525 g_fetcher->ExportBookmarks(); |
521 } | 526 } |
522 } | 527 } |
523 | 528 |
524 } // namespace bookmark_html_writer | 529 } // namespace bookmark_html_writer |
OLD | NEW |