Index: content/browser/font_access/font_access_service_impl.h |
diff --git a/content/browser/font_access/font_access_service_impl.h b/content/browser/font_access/font_access_service_impl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e2ee833bfca33d081b1d789c9f2ab3c4f983bac8 |
--- /dev/null |
+++ b/content/browser/font_access/font_access_service_impl.h |
@@ -0,0 +1,91 @@ |
+// 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. |
+ |
+#ifndef CONTENT_BROWSER_FONT_ACCESS_FONT_ACCESS_SERVICE_IMPL_H_ |
+#define CONTENT_BROWSER_FONT_ACCESS_FONT_ACCESS_SERVICE_IMPL_H_ |
+ |
+#include "base/callback.h" |
+#include "base/macros.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
+#include "content/browser/font_access/font_getter.h" |
+#include "content/common/font_access/font_access_service.mojom.h" |
+#include "mojo/public/cpp/bindings/strong_binding.h" |
+ |
+namespace content { |
+ |
+class FontAccessServiceImpl : public FontAccessService { |
+ public: |
+ FontAccessServiceImpl(base::Callback<scoped_ptr<FontCacheMap>(void)> getter, |
+ mojo::InterfaceRequest<FontAccessService> request); |
+ ~FontAccessServiceImpl() override; |
+ |
+ static void Create(mojo::InterfaceRequest<FontAccessService> request); |
+ |
+ // Returns a list of FontAccessDescriptions to the callback. |
+ void GetFontList(const GetFontListCallback& callback) override; |
+ |
+ // Returns a Mojo SharedBuffer of the font's binary on the callback. |
+ void GetFontData(const mojo::String& family, |
+ const mojo::String& style, |
+ const GetFontDataCallback& callback) override; |
+ |
+ private: |
+ // Used to pass around all the information about a blob from disk. |
+ struct BlobInfo { |
+ BlobInfo(); |
+ ~BlobInfo(); |
+ |
+ uint64_t size; |
+ base::Time last_modified; |
+ std::string mime; |
+ bool is_valid; |
+ }; |
+ |
+ static BlobInfo GetFileInfo(const base::FilePath& path); |
+ |
+ // Returns a shared buffer with the binary data from a file path. |
+ static mojo::ScopedSharedBufferHandle GetSharedBuffer( |
+ const base::FilePath& path, |
+ uint64_t size); |
+ static void PassBufferAndSize( |
+ const FontAccessService::GetFontDataCallback& callback, |
+ uint64_t size, |
+ mojo::ScopedSharedBufferHandle handle); |
+ |
+ // Clobbers the cache and then fetches the font list. |
+ void GetFontListFromCache(const GetFontListCallback& callback); |
+ |
+ // Pulls the font binary path from the cache and returns the font binary in a |
+ // shared buffer on the callback, if it exists. If it does not exist, returns |
+ // an empty shared buffer on the callback. |
+ void GetFontDataInternal(const std::string& family, |
+ const std::string& style, |
+ const GetFontDataCallback& callback); |
+ |
+ // Returns the font binary path if it exists in the cache. |
+ // Otherwise, returns an empty string. |
+ base::FilePath FindPathInCache(const std::string& family, |
+ const std::string& style); |
+ |
+ void GetFileDataCallback( |
+ const FontAccessService::GetFontDataCallback& callback, |
+ const base::FilePath& path, |
+ const BlobInfo info); |
+ |
+ void ClobberCacheAndReply(const base::Closure closure); |
+ void SwapCacheAndReply(const base::Closure closure, scoped_ptr<FontCacheMap>); |
+ |
+ scoped_ptr<FontCacheMap> font_cache_map_; |
+ // The binding between this object and the other end of the pipe. |
+ mojo::StrongBinding<FontAccessService> binding_; |
+ base::Callback<scoped_ptr<FontCacheMap>(void)> cache_map_getter_; |
+ base::WeakPtrFactory<FontAccessServiceImpl> weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FontAccessServiceImpl); |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_BROWSER_FONT_ACCESS_FONT_ACCESS_SERVICE_IMPL_H_ |