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

Side by Side Diff: components/font_service/public/cpp/font_service_thread.h

Issue 1274743004: Sandbox html_viewer on Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix android compile. Created 5 years, 4 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 2015 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 COMPONENTS_FONT_SERVICE_PUBLIC_CPP_FONT_SERVICE_THREAD_H_
6 #define COMPONENTS_FONT_SERVICE_PUBLIC_CPP_FONT_SERVICE_THREAD_H_
7
8 #include "base/files/file.h"
9 #include "base/threading/thread.h"
10 #include "components/font_service/public/interfaces/font_service.mojom.h"
11 #include "third_party/skia/include/core/SkStream.h"
12 #include "third_party/skia/include/core/SkTypeface.h"
13 #include "third_party/skia/include/ports/SkFontConfigInterface.h"
14
15 namespace font_service {
16 namespace internal {
17
18 class MappedFontFile;
19
20 // The thread which services font requests.
21 //
22 // The SkFontConfigInterface is a global singleton which can be accessed from
23 // multiple threads. However, mojo pipes are bound to a single thread. Because
24 // of this mismatch, we create a thread which owns the mojo pipe, sends and
25 // receives messages. The multiple threads which call through FontLoader class
26 // do blocking message calls to this thread.
27 class FontServiceThread : public base::Thread,
28 public base::RefCountedThreadSafe<FontServiceThread> {
29 public:
30 explicit FontServiceThread(FontServicePtr font_service);
31
32 // These methods are proxies which run on your thread, post a blocking task
33 // to the FontServiceThread, and
jam 2015/08/06 21:34:38 nit:
34 bool MatchFamilyName(const char family_name[],
35 SkTypeface::Style requestedStyle,
36 SkFontConfigInterface::FontIdentity* outFontIdentity,
37 SkString* outFamilyName,
38 SkTypeface::Style* outStyle);
39 scoped_refptr<MappedFontFile> OpenStream(
40 const SkFontConfigInterface::FontIdentity& identity);
41
42 private:
43 friend class base::RefCountedThreadSafe<FontServiceThread>;
44 ~FontServiceThread() override;
45
46 // Methods which run on the FontServiceThread. The public MatchFamilyName
47 // calls this method, this method calls the mojo interface, and
jam 2015/08/06 21:34:38 nit:
48 void MatchFamilyNameImpl(
49 base::WaitableEvent* done_event,
50 const char family_name[],
51 SkTypeface::Style requestedStyle,
52 bool* out_valid,
53 SkFontConfigInterface::FontIdentity* out_font_identity,
54 SkString* out_family_name,
55 SkTypeface::Style* out_style);
56
57 // Called on the FontServiceThread in response to receiving a message from
58 // our MatchFamily mojo IPC. This writes the data returned by mojo, and then
59 // signals |done_event| to wake up the other thread.
60 void OnMatchFamilyNameComplete(
61 base::WaitableEvent* done_event,
62 bool* out_valid,
63 SkFontConfigInterface::FontIdentity* out_font_identity,
64 SkString* out_family_name,
65 SkTypeface::Style* out_style,
66 FontIdentityPtr font_identity,
67 mojo::String family_name,
68 TypefaceStyle style);
69
70 // Implementation of OpenStream; same threading restrictions as MatchFamily.
71 void OpenStreamImpl(base::WaitableEvent* done_event,
72 base::File* output_file,
73 const uint32_t id_number);
74 void OnOpenStreamComplete(base::WaitableEvent* done_event,
75 base::File* output_file,
76 mojo::ScopedHandle handle);
77
78 // base::Thread
79 void Init() override;
80 void CleanUp() override;
81
82 // This member is used to safely pass data from one thread to another. It is
83 // set in the constructor and is consumed in Init().
84 mojo::InterfacePtrInfo<FontService> font_service_info_;
85
86 // This member is set in Init(). It takes |font_service_info_|, which is
87 // non-thread bound, and binds it to the newly created thread.
88 mojo::InterfacePtr<FontService> font_service_;
89
90 DISALLOW_COPY_AND_ASSIGN(FontServiceThread);
91 };
92
93 } // namespace internal
94 } // namespace font_service
95
96 #endif // COMPONENTS_FONT_SERVICE_PUBLIC_CPP_FONT_SERVICE_THREAD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698