OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_FONT_SERVICE_PUBLIC_CPP_FONT_SERVICE_THREAD_H_ | 5 #ifndef COMPONENTS_FONT_SERVICE_PUBLIC_CPP_FONT_SERVICE_THREAD_H_ |
6 #define COMPONENTS_FONT_SERVICE_PUBLIC_CPP_FONT_SERVICE_THREAD_H_ | 6 #define COMPONENTS_FONT_SERVICE_PUBLIC_CPP_FONT_SERVICE_THREAD_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 // receives messages. The multiple threads which call through FontLoader class | 28 // receives messages. The multiple threads which call through FontLoader class |
29 // do blocking message calls to this thread. | 29 // do blocking message calls to this thread. |
30 class FontServiceThread : public base::Thread, | 30 class FontServiceThread : public base::Thread, |
31 public base::RefCountedThreadSafe<FontServiceThread> { | 31 public base::RefCountedThreadSafe<FontServiceThread> { |
32 public: | 32 public: |
33 explicit FontServiceThread(FontServicePtr font_service); | 33 explicit FontServiceThread(FontServicePtr font_service); |
34 | 34 |
35 // These methods are proxies which run on your thread, post a blocking task | 35 // These methods are proxies which run on your thread, post a blocking task |
36 // to the FontServiceThread, and wait on an event signaled from the callback. | 36 // to the FontServiceThread, and wait on an event signaled from the callback. |
37 bool MatchFamilyName(const char family_name[], | 37 bool MatchFamilyName(const char family_name[], |
38 SkTypeface::Style requested_style, | 38 SkFontStyle requested_style, |
39 SkFontConfigInterface::FontIdentity* out_font_identity, | 39 SkFontConfigInterface::FontIdentity* out_font_identity, |
40 SkString* out_family_name, | 40 SkString* out_family_name, |
41 SkTypeface::Style* out_style); | 41 SkFontStyle* out_style); |
42 scoped_refptr<MappedFontFile> OpenStream( | 42 scoped_refptr<MappedFontFile> OpenStream( |
43 const SkFontConfigInterface::FontIdentity& identity); | 43 const SkFontConfigInterface::FontIdentity& identity); |
44 | 44 |
45 private: | 45 private: |
46 friend class base::RefCountedThreadSafe<FontServiceThread>; | 46 friend class base::RefCountedThreadSafe<FontServiceThread>; |
47 ~FontServiceThread() override; | 47 ~FontServiceThread() override; |
48 | 48 |
49 // Methods which run on the FontServiceThread. The public MatchFamilyName | 49 // Methods which run on the FontServiceThread. The public MatchFamilyName |
50 // calls this method, this method calls the mojo interface, and sets up the | 50 // calls this method, this method calls the mojo interface, and sets up the |
51 // callback to OnMatchFamilyNameComplete. | 51 // callback to OnMatchFamilyNameComplete. |
52 void MatchFamilyNameImpl( | 52 void MatchFamilyNameImpl( |
53 base::WaitableEvent* done_event, | 53 base::WaitableEvent* done_event, |
54 const char family_name[], | 54 const char family_name[], |
55 SkTypeface::Style requested_style, | 55 SkFontStyle requested_style, |
56 bool* out_valid, | 56 bool* out_valid, |
57 SkFontConfigInterface::FontIdentity* out_font_identity, | 57 SkFontConfigInterface::FontIdentity* out_font_identity, |
58 SkString* out_family_name, | 58 SkString* out_family_name, |
59 SkTypeface::Style* out_style); | 59 SkFontStyle* out_style); |
60 | 60 |
61 // Called on the FontServiceThread in response to receiving a message from | 61 // Called on the FontServiceThread in response to receiving a message from |
62 // our MatchFamily mojo IPC. This writes the data returned by mojo, and then | 62 // our MatchFamily mojo IPC. This writes the data returned by mojo, and then |
63 // signals |done_event| to wake up the other thread. | 63 // signals |done_event| to wake up the other thread. |
64 void OnMatchFamilyNameComplete( | 64 void OnMatchFamilyNameComplete( |
65 base::WaitableEvent* done_event, | 65 base::WaitableEvent* done_event, |
66 bool* out_valid, | 66 bool* out_valid, |
67 SkFontConfigInterface::FontIdentity* out_font_identity, | 67 SkFontConfigInterface::FontIdentity* out_font_identity, |
68 SkString* out_family_name, | 68 SkString* out_family_name, |
69 SkTypeface::Style* out_style, | 69 SkFontStyle* out_style, |
70 FontIdentityPtr font_identity, | 70 FontIdentityPtr font_identity, |
71 mojo::String family_name, | 71 mojo::String family_name, |
72 TypefaceStyle style); | 72 TypefaceStylePtr style); |
73 | 73 |
74 // Implementation of OpenStream; same threading restrictions as MatchFamily. | 74 // Implementation of OpenStream; same threading restrictions as MatchFamily. |
75 void OpenStreamImpl(base::WaitableEvent* done_event, | 75 void OpenStreamImpl(base::WaitableEvent* done_event, |
76 base::File* output_file, | 76 base::File* output_file, |
77 const uint32_t id_number); | 77 const uint32_t id_number); |
78 void OnOpenStreamComplete(base::WaitableEvent* done_event, | 78 void OnOpenStreamComplete(base::WaitableEvent* done_event, |
79 base::File* output_file, | 79 base::File* output_file, |
80 mojo::ScopedHandle handle); | 80 mojo::ScopedHandle handle); |
81 | 81 |
82 // base::Thread | 82 // base::Thread |
83 void Init() override; | 83 void Init() override; |
84 void CleanUp() override; | 84 void CleanUp() override; |
85 | 85 |
86 // This member is used to safely pass data from one thread to another. It is | 86 // This member is used to safely pass data from one thread to another. It is |
87 // set in the constructor and is consumed in Init(). | 87 // set in the constructor and is consumed in Init(). |
88 mojo::InterfacePtrInfo<FontService> font_service_info_; | 88 mojo::InterfacePtrInfo<FontService> font_service_info_; |
89 | 89 |
90 // This member is set in Init(). It takes |font_service_info_|, which is | 90 // This member is set in Init(). It takes |font_service_info_|, which is |
91 // non-thread bound, and binds it to the newly created thread. | 91 // non-thread bound, and binds it to the newly created thread. |
92 mojo::InterfacePtr<FontService> font_service_; | 92 mojo::InterfacePtr<FontService> font_service_; |
93 | 93 |
94 DISALLOW_COPY_AND_ASSIGN(FontServiceThread); | 94 DISALLOW_COPY_AND_ASSIGN(FontServiceThread); |
95 }; | 95 }; |
96 | 96 |
97 } // namespace internal | 97 } // namespace internal |
98 } // namespace font_service | 98 } // namespace font_service |
99 | 99 |
100 #endif // COMPONENTS_FONT_SERVICE_PUBLIC_CPP_FONT_SERVICE_THREAD_H_ | 100 #endif // COMPONENTS_FONT_SERVICE_PUBLIC_CPP_FONT_SERVICE_THREAD_H_ |
OLD | NEW |