Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(504)

Side by Side Diff: chrome/browser/bookmarks/bookmark_html_writer.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/base64.h" 7 #include "base/base64.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 FetchNextFavicon(); 410 FetchNextFavicon();
411 else 411 else
412 ExecuteWriter(); 412 ExecuteWriter();
413 } 413 }
414 414
415 void BookmarkFaviconFetcher::Observe( 415 void BookmarkFaviconFetcher::Observe(
416 int type, 416 int type,
417 const content::NotificationSource& source, 417 const content::NotificationSource& source,
418 const content::NotificationDetails& details) { 418 const content::NotificationDetails& details) {
419 if (chrome::NOTIFICATION_PROFILE_DESTROYED == type && fetcher != NULL) { 419 if (chrome::NOTIFICATION_PROFILE_DESTROYED == type && fetcher != NULL) {
420 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); 420 base::MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
421 fetcher = NULL; 421 fetcher = NULL;
422 } 422 }
423 } 423 }
424 424
425 void BookmarkFaviconFetcher::ExtractUrls(const BookmarkNode* node) { 425 void BookmarkFaviconFetcher::ExtractUrls(const BookmarkNode* node) {
426 if (node->is_url()) { 426 if (node->is_url()) {
427 std::string url = node->url().spec(); 427 std::string url = node->url().spec();
428 if (!url.empty()) 428 if (!url.empty())
429 bookmark_urls_.push_back(url); 429 bookmark_urls_.push_back(url);
430 } else { 430 } else {
431 for (int i = 0; i < node->child_count(); ++i) 431 for (int i = 0; i < node->child_count(); ++i)
432 ExtractUrls(node->GetChild(i)); 432 ExtractUrls(node->GetChild(i));
433 } 433 }
434 } 434 }
435 435
436 void BookmarkFaviconFetcher::ExecuteWriter() { 436 void BookmarkFaviconFetcher::ExecuteWriter() {
437 // BookmarkModel isn't thread safe (nor would we want to lock it down 437 // BookmarkModel isn't thread safe (nor would we want to lock it down
438 // for the duration of the write), as such we make a copy of the 438 // for the duration of the write), as such we make a copy of the
439 // BookmarkModel using BookmarkCodec then write from that. 439 // BookmarkModel using BookmarkCodec then write from that.
440 BookmarkCodec codec; 440 BookmarkCodec codec;
441 BrowserThread::PostTask( 441 BrowserThread::PostTask(
442 BrowserThread::FILE, FROM_HERE, 442 BrowserThread::FILE, FROM_HERE,
443 base::Bind(&Writer::DoWrite, 443 base::Bind(&Writer::DoWrite,
444 new Writer(codec.Encode(BookmarkModelFactory::GetForProfile( 444 new Writer(codec.Encode(BookmarkModelFactory::GetForProfile(
445 profile_)), 445 profile_)),
446 path_, favicons_map_.release(), observer_))); 446 path_, favicons_map_.release(), observer_)));
447 if (fetcher != NULL) { 447 if (fetcher != NULL) {
448 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); 448 base::MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
449 fetcher = NULL; 449 fetcher = NULL;
450 } 450 }
451 } 451 }
452 452
453 bool BookmarkFaviconFetcher::FetchNextFavicon() { 453 bool BookmarkFaviconFetcher::FetchNextFavicon() {
454 if (bookmark_urls_.empty()) { 454 if (bookmark_urls_.empty()) {
455 return false; 455 return false;
456 } 456 }
457 do { 457 do {
458 std::string url = bookmark_urls_.front(); 458 std::string url = bookmark_urls_.front();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 // BookmarkModel isn't thread safe (nor would we want to lock it down 502 // BookmarkModel isn't thread safe (nor would we want to lock it down
503 // for the duration of the write), as such we make a copy of the 503 // for the duration of the write), as such we make a copy of the
504 // BookmarkModel using BookmarkCodec then write from that. 504 // BookmarkModel using BookmarkCodec then write from that.
505 if (fetcher == NULL) { 505 if (fetcher == NULL) {
506 fetcher = new BookmarkFaviconFetcher(profile, path, observer); 506 fetcher = new BookmarkFaviconFetcher(profile, path, observer);
507 fetcher->ExportBookmarks(); 507 fetcher->ExportBookmarks();
508 } 508 }
509 } 509 }
510 510
511 } // namespace bookmark_html_writer 511 } // namespace bookmark_html_writer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698