Roll src/third_party/WebKit 605a979:06cb9e9 (svn 202556:202558)
[chromium-blink-merge.git] / components / font_service / public / cpp / mapped_font_file.h
blobc860fed4c3d501ef39624d87b0f4de028585c60c
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.
5 #ifndef COMPONENTS_FONT_SERVICE_PUBLIC_CPP_MAPPED_FONT_FILE_H_
6 #define COMPONENTS_FONT_SERVICE_PUBLIC_CPP_MAPPED_FONT_FILE_H_
8 #include "base/files/file.h"
9 #include "base/files/memory_mapped_file.h"
10 #include "base/memory/ref_counted.h"
11 #include "third_party/skia/include/core/SkStream.h"
13 namespace font_service {
14 namespace internal {
16 // Owns the memory of the mmaped file that we get back from the font_service.
18 // This class is an implementation detail and shouldn't be used by consumers.
19 class MappedFontFile : public base::RefCountedThreadSafe<MappedFontFile> {
20 public:
21 class Observer {
22 public:
23 ~Observer() {}
25 // Called when a MappedFontFile is destroyed.
26 virtual void OnMappedFontFileDestroyed(MappedFontFile* f) = 0;
29 explicit MappedFontFile(uint32_t font_id);
31 uint32_t font_id() const { return font_id_; }
33 void set_observer(Observer* observer) { observer_ = observer; }
35 bool Initialize(base::File file);
37 SkMemoryStream* CreateMemoryStream();
39 private:
40 friend class base::RefCountedThreadSafe<MappedFontFile>;
42 ~MappedFontFile();
44 static void ReleaseProc(const void* ptr, void* context);
46 uint32_t font_id_;
47 base::MemoryMappedFile mapped_font_file_;
48 Observer* observer_;
51 } // namespace internal
52 } // namespace font_service
54 #endif // COMPONENTS_FONT_SERVICE_PUBLIC_CPP_MAPPED_FONT_FILE_H_