Chromium Code Reviews| 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..8b341e2c52f3daf14f7697e197651518a27ed996 |
| --- /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; |
| + |
| + // Returns a list of FontAccessDescriptions on the callback. |
|
nasko
2016/02/10 23:43:26
nit: Technically, it returns void. It sends that l
Daniel Nishi
2016/02/11 00:23:50
That is correct.
Done.
|
| + 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; |
| + |
| + static void Create( |
| + mojo::InterfaceRequest<FontAccessService> request); |
| + |
| + 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; |
| + }; |
| + |
| + // 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 |
|
nasko
2016/02/10 23:43:26
nit: When talking about paths, one usually thinks
Daniel Nishi
2016/02/11 00:23:50
It is referring to a file system one. We're cachin
|
| + // 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. |
|
nasko
2016/02/10 23:43:26
nit: Empty line before the comment.
Daniel Nishi
2016/02/11 00:23:50
Done.
|
| + // Otherwise, returns an empty string. |
| + std::string FindPathInCache(const std::string& family, |
| + const std::string& style); |
| + |
| + void GetFileDataCallback( |
| + const FontAccessService::GetFontDataCallback& callback, |
| + const std::string& path, |
| + const BlobInfo info); |
| + |
| + void ClobberCacheAndReply(const base::Closure closure); |
| + void SwapCacheAndReply(const base::Closure closure, scoped_ptr<FontCacheMap>); |
| + |
| + static BlobInfo GetFileInfo(const std::string path); |
|
nasko
2016/02/10 23:43:26
sytle: static methods go first in ordering of the
Daniel Nishi
2016/02/11 00:23:50
Done.
|
| + |
| + // Returns a shared buffer with the binary data from a file path. |
| + static mojo::ScopedSharedBufferHandle GetSharedBuffer(const std::string path, |
| + uint64_t size); |
| + static void PassBufferAndSize( |
| + const FontAccessService::GetFontDataCallback& callback, |
| + uint64_t size, |
| + mojo::ScopedSharedBufferHandle handle); |
| + |
| + 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_ |