Commit 9ed2fda9 authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Coding style cleanup in FontServiceApp

This CL is changing the file path from type SkString to base::FilePath.
It's also using a size_t for iterating through a vector space.

Change-Id: Ic345514557365e1e7a0115eddfae365c1b97b3e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1829791Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarDominik Röttsches <drott@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702107}
parent 89773cf6
......@@ -14,6 +14,7 @@
#include "components/services/font/fontconfig_matching.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "ppapi/buildflags/buildflags.h"
#include "skia/ext/skia_utils_base.h"
#include "ui/gfx/font_fallback_linux.h"
#include "ui/gfx/font_render_params.h"
......@@ -115,7 +116,8 @@ void FontServiceApp::MatchFamilyName(const std::string& family_name,
// Stash away the returned path, so we can give it an ID (index)
// which will later be given to us in a request to open the file.
int index = FindOrAddPath(result_identity.fString);
base::FilePath path(result_identity.fString.c_str());
size_t index = FindOrAddPath(path);
mojom::FontIdentityPtr identity(mojom::FontIdentity::New());
identity->id = static_cast<uint32_t>(index);
......@@ -137,9 +139,8 @@ void FontServiceApp::OpenStream(uint32_t id_number,
DCHECK_LT(id_number, static_cast<uint32_t>(paths_.size()));
base::File file;
if (id_number < static_cast<uint32_t>(paths_.size())) {
file = GetFileForPath(base::FilePath(paths_[id_number].c_str()));
}
if (id_number < static_cast<uint32_t>(paths_.size()))
file = GetFileForPath(paths_[id_number]);
std::move(callback).Run(std::move(file));
}
......@@ -151,7 +152,7 @@ void FontServiceApp::FallbackFontForCharacter(
TRACE_EVENT0("fonts", "FontServiceApp::FallbackFontForCharacter");
auto fallback_font = gfx::GetFallbackFontForChar(character, locale);
int index = FindOrAddPath(SkString(fallback_font.filename.data()));
size_t index = FindOrAddPath(base::FilePath(fallback_font.filename));
mojom::FontIdentityPtr identity(mojom::FontIdentity::New());
identity->id = static_cast<uint32_t>(index);
......@@ -206,8 +207,7 @@ void FontServiceApp::MatchFontByPostscriptNameOrFullFontName(
base::Optional<FontConfigLocalMatching::FontConfigMatchResult> match_result =
FontConfigLocalMatching::FindFontByPostscriptNameOrFullFontName(family);
if (match_result) {
uint32_t fontconfig_interface_id =
FindOrAddPath(SkString(match_result->file_path.value().c_str()));
uint32_t fontconfig_interface_id = FindOrAddPath(match_result->file_path);
mojom::FontIdentityPtr font_identity =
mojom::FontIdentityPtr(mojom::FontIdentity::New(
fontconfig_interface_id, match_result->ttc_index,
......@@ -240,11 +240,11 @@ void FontServiceApp::MatchFontWithFallback(
#endif
}
int FontServiceApp::FindOrAddPath(const SkString& path) {
size_t FontServiceApp::FindOrAddPath(const base::FilePath& path) {
TRACE_EVENT1("fonts", "FontServiceApp::FindOrAddPath", "path",
TRACE_STR_COPY(path.c_str()));
int count = paths_.size();
for (int i = 0; i < count; ++i) {
path.AsUTF8Unsafe());
size_t count = paths_.size();
for (size_t i = 0; i < count; ++i) {
if (path == paths_[i])
return i;
}
......
......@@ -8,10 +8,10 @@
#include <stdint.h>
#include <vector>
#include "base/files/file_path.h"
#include "base/macros.h"
#include "components/services/font/public/mojom/font_service.mojom.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "skia/ext/skia_utils_base.h"
namespace font_service {
......@@ -48,13 +48,13 @@ class FontServiceApp : public mojom::FontService {
uint32_t charset,
uint32_t fallbackFamilyType,
MatchFontWithFallbackCallback callback) override;
int FindOrAddPath(const SkString& path);
size_t FindOrAddPath(const base::FilePath& path);
mojo::ReceiverSet<mojom::FontService> receivers_;
// We don't want to leak paths to our callers; we thus enumerate the paths of
// fonts.
std::vector<SkString> paths_;
std::vector<base::FilePath> paths_;
DISALLOW_COPY_AND_ASSIGN(FontServiceApp);
};
......
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