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

Unified Diff: content/browser/hyphenation/hyphenation_impl.cc

Issue 2539383002: Replace base::File wrapping with typemapping. (Closed)
Patch Set: Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/hyphenation/hyphenation_impl.cc
diff --git a/content/browser/hyphenation/hyphenation_impl.cc b/content/browser/hyphenation/hyphenation_impl.cc
index 32c9730e3e81aac378bcc80904d2e7be3e1c4762..02ba320475b30d7ba256a5986537f0ae6e0bbe88 100644
--- a/content/browser/hyphenation/hyphenation_impl.cc
+++ b/content/browser/hyphenation/hyphenation_impl.cc
@@ -15,25 +15,24 @@
#include "base/strings/stringprintf.h"
#include "base/timer/elapsed_timer.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
-#include "mojo/public/cpp/system/platform_handle.h"
namespace {
using DictionaryFileMap = std::unordered_map<std::string, base::File>;
-static bool IsValidLocale(const std::string& locale) {
+bool IsValidLocale(const std::string& locale) {
return std::all_of(locale.cbegin(), locale.cend(), [](const char ch) {
return base::IsAsciiAlpha(ch) || base::IsAsciiDigit(ch) || ch == '-';
});
}
-static base::File& GetDictionaryFile(const std::string& locale) {
+base::File GetDictionaryFile(const std::string& locale) {
// Keep Files open in the cache for subsequent calls.
CR_DEFINE_STATIC_LOCAL(DictionaryFileMap, cache, ());
const auto& it = cache.find(locale);
if (it != cache.end())
- return it->second;
+ return it->second.Duplicate();
const auto& inserted = cache.insert(std::make_pair(locale, base::File()));
base::File& file = inserted.first->second;
DCHECK(!file.IsValid());
@@ -48,7 +47,7 @@ static base::File& GetDictionaryFile(const std::string& locale) {
base::ElapsedTimer timer;
file.Initialize(path, base::File::FLAG_OPEN | base::File::FLAG_READ);
UMA_HISTOGRAM_TIMES("Hyphenation.Open.File", timer.Elapsed());
- return file;
+ return file.Duplicate();
}
} // namespace
@@ -67,13 +66,10 @@ void HyphenationImpl::Create(blink::mojom::HyphenationRequest request) {
void HyphenationImpl::OpenDictionary(const std::string& locale,
const OpenDictionaryCallback& callback) {
- mojo::ScopedHandle handle;
- if (IsValidLocale(locale)) {
- base::File& file = GetDictionaryFile(locale);
- if (file.IsValid())
- handle = mojo::WrapPlatformFile(file.Duplicate().TakePlatformFile());
- }
- callback.Run(std::move(handle));
+ if (IsValidLocale(locale))
+ callback.Run(GetDictionaryFile(locale));
+ else
+ callback.Run(base::File());
}
} // namespace hyphenation

Powered by Google App Engine
This is Rietveld 408576698