| 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 #include "components/font_service/font_service_app.h" | 5 #include "components/font_service/font_service_app.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "mojo/platform_handle/platform_handle_functions.h" | 11 #include "mojo/public/cpp/system/platform_handle.h" |
| 12 #include "services/shell/public/cpp/connection.h" | 12 #include "services/shell/public/cpp/connection.h" |
| 13 | 13 |
| 14 static_assert( | 14 static_assert( |
| 15 static_cast<uint32_t>(SkFontStyle::kUpright_Slant) == | 15 static_cast<uint32_t>(SkFontStyle::kUpright_Slant) == |
| 16 static_cast<uint32_t>(font_service::mojom::TypefaceSlant::ROMAN), | 16 static_cast<uint32_t>(font_service::mojom::TypefaceSlant::ROMAN), |
| 17 "Skia and font service flags must match"); | 17 "Skia and font service flags must match"); |
| 18 static_assert( | 18 static_assert( |
| 19 static_cast<uint32_t>(SkFontStyle::kItalic_Slant) == | 19 static_cast<uint32_t>(SkFontStyle::kItalic_Slant) == |
| 20 static_cast<uint32_t>(font_service::mojom::TypefaceSlant::ITALIC), | 20 static_cast<uint32_t>(font_service::mojom::TypefaceSlant::ITALIC), |
| 21 "Skia and font service flags must match"); | 21 "Skia and font service flags must match"); |
| 22 static_assert( | 22 static_assert( |
| 23 static_cast<uint32_t>(SkFontStyle::kOblique_Slant) == | 23 static_cast<uint32_t>(SkFontStyle::kOblique_Slant) == |
| 24 static_cast<uint32_t>(font_service::mojom::TypefaceSlant::OBLIQUE), | 24 static_cast<uint32_t>(font_service::mojom::TypefaceSlant::OBLIQUE), |
| 25 "Skia and font service flags must match"); | 25 "Skia and font service flags must match"); |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 mojo::ScopedHandle GetHandleForPath(const base::FilePath& path) { | 29 mojo::ScopedHandle GetHandleForPath(const base::FilePath& path) { |
| 30 if (path.empty()) | 30 if (path.empty()) |
| 31 return mojo::ScopedHandle(); | 31 return mojo::ScopedHandle(); |
| 32 | 32 |
| 33 mojo::ScopedHandle to_pass; | 33 mojo::ScopedHandle to_pass; |
| 34 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ); | 34 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ); |
| 35 if (!file.IsValid()) { | 35 if (!file.IsValid()) { |
| 36 LOG(WARNING) << "file not valid, path=" << path.value(); | 36 LOG(WARNING) << "file not valid, path=" << path.value(); |
| 37 return mojo::ScopedHandle(); | 37 return mojo::ScopedHandle(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 MojoHandle mojo_handle; | 40 return mojo::WrapPlatformFile(file.TakePlatformFile()); |
| 41 MojoResult create_result = | |
| 42 MojoCreatePlatformHandleWrapper(file.TakePlatformFile(), &mojo_handle); | |
| 43 if (create_result != MOJO_RESULT_OK) { | |
| 44 LOG(WARNING) << "unable to create wrapper, path=" << path.value() | |
| 45 << "result=" << create_result; | |
| 46 return mojo::ScopedHandle(); | |
| 47 } | |
| 48 | |
| 49 return mojo::ScopedHandle(mojo::Handle(mojo_handle)); | |
| 50 } | 41 } |
| 51 | 42 |
| 52 } // namespace | 43 } // namespace |
| 53 | 44 |
| 54 namespace font_service { | 45 namespace font_service { |
| 55 | 46 |
| 56 FontServiceApp::FontServiceApp() {} | 47 FontServiceApp::FontServiceApp() {} |
| 57 | 48 |
| 58 FontServiceApp::~FontServiceApp() {} | 49 FontServiceApp::~FontServiceApp() {} |
| 59 | 50 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 int count = paths_.size(); | 120 int count = paths_.size(); |
| 130 for (int i = 0; i < count; ++i) { | 121 for (int i = 0; i < count; ++i) { |
| 131 if (path == paths_[i]) | 122 if (path == paths_[i]) |
| 132 return i; | 123 return i; |
| 133 } | 124 } |
| 134 paths_.emplace_back(path); | 125 paths_.emplace_back(path); |
| 135 return count; | 126 return count; |
| 136 } | 127 } |
| 137 | 128 |
| 138 } // namespace font_service | 129 } // namespace font_service |
| OLD | NEW |