blob: 933ce511627a54a727611b2be2001edd7f8658fc [file] [log] [blame]
[email protected]c6420f082013-09-18 22:42:411// Copyright 2013 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#include "ppapi/shared_impl/file_ref_create_info.h"
6
avie029c4132015-12-23 06:45:227#include <stddef.h>
8
Hans Wennborg708fa822020-04-27 17:23:159#include "base/check.h"
[email protected]c6420f082013-09-18 22:42:4110#include "base/strings/utf_string_conversions.h"
avie029c4132015-12-23 06:45:2211#include "build/build_config.h"
[email protected]c6420f082013-09-18 22:42:4112#include "ppapi/c/pp_file_info.h"
13
14namespace ppapi {
15
16namespace {
17
18std::string GetNameForExternalFilePath(const base::FilePath& in_path) {
19 const base::FilePath::StringType& path = in_path.value();
20 size_t pos = path.rfind(base::FilePath::kSeparators[0]);
21 CHECK(pos != base::FilePath::StringType::npos);
Xiaohan Wang0fd6e56a2022-01-13 20:26:1122#if BUILDFLAG(IS_WIN)
[email protected]c6420f082013-09-18 22:42:4123 return base::WideToUTF8(path.substr(pos + 1));
Xiaohan Wang0fd6e56a2022-01-13 20:26:1124#elif BUILDFLAG(IS_POSIX)
[email protected]c6420f082013-09-18 22:42:4125 return path.substr(pos + 1);
26#else
27#error "Unsupported platform."
28#endif
29}
30
31} // namespace
32
33bool FileRefCreateInfo::IsValid() const {
34 return file_system_type != PP_FILESYSTEMTYPE_INVALID;
35}
36
[email protected]665b5c542014-02-22 08:06:2637FileRefCreateInfo MakeExternalFileRefCreateInfo(
38 const base::FilePath& external_path,
39 const std::string& display_name,
40 int browser_pending_host_resource_id,
41 int renderer_pending_host_resource_id) {
[email protected]c6420f082013-09-18 22:42:4142 FileRefCreateInfo info;
43 info.file_system_type = PP_FILESYSTEMTYPE_EXTERNAL;
44 if (!display_name.empty())
45 info.display_name = display_name;
46 else
47 info.display_name = GetNameForExternalFilePath(external_path);
48 info.browser_pending_host_resource_id = browser_pending_host_resource_id;
49 info.renderer_pending_host_resource_id = renderer_pending_host_resource_id;
50 return info;
51}
52
53} // namespace ppapi