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

Unified Diff: third_party/WebKit/Source/platform/text/hyphenation/HyphenationMinikin.cpp

Issue 2113933003: Add mojo interface to load hyphenation dictionaries on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: jam/eae review Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/text/hyphenation/HyphenationMinikin.cpp
diff --git a/third_party/WebKit/Source/platform/text/hyphenation/HyphenationMinikin.cpp b/third_party/WebKit/Source/platform/text/hyphenation/HyphenationMinikin.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..db50d982149da035ddb17aaa5e7779e0c286776b
--- /dev/null
+++ b/third_party/WebKit/Source/platform/text/hyphenation/HyphenationMinikin.cpp
@@ -0,0 +1,89 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "platform/text/Hyphenation.h"
+
+#include "base/files/file.h"
+#include "base/files/memory_mapped_file.h"
+#include "base/metrics/histogram.h"
+#include "base/timer/elapsed_timer.h"
+#include "mojo/public/cpp/system/platform_handle.h"
+#include "public/platform/Platform.h"
+#include "public/platform/ServiceRegistry.h"
+#include "public/platform/modules/hyphenation/hyphenation.mojom-blink.h"
+
+namespace blink {
+
+class HyphenationMinikin : public Hyphenation {
+public:
+ bool openDictionary(const AtomicString& locale);
+
+ size_t lastHyphenLocation(const StringView& text, size_t beforeIndex) const override;
+
+private:
+ static base::PlatformFile openDictionaryFile(const AtomicString& locale);
+
+ base::MemoryMappedFile m_file;
+};
+
+static const mojom::blink::HyphenationPtr& getService()
+{
+ DEFINE_STATIC_LOCAL(mojom::blink::HyphenationPtr, service, ());
+ if (service.is_bound())
dcheng 2016/07/13 02:56:29 I have a question about this pattern: https://grou
kojii 2016/07/13 05:02:29 Thanks for asking in the group. I tried a differen
dcheng 2016/07/13 12:08:58 Nod, either way is fine with me.
+ return service;
+
+ Platform::current()->serviceRegistry()->connectToRemoteService(
+ mojo::GetProxy(&service));
+ return service;
+}
+
+base::PlatformFile HyphenationMinikin::openDictionaryFile(const AtomicString& locale)
+{
+ const mojom::blink::HyphenationPtr& service = getService();
+ mojo::ScopedHandle handle;
+ base::ElapsedTimer timer;
+ service->OpenDictionary(locale, &handle);
+ UMA_HISTOGRAM_TIMES("Hyphenation.Open", timer.Elapsed());
+ if (!handle.is_valid())
+ return base::kInvalidPlatformFile;
+
+ base::PlatformFile file;
+ MojoResult result = mojo::UnwrapPlatformFile(std::move(handle), &file);
+ if (result != MOJO_RESULT_OK) {
+ DLOG(ERROR) << "UnwrapPlatformFile failed";
+ return base::kInvalidPlatformFile;
+ }
+ return file;
+}
+
+bool HyphenationMinikin::openDictionary(const AtomicString& locale)
+{
+ base::PlatformFile file = openDictionaryFile(locale);
+ if (file == base::kInvalidPlatformFile)
+ return false;
+ if (!m_file.Initialize(base::File(file))) {
+ DLOG(ERROR) << "mmap failed";
+ return false;
+ }
+
+ // TODO(kojii): Create dictionary from m_file when Minikin is ready.
+
+ return true;
+}
+
+size_t HyphenationMinikin::lastHyphenLocation(const StringView& text, size_t beforeIndex) const
+{
+ // TODO(kojii): Call minikin using the dictionary when Minikin is ready.
+ return 0;
+}
+
+PassRefPtr<Hyphenation> Hyphenation::platformGetHyphenation(const AtomicString& locale)
+{
+ RefPtr<HyphenationMinikin> hyphenation(adoptRef(new HyphenationMinikin));
+ if (!hyphenation->openDictionary(locale))
+ return nullptr;
+ return hyphenation.release();
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698