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

Side by Side Diff: components/dom_distiller/core/distilled_page_prefs.cc

Issue 1144153004: components: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/dom_distiller/core/distilled_page_prefs.h" 5 #include "components/dom_distiller/core/distilled_page_prefs.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h"
8 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/observer_list.h" 10 #include "base/observer_list.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/thread_task_runner_handle.h"
12 #include "components/pref_registry/pref_registry_syncable.h" 14 #include "components/pref_registry/pref_registry_syncable.h"
13 15
14 namespace { 16 namespace {
15 17
16 // Path to the integer corresponding to user's preference theme. 18 // Path to the integer corresponding to user's preference theme.
17 const char kFontPref[] = "dom_distiller.font_family"; 19 const char kFontPref[] = "dom_distiller.font_family";
18 // Path to the integer corresponding to user's preference font family. 20 // Path to the integer corresponding to user's preference font family.
19 const char kThemePref[] = "dom_distiller.theme"; 21 const char kThemePref[] = "dom_distiller.theme";
20 } 22 }
21 23
(...skipping 15 matching lines...) Expand all
37 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 39 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
38 registry->RegisterIntegerPref( 40 registry->RegisterIntegerPref(
39 kFontPref, 41 kFontPref,
40 DistilledPagePrefs::SANS_SERIF, 42 DistilledPagePrefs::SANS_SERIF,
41 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 43 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
42 } 44 }
43 45
44 void DistilledPagePrefs::SetFontFamily( 46 void DistilledPagePrefs::SetFontFamily(
45 DistilledPagePrefs::FontFamily new_font_family) { 47 DistilledPagePrefs::FontFamily new_font_family) {
46 pref_service_->SetInteger(kFontPref, new_font_family); 48 pref_service_->SetInteger(kFontPref, new_font_family);
47 base::MessageLoop::current()->PostTask( 49 base::ThreadTaskRunnerHandle::Get()->PostTask(
48 FROM_HERE, 50 FROM_HERE, base::Bind(&DistilledPagePrefs::NotifyOnChangeFontFamily,
49 base::Bind(&DistilledPagePrefs::NotifyOnChangeFontFamily, 51 weak_ptr_factory_.GetWeakPtr(), new_font_family));
50 weak_ptr_factory_.GetWeakPtr(),
51 new_font_family));
52 } 52 }
53 53
54 DistilledPagePrefs::FontFamily DistilledPagePrefs::GetFontFamily() { 54 DistilledPagePrefs::FontFamily DistilledPagePrefs::GetFontFamily() {
55 int font_family = pref_service_->GetInteger(kFontPref); 55 int font_family = pref_service_->GetInteger(kFontPref);
56 if (font_family < 0 || font_family >= DistilledPagePrefs::FONT_FAMILY_COUNT) { 56 if (font_family < 0 || font_family >= DistilledPagePrefs::FONT_FAMILY_COUNT) {
57 // Persisted data was incorrect, trying to clean it up by storing the 57 // Persisted data was incorrect, trying to clean it up by storing the
58 // default. 58 // default.
59 SetFontFamily(DistilledPagePrefs::SANS_SERIF); 59 SetFontFamily(DistilledPagePrefs::SANS_SERIF);
60 return DistilledPagePrefs::SANS_SERIF; 60 return DistilledPagePrefs::SANS_SERIF;
61 } 61 }
62 return static_cast<FontFamily>(font_family); 62 return static_cast<FontFamily>(font_family);
63 } 63 }
64 64
65 void DistilledPagePrefs::SetTheme(DistilledPagePrefs::Theme new_theme) { 65 void DistilledPagePrefs::SetTheme(DistilledPagePrefs::Theme new_theme) {
66 pref_service_->SetInteger(kThemePref, new_theme); 66 pref_service_->SetInteger(kThemePref, new_theme);
67 base::MessageLoop::current()->PostTask( 67 base::ThreadTaskRunnerHandle::Get()->PostTask(
68 FROM_HERE, 68 FROM_HERE, base::Bind(&DistilledPagePrefs::NotifyOnChangeTheme,
69 base::Bind(&DistilledPagePrefs::NotifyOnChangeTheme, 69 weak_ptr_factory_.GetWeakPtr(), new_theme));
70 weak_ptr_factory_.GetWeakPtr(),
71 new_theme));
72 } 70 }
73 71
74 DistilledPagePrefs::Theme DistilledPagePrefs::GetTheme() { 72 DistilledPagePrefs::Theme DistilledPagePrefs::GetTheme() {
75 int theme = pref_service_->GetInteger(kThemePref); 73 int theme = pref_service_->GetInteger(kThemePref);
76 if (theme < 0 || theme >= DistilledPagePrefs::THEME_COUNT) { 74 if (theme < 0 || theme >= DistilledPagePrefs::THEME_COUNT) {
77 // Persisted data was incorrect, trying to clean it up by storing the 75 // Persisted data was incorrect, trying to clean it up by storing the
78 // default. 76 // default.
79 SetTheme(DistilledPagePrefs::LIGHT); 77 SetTheme(DistilledPagePrefs::LIGHT);
80 return DistilledPagePrefs::LIGHT; 78 return DistilledPagePrefs::LIGHT;
81 } 79 }
(...skipping 12 matching lines...) Expand all
94 DistilledPagePrefs::FontFamily new_font_family) { 92 DistilledPagePrefs::FontFamily new_font_family) {
95 FOR_EACH_OBSERVER(Observer, observers_, OnChangeFontFamily(new_font_family)); 93 FOR_EACH_OBSERVER(Observer, observers_, OnChangeFontFamily(new_font_family));
96 } 94 }
97 95
98 void DistilledPagePrefs::NotifyOnChangeTheme( 96 void DistilledPagePrefs::NotifyOnChangeTheme(
99 DistilledPagePrefs::Theme new_theme) { 97 DistilledPagePrefs::Theme new_theme) {
100 FOR_EACH_OBSERVER(Observer, observers_, OnChangeTheme(new_theme)); 98 FOR_EACH_OBSERVER(Observer, observers_, OnChangeTheme(new_theme));
101 } 99 }
102 100
103 } // namespace dom_distiller 101 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « components/dom_distiller/core/distilled_content_store.cc ('k') | components/dom_distiller/core/distiller_page.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698