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

Side by Side Diff: content/browser/font_access/font_access_service_impl.h

Issue 1615133002: Implement API for accessing fonts installed locally on the system. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 unified diff | Download patch
OLDNEW
(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 static void Create(
26 mojo::InterfaceRequest<FontAccessService> request);
27
28 // Returns a list of FontAccessDescriptions to the callback.
29 void GetFontList(const GetFontListCallback& callback) override;
30
31 // Returns a Mojo SharedBuffer of the font's binary on the callback.
32 void GetFontData(const mojo::String& family,
33 const mojo::String& style,
34 const GetFontDataCallback& callback) override;
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 static BlobInfo GetFileInfo(const std::string& path);
49
50 // Returns a shared buffer with the binary data from a file path.
51 static mojo::ScopedSharedBufferHandle GetSharedBuffer(const std::string& path,
52 uint64_t size);
53 static void PassBufferAndSize(
54 const FontAccessService::GetFontDataCallback& callback,
55 uint64_t size,
56 mojo::ScopedSharedBufferHandle handle);
57
58 // Clobbers the cache and then fetches the font list.
59 void GetFontListFromCache(const GetFontListCallback& callback);
60
61 // Pulls the font binary path from the cache and returns the font binary in a
62 // shared buffer on the callback, if it exists. If it does not exist, returns
63 // an empty shared buffer on the callback.
64 void GetFontDataInternal(const std::string& family,
65 const std::string& style,
66 const GetFontDataCallback& callback);
67
68 // Returns the font binary path if it exists in the cache.
69 // Otherwise, returns an empty string.
70 std::string FindPathInCache(const std::string& family,
71 const std::string& style);
72
73 void GetFileDataCallback(
74 const FontAccessService::GetFontDataCallback& callback,
75 const std::string& path,
76 const BlobInfo info);
77
78 void ClobberCacheAndReply(const base::Closure closure);
79 void SwapCacheAndReply(const base::Closure closure, scoped_ptr<FontCacheMap>);
80
81 scoped_ptr<FontCacheMap> font_cache_map_;
82 // The binding between this object and the other end of the pipe.
83 mojo::StrongBinding<FontAccessService> binding_;
84 base::Callback<scoped_ptr<FontCacheMap>(void)> cache_map_getter_;
85 base::WeakPtrFactory<FontAccessServiceImpl> weak_factory_;
86
87 DISALLOW_COPY_AND_ASSIGN(FontAccessServiceImpl);
88 };
89
90 } // namespace content
91
92 #endif // CONTENT_BROWSER_FONT_ACCESS_FONT_ACCESS_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698