OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_FONT_ACCESS_FONT_ACCESS_SERVICE_IMPL_H_ |
| 6 #define CONTENT_BROWSER_FONT_ACCESS_FONT_ACCESS_SERVICE_IMPL_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "content/browser/font_access/font_getter.h" |
| 13 #include "content/common/font_access/font_access_service.mojom.h" |
| 14 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 15 |
| 16 namespace content { |
| 17 |
| 18 class FontAccessServiceImpl : public FontAccessService { |
| 19 public: |
| 20 FontAccessServiceImpl( |
| 21 base::Callback<scoped_ptr<FontCacheMap>(void)> getter, |
| 22 mojo::InterfaceRequest<FontAccessService> request); |
| 23 ~FontAccessServiceImpl() override; |
| 24 |
| 25 // Returns a list of FontAccessDescriptions on the callback. |
| 26 void GetFontList(const GetFontListCallback& callback) override; |
| 27 |
| 28 // Returns a Mojo SharedBuffer of the font's binary on the callback. |
| 29 void GetFontData(const mojo::String& family, |
| 30 const mojo::String& style, |
| 31 const GetFontDataCallback& callback) override; |
| 32 |
| 33 static void Create( |
| 34 mojo::InterfaceRequest<FontAccessService> request); |
| 35 |
| 36 private: |
| 37 // Used to pass around all the information about a blob from disk. |
| 38 struct BlobInfo { |
| 39 BlobInfo(); |
| 40 ~BlobInfo(); |
| 41 |
| 42 uint64_t size; |
| 43 base::Time last_modified; |
| 44 std::string mime; |
| 45 }; |
| 46 |
| 47 // Clobbers the cache and then fetches the font list. |
| 48 void GetFontListFromCache(const GetFontListCallback& callback); |
| 49 |
| 50 // Pulls the font binary path from the cache and returns the font binary in a |
| 51 // shared buffer on the callback, if it exists. If it does not exist, returns |
| 52 // an empty shared buffer on the callback. |
| 53 void GetFontDataInternal(const std::string& family, |
| 54 const std::string& style, |
| 55 const GetFontDataCallback& callback); |
| 56 // Returns the font binary path if it exists in the cache. |
| 57 // Otherwise, returns an empty string. |
| 58 std::string FindPathInCache(const std::string& family, |
| 59 const std::string& style); |
| 60 |
| 61 void GetFileDataCallback( |
| 62 const FontAccessService::GetFontDataCallback& callback, |
| 63 const std::string& path, |
| 64 const BlobInfo info); |
| 65 |
| 66 void ClobberCacheAndReply(const base::Closure closure); |
| 67 void SwapCacheAndReply(const base::Closure closure, scoped_ptr<FontCacheMap>); |
| 68 |
| 69 static BlobInfo GetFileInfo(const std::string path); |
| 70 |
| 71 // Returns a shared buffer with the binary data from a file path. |
| 72 static mojo::ScopedSharedBufferHandle GetSharedBuffer(const std::string path, |
| 73 uint64_t size); |
| 74 static void PassBufferAndSize( |
| 75 const FontAccessService::GetFontDataCallback& callback, |
| 76 uint64_t size, |
| 77 mojo::ScopedSharedBufferHandle handle); |
| 78 |
| 79 scoped_ptr<FontCacheMap> font_cache_map_; |
| 80 // The binding between this object and the other end of the pipe. |
| 81 mojo::StrongBinding<FontAccessService> binding_; |
| 82 base::Callback<scoped_ptr<FontCacheMap>(void)> cache_map_getter_; |
| 83 base::WeakPtrFactory<FontAccessServiceImpl> weak_factory_; |
| 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(FontAccessServiceImpl); |
| 86 }; |
| 87 |
| 88 } // namespace content |
| 89 |
| 90 #endif // CONTENT_BROWSER_FONT_ACCESS_FONT_ACCESS_SERVICE_IMPL_H_ |
OLD | NEW |