Commit eeb6ecad authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

[Extensions Functions] Migrate fontSettings.getFontList() to ExtensionFunction

Bug: 634140
Change-Id: I8c9e30665ae58b290d1a180e1aeceac8b8f26d08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2065808Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Anand Mistry <amistry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742933}
parent 29813676
......@@ -285,38 +285,38 @@ ExtensionFunction::ResponseAction FontSettingsSetFontFunction::Run() {
return RespondNow(NoArguments());
}
bool FontSettingsGetFontListFunction::RunAsync() {
ExtensionFunction::ResponseAction FontSettingsGetFontListFunction::Run() {
content::GetFontListAsync(
BindOnce(&FontSettingsGetFontListFunction::FontListHasLoaded, this));
return true;
return RespondLater();
}
void FontSettingsGetFontListFunction::FontListHasLoaded(
std::unique_ptr<base::ListValue> list) {
bool success = CopyFontsToResult(list.get());
SendResponse(success);
ExtensionFunction::ResponseValue response = CopyFontsToResult(list.get());
Respond(std::move(response));
}
bool FontSettingsGetFontListFunction::CopyFontsToResult(
base::ListValue* fonts) {
ExtensionFunction::ResponseValue
FontSettingsGetFontListFunction::CopyFontsToResult(base::ListValue* fonts) {
std::unique_ptr<base::ListValue> result(new base::ListValue());
for (auto it = fonts->begin(); it != fonts->end(); ++it) {
base::ListValue* font_list_value;
if (!it->GetAsList(&font_list_value)) {
NOTREACHED();
return false;
return Error("");
}
std::string name;
if (!font_list_value->GetString(0, &name)) {
NOTREACHED();
return false;
return Error("");
}
std::string localized_name;
if (!font_list_value->GetString(1, &localized_name)) {
NOTREACHED();
return false;
return Error("");
}
std::unique_ptr<base::DictionaryValue> font_name(
......@@ -327,8 +327,7 @@ bool FontSettingsGetFontListFunction::CopyFontsToResult(
result->Append(std::move(font_name));
}
SetResult(std::move(result));
return true;
return OneArgument(std::move(result));
}
ExtensionFunction::ResponseAction ClearFontPrefExtensionFunction::Run() {
......
......@@ -12,13 +12,13 @@
#include <string>
#include "base/macros.h"
#include "chrome/browser/extensions/chrome_extension_function.h"
#include "chrome/browser/font_pref_change_notifier.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_service.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_event_histogram_value.h"
#include "extensions/browser/extension_function.h"
class Profile;
......@@ -139,7 +139,7 @@ class FontSettingsSetFontFunction : public ExtensionFunction {
};
// fontSettings.getFontList API function.
class FontSettingsGetFontListFunction : public ChromeAsyncExtensionFunction {
class FontSettingsGetFontListFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fontSettings.getFontList",
FONTSETTINGS_GETFONTLIST)
......@@ -148,11 +148,11 @@ class FontSettingsGetFontListFunction : public ChromeAsyncExtensionFunction {
~FontSettingsGetFontListFunction() override {}
// ExtensionFunction:
bool RunAsync() override;
ResponseAction Run() override;
private:
void FontListHasLoaded(std::unique_ptr<base::ListValue> list);
bool CopyFontsToResult(base::ListValue* fonts);
ResponseValue CopyFontsToResult(base::ListValue* fonts);
};
// Base class for extension API functions that clear a browser font pref.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment