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

Side by Side Diff: components/font_service/font_service_app.cc

Issue 2539383002: Replace base::File wrapping with typemapping. (Closed)
Patch Set: Created 4 years 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
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"
(...skipping 10 matching lines...) Expand all
21 static_cast<uint32_t>(SkFontStyle::kItalic_Slant) == 21 static_cast<uint32_t>(SkFontStyle::kItalic_Slant) ==
22 static_cast<uint32_t>(font_service::mojom::TypefaceSlant::ITALIC), 22 static_cast<uint32_t>(font_service::mojom::TypefaceSlant::ITALIC),
23 "Skia and font service flags must match"); 23 "Skia and font service flags must match");
24 static_assert( 24 static_assert(
25 static_cast<uint32_t>(SkFontStyle::kOblique_Slant) == 25 static_cast<uint32_t>(SkFontStyle::kOblique_Slant) ==
26 static_cast<uint32_t>(font_service::mojom::TypefaceSlant::OBLIQUE), 26 static_cast<uint32_t>(font_service::mojom::TypefaceSlant::OBLIQUE),
27 "Skia and font service flags must match"); 27 "Skia and font service flags must match");
28 28
29 namespace { 29 namespace {
30 30
31 mojo::ScopedHandle GetHandleForPath(const base::FilePath& path) { 31 base::File GetFileForPath(const base::FilePath& path) {
32 if (path.empty()) 32 if (path.empty())
33 return mojo::ScopedHandle(); 33 return base::File();
34 34
35 mojo::ScopedHandle to_pass;
36 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ); 35 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ);
37 if (!file.IsValid()) { 36 LOG_IF(WARNING, !file.IsValid()) << "file not valid, path=" << path.value();
38 LOG(WARNING) << "file not valid, path=" << path.value(); 37 return file;
39 return mojo::ScopedHandle();
40 }
41
42 return mojo::WrapPlatformFile(file.TakePlatformFile());
43 } 38 }
44 39
45 } // namespace 40 } // namespace
46 41
47 namespace font_service { 42 namespace font_service {
48 43
49 FontServiceApp::FontServiceApp() {} 44 FontServiceApp::FontServiceApp() {}
50 45
51 FontServiceApp::~FontServiceApp() {} 46 FontServiceApp::~FontServiceApp() {}
52 47
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 mojom::TypefaceStylePtr style(mojom::TypefaceStyle::New()); 97 mojom::TypefaceStylePtr style(mojom::TypefaceStyle::New());
103 style->weight = result_style.weight(); 98 style->weight = result_style.weight();
104 style->width = result_style.width(); 99 style->width = result_style.width();
105 style->slant = static_cast<mojom::TypefaceSlant>(result_style.slant()); 100 style->slant = static_cast<mojom::TypefaceSlant>(result_style.slant());
106 101
107 callback.Run(std::move(identity), result_family.c_str(), std::move(style)); 102 callback.Run(std::move(identity), result_family.c_str(), std::move(style));
108 } 103 }
109 104
110 void FontServiceApp::OpenStream(uint32_t id_number, 105 void FontServiceApp::OpenStream(uint32_t id_number,
111 const OpenStreamCallback& callback) { 106 const OpenStreamCallback& callback) {
112 mojo::ScopedHandle handle; 107 base::File file;
113 if (id_number < static_cast<uint32_t>(paths_.size())) { 108 if (id_number < static_cast<uint32_t>(paths_.size())) {
114 handle = GetHandleForPath(base::FilePath(paths_[id_number].c_str())); 109 file = GetFileForPath(base::FilePath(paths_[id_number].c_str()));
115 } 110 }
116 111
117 callback.Run(std::move(handle)); 112 callback.Run(std::move(file));
118 } 113 }
119 114
120 int FontServiceApp::FindOrAddPath(const SkString& path) { 115 int FontServiceApp::FindOrAddPath(const SkString& path) {
121 int count = paths_.size(); 116 int count = paths_.size();
122 for (int i = 0; i < count; ++i) { 117 for (int i = 0; i < count; ++i) {
123 if (path == paths_[i]) 118 if (path == paths_[i])
124 return i; 119 return i;
125 } 120 }
126 paths_.emplace_back(path); 121 paths_.emplace_back(path);
127 return count; 122 return count;
128 } 123 }
129 124
130 } // namespace font_service 125 } // namespace font_service
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698