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

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

Issue 2216713002: Use BookmarkModelFactory::GetForBrowserContext everywhere (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bookmarks
Patch Set: Replace in .mm files Created 4 years, 4 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
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 <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/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
23 #include "base/time/time.h" 23 #include "base/time/time.h"
24 #include "base/values.h" 24 #include "base/values.h"
25 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 25 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
26 #include "chrome/browser/chrome_notification_types.h" 26 #include "chrome/browser/chrome_notification_types.h"
27 #include "chrome/browser/favicon/favicon_service_factory.h" 27 #include "chrome/browser/favicon/favicon_service_factory.h"
28 #include "chrome/browser/profiles/profile.h"
28 #include "components/bookmarks/browser/bookmark_codec.h" 29 #include "components/bookmarks/browser/bookmark_codec.h"
29 #include "components/bookmarks/browser/bookmark_model.h" 30 #include "components/bookmarks/browser/bookmark_model.h"
30 #include "components/favicon/core/favicon_service.h" 31 #include "components/favicon/core/favicon_service.h"
31 #include "components/favicon_base/favicon_types.h" 32 #include "components/favicon_base/favicon_types.h"
32 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
33 #include "content/public/browser/notification_source.h" 34 #include "content/public/browser/notification_source.h"
34 #include "grit/components_strings.h" 35 #include "grit/components_strings.h"
35 #include "net/base/escape.h" 36 #include "net/base/escape.h"
36 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
37 #include "ui/gfx/favicon_size.h" 38 #include "ui/gfx/favicon_size.h"
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 favicons_map_.reset(new URLFaviconMap()); 403 favicons_map_.reset(new URLFaviconMap());
403 registrar_.Add(this, 404 registrar_.Add(this,
404 chrome::NOTIFICATION_PROFILE_DESTROYED, 405 chrome::NOTIFICATION_PROFILE_DESTROYED,
405 content::Source<Profile>(profile_)); 406 content::Source<Profile>(profile_));
406 } 407 }
407 408
408 BookmarkFaviconFetcher::~BookmarkFaviconFetcher() { 409 BookmarkFaviconFetcher::~BookmarkFaviconFetcher() {
409 } 410 }
410 411
411 void BookmarkFaviconFetcher::ExportBookmarks() { 412 void BookmarkFaviconFetcher::ExportBookmarks() {
412 ExtractUrls(BookmarkModelFactory::GetForProfile( 413 ExtractUrls(BookmarkModelFactory::GetForBrowserContext(profile_)
413 profile_)->bookmark_bar_node()); 414 ->bookmark_bar_node());
414 ExtractUrls(BookmarkModelFactory::GetForProfile(profile_)->other_node()); 415 ExtractUrls(
415 ExtractUrls(BookmarkModelFactory::GetForProfile(profile_)->mobile_node()); 416 BookmarkModelFactory::GetForBrowserContext(profile_)->other_node());
417 ExtractUrls(
418 BookmarkModelFactory::GetForBrowserContext(profile_)->mobile_node());
416 if (!bookmark_urls_.empty()) 419 if (!bookmark_urls_.empty())
417 FetchNextFavicon(); 420 FetchNextFavicon();
418 else 421 else
419 ExecuteWriter(); 422 ExecuteWriter();
420 } 423 }
421 424
422 void BookmarkFaviconFetcher::Observe( 425 void BookmarkFaviconFetcher::Observe(
423 int type, 426 int type,
424 const content::NotificationSource& source, 427 const content::NotificationSource& source,
425 const content::NotificationDetails& details) { 428 const content::NotificationDetails& details) {
(...skipping 15 matching lines...) Expand all
441 } 444 }
442 } 445 }
443 446
444 void BookmarkFaviconFetcher::ExecuteWriter() { 447 void BookmarkFaviconFetcher::ExecuteWriter() {
445 // BookmarkModel isn't thread safe (nor would we want to lock it down 448 // 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 449 // for the duration of the write), as such we make a copy of the
447 // BookmarkModel using BookmarkCodec then write from that. 450 // BookmarkModel using BookmarkCodec then write from that.
448 BookmarkCodec codec; 451 BookmarkCodec codec;
449 BrowserThread::PostTask( 452 BrowserThread::PostTask(
450 BrowserThread::FILE, FROM_HERE, 453 BrowserThread::FILE, FROM_HERE,
451 base::Bind(&Writer::DoWrite, 454 base::Bind(
452 new Writer(codec.Encode(BookmarkModelFactory::GetForProfile( 455 &Writer::DoWrite,
453 profile_)), 456 new Writer(codec.Encode(
454 path_, favicons_map_.release(), observer_))); 457 BookmarkModelFactory::GetForBrowserContext(profile_)),
458 path_, favicons_map_.release(), observer_)));
455 if (g_fetcher) { 459 if (g_fetcher) {
456 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, g_fetcher); 460 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, g_fetcher);
457 g_fetcher = nullptr; 461 g_fetcher = nullptr;
458 } 462 }
459 } 463 }
460 464
461 bool BookmarkFaviconFetcher::FetchNextFavicon() { 465 bool BookmarkFaviconFetcher::FetchNextFavicon() {
462 if (bookmark_urls_.empty()) { 466 if (bookmark_urls_.empty()) {
463 return false; 467 return false;
464 } 468 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 // BookmarkModel isn't thread safe (nor would we want to lock it down 515 // 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 516 // for the duration of the write), as such we make a copy of the
513 // BookmarkModel using BookmarkCodec then write from that. 517 // BookmarkModel using BookmarkCodec then write from that.
514 if (!g_fetcher) { 518 if (!g_fetcher) {
515 g_fetcher = new BookmarkFaviconFetcher(profile, path, observer); 519 g_fetcher = new BookmarkFaviconFetcher(profile, path, observer);
516 g_fetcher->ExportBookmarks(); 520 g_fetcher->ExportBookmarks();
517 } 521 }
518 } 522 }
519 523
520 } // namespace bookmark_html_writer 524 } // namespace bookmark_html_writer
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/in_memory_url_index_factory.cc ('k') | chrome/browser/bookmarks/bookmark_html_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698