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() { ...@@ -285,38 +285,38 @@ ExtensionFunction::ResponseAction FontSettingsSetFontFunction::Run() {
return RespondNow(NoArguments()); return RespondNow(NoArguments());
} }
bool FontSettingsGetFontListFunction::RunAsync() { ExtensionFunction::ResponseAction FontSettingsGetFontListFunction::Run() {
content::GetFontListAsync( content::GetFontListAsync(
BindOnce(&FontSettingsGetFontListFunction::FontListHasLoaded, this)); BindOnce(&FontSettingsGetFontListFunction::FontListHasLoaded, this));
return true; return RespondLater();
} }
void FontSettingsGetFontListFunction::FontListHasLoaded( void FontSettingsGetFontListFunction::FontListHasLoaded(
std::unique_ptr<base::ListValue> list) { std::unique_ptr<base::ListValue> list) {
bool success = CopyFontsToResult(list.get()); ExtensionFunction::ResponseValue response = CopyFontsToResult(list.get());
SendResponse(success); Respond(std::move(response));
} }
bool FontSettingsGetFontListFunction::CopyFontsToResult( ExtensionFunction::ResponseValue
base::ListValue* fonts) { FontSettingsGetFontListFunction::CopyFontsToResult(base::ListValue* fonts) {
std::unique_ptr<base::ListValue> result(new base::ListValue()); std::unique_ptr<base::ListValue> result(new base::ListValue());
for (auto it = fonts->begin(); it != fonts->end(); ++it) { for (auto it = fonts->begin(); it != fonts->end(); ++it) {
base::ListValue* font_list_value; base::ListValue* font_list_value;
if (!it->GetAsList(&font_list_value)) { if (!it->GetAsList(&font_list_value)) {
NOTREACHED(); NOTREACHED();
return false; return Error("");
} }
std::string name; std::string name;
if (!font_list_value->GetString(0, &name)) { if (!font_list_value->GetString(0, &name)) {
NOTREACHED(); NOTREACHED();
return false; return Error("");
} }
std::string localized_name; std::string localized_name;
if (!font_list_value->GetString(1, &localized_name)) { if (!font_list_value->GetString(1, &localized_name)) {
NOTREACHED(); NOTREACHED();
return false; return Error("");
} }
std::unique_ptr<base::DictionaryValue> font_name( std::unique_ptr<base::DictionaryValue> font_name(
...@@ -327,8 +327,7 @@ bool FontSettingsGetFontListFunction::CopyFontsToResult( ...@@ -327,8 +327,7 @@ bool FontSettingsGetFontListFunction::CopyFontsToResult(
result->Append(std::move(font_name)); result->Append(std::move(font_name));
} }
SetResult(std::move(result)); return OneArgument(std::move(result));
return true;
} }
ExtensionFunction::ResponseAction ClearFontPrefExtensionFunction::Run() { ExtensionFunction::ResponseAction ClearFontPrefExtensionFunction::Run() {
......
...@@ -12,13 +12,13 @@ ...@@ -12,13 +12,13 @@
#include <string> #include <string>
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/extensions/chrome_extension_function.h"
#include "chrome/browser/font_pref_change_notifier.h" #include "chrome/browser/font_pref_change_notifier.h"
#include "components/prefs/pref_change_registrar.h" #include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "extensions/browser/browser_context_keyed_api_factory.h" #include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/event_router.h" #include "extensions/browser/event_router.h"
#include "extensions/browser/extension_event_histogram_value.h" #include "extensions/browser/extension_event_histogram_value.h"
#include "extensions/browser/extension_function.h"
class Profile; class Profile;
...@@ -139,7 +139,7 @@ class FontSettingsSetFontFunction : public ExtensionFunction { ...@@ -139,7 +139,7 @@ class FontSettingsSetFontFunction : public ExtensionFunction {
}; };
// fontSettings.getFontList API function. // fontSettings.getFontList API function.
class FontSettingsGetFontListFunction : public ChromeAsyncExtensionFunction { class FontSettingsGetFontListFunction : public ExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("fontSettings.getFontList", DECLARE_EXTENSION_FUNCTION("fontSettings.getFontList",
FONTSETTINGS_GETFONTLIST) FONTSETTINGS_GETFONTLIST)
...@@ -148,11 +148,11 @@ class FontSettingsGetFontListFunction : public ChromeAsyncExtensionFunction { ...@@ -148,11 +148,11 @@ class FontSettingsGetFontListFunction : public ChromeAsyncExtensionFunction {
~FontSettingsGetFontListFunction() override {} ~FontSettingsGetFontListFunction() override {}
// ExtensionFunction: // ExtensionFunction:
bool RunAsync() override; ResponseAction Run() override;
private: private:
void FontListHasLoaded(std::unique_ptr<base::ListValue> list); 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. // 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