Chromium Code Reviews| 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. | |
|
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.
| |
| 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 bool is_valid; | |
| 46 }; | |
| 47 | |
| 48 // Clobbers the cache and then fetches the font list. | |
| 49 void GetFontListFromCache(const GetFontListCallback& callback); | |
| 50 | |
| 51 // 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
| |
| 52 // shared buffer on the callback, if it exists. If it does not exist, returns | |
| 53 // an empty shared buffer on the callback. | |
| 54 void GetFontDataInternal(const std::string& family, | |
| 55 const std::string& style, | |
| 56 const GetFontDataCallback& callback); | |
| 57 // 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.
| |
| 58 // Otherwise, returns an empty string. | |
| 59 std::string FindPathInCache(const std::string& family, | |
| 60 const std::string& style); | |
| 61 | |
| 62 void GetFileDataCallback( | |
| 63 const FontAccessService::GetFontDataCallback& callback, | |
| 64 const std::string& path, | |
| 65 const BlobInfo info); | |
| 66 | |
| 67 void ClobberCacheAndReply(const base::Closure closure); | |
| 68 void SwapCacheAndReply(const base::Closure closure, scoped_ptr<FontCacheMap>); | |
| 69 | |
| 70 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.
| |
| 71 | |
| 72 // Returns a shared buffer with the binary data from a file path. | |
| 73 static mojo::ScopedSharedBufferHandle GetSharedBuffer(const std::string path, | |
| 74 uint64_t size); | |
| 75 static void PassBufferAndSize( | |
| 76 const FontAccessService::GetFontDataCallback& callback, | |
| 77 uint64_t size, | |
| 78 mojo::ScopedSharedBufferHandle handle); | |
| 79 | |
| 80 scoped_ptr<FontCacheMap> font_cache_map_; | |
| 81 // The binding between this object and the other end of the pipe. | |
| 82 mojo::StrongBinding<FontAccessService> binding_; | |
| 83 base::Callback<scoped_ptr<FontCacheMap>(void)> cache_map_getter_; | |
| 84 base::WeakPtrFactory<FontAccessServiceImpl> weak_factory_; | |
| 85 | |
| 86 DISALLOW_COPY_AND_ASSIGN(FontAccessServiceImpl); | |
| 87 }; | |
| 88 | |
| 89 } // namespace content | |
| 90 | |
| 91 #endif // CONTENT_BROWSER_FONT_ACCESS_FONT_ACCESS_SERVICE_IMPL_H_ | |
| OLD | NEW |