| 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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 favicons_map_.reset(new URLFaviconMap()); | 402 favicons_map_.reset(new URLFaviconMap()); |
| 403 registrar_.Add(this, | 403 registrar_.Add(this, |
| 404 chrome::NOTIFICATION_PROFILE_DESTROYED, | 404 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 405 content::Source<Profile>(profile_)); | 405 content::Source<Profile>(profile_)); |
| 406 } | 406 } |
| 407 | 407 |
| 408 BookmarkFaviconFetcher::~BookmarkFaviconFetcher() { | 408 BookmarkFaviconFetcher::~BookmarkFaviconFetcher() { |
| 409 } | 409 } |
| 410 | 410 |
| 411 void BookmarkFaviconFetcher::ExportBookmarks() { | 411 void BookmarkFaviconFetcher::ExportBookmarks() { |
| 412 ExtractUrls(BookmarkModelFactory::GetForProfile( | 412 ExtractUrls(BookmarkModelFactory::GetForBrowserContext(profile_) |
| 413 profile_)->bookmark_bar_node()); | 413 ->bookmark_bar_node()); |
| 414 ExtractUrls(BookmarkModelFactory::GetForProfile(profile_)->other_node()); | 414 ExtractUrls( |
| 415 ExtractUrls(BookmarkModelFactory::GetForProfile(profile_)->mobile_node()); | 415 BookmarkModelFactory::GetForBrowserContext(profile_)->other_node()); |
| 416 ExtractUrls( |
| 417 BookmarkModelFactory::GetForBrowserContext(profile_)->mobile_node()); |
| 416 if (!bookmark_urls_.empty()) | 418 if (!bookmark_urls_.empty()) |
| 417 FetchNextFavicon(); | 419 FetchNextFavicon(); |
| 418 else | 420 else |
| 419 ExecuteWriter(); | 421 ExecuteWriter(); |
| 420 } | 422 } |
| 421 | 423 |
| 422 void BookmarkFaviconFetcher::Observe( | 424 void BookmarkFaviconFetcher::Observe( |
| 423 int type, | 425 int type, |
| 424 const content::NotificationSource& source, | 426 const content::NotificationSource& source, |
| 425 const content::NotificationDetails& details) { | 427 const content::NotificationDetails& details) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 441 } | 443 } |
| 442 } | 444 } |
| 443 | 445 |
| 444 void BookmarkFaviconFetcher::ExecuteWriter() { | 446 void BookmarkFaviconFetcher::ExecuteWriter() { |
| 445 // BookmarkModel isn't thread safe (nor would we want to lock it down | 447 // BookmarkModel isn't thread safe (nor would we want to lock it down |
| 446 // for the duration of the write), as such we make a copy of the | 448 // for the duration of the write), as such we make a copy of the |
| 447 // BookmarkModel using BookmarkCodec then write from that. | 449 // BookmarkModel using BookmarkCodec then write from that. |
| 448 BookmarkCodec codec; | 450 BookmarkCodec codec; |
| 449 BrowserThread::PostTask( | 451 BrowserThread::PostTask( |
| 450 BrowserThread::FILE, FROM_HERE, | 452 BrowserThread::FILE, FROM_HERE, |
| 451 base::Bind(&Writer::DoWrite, | 453 base::Bind( |
| 452 new Writer(codec.Encode(BookmarkModelFactory::GetForProfile( | 454 &Writer::DoWrite, |
| 453 profile_)), | 455 new Writer(codec.Encode( |
| 454 path_, favicons_map_.release(), observer_))); | 456 BookmarkModelFactory::GetForBrowserContext(profile_)), |
| 457 path_, favicons_map_.release(), observer_))); |
| 455 if (g_fetcher) { | 458 if (g_fetcher) { |
| 456 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, g_fetcher); | 459 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, g_fetcher); |
| 457 g_fetcher = nullptr; | 460 g_fetcher = nullptr; |
| 458 } | 461 } |
| 459 } | 462 } |
| 460 | 463 |
| 461 bool BookmarkFaviconFetcher::FetchNextFavicon() { | 464 bool BookmarkFaviconFetcher::FetchNextFavicon() { |
| 462 if (bookmark_urls_.empty()) { | 465 if (bookmark_urls_.empty()) { |
| 463 return false; | 466 return false; |
| 464 } | 467 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 // 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 |
| 512 // 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 |
| 513 // BookmarkModel using BookmarkCodec then write from that. | 516 // BookmarkModel using BookmarkCodec then write from that. |
| 514 if (!g_fetcher) { | 517 if (!g_fetcher) { |
| 515 g_fetcher = new BookmarkFaviconFetcher(profile, path, observer); | 518 g_fetcher = new BookmarkFaviconFetcher(profile, path, observer); |
| 516 g_fetcher->ExportBookmarks(); | 519 g_fetcher->ExportBookmarks(); |
| 517 } | 520 } |
| 518 } | 521 } |
| 519 | 522 |
| 520 } // namespace bookmark_html_writer | 523 } // namespace bookmark_html_writer |
| OLD | NEW |