[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 1 | // 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 | |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
Hans Wennborg | 708fa82 | 2020-04-27 17:23:15 | [diff] [blame] | 9 | #include "base/check.h" |
[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 10 | #include "base/strings/utf_string_conversions.h" |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 11 | #include "build/build_config.h" |
[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 12 | #include "ppapi/c/pp_file_info.h" |
| 13 | |
| 14 | namespace ppapi { |
| 15 | |
| 16 | namespace { |
| 17 | |
| 18 | std::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 Wang | 0fd6e56a | 2022-01-13 20:26:11 | [diff] [blame] | 22 | #if BUILDFLAG(IS_WIN) |
[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 23 | return base::WideToUTF8(path.substr(pos + 1)); |
Xiaohan Wang | 0fd6e56a | 2022-01-13 20:26:11 | [diff] [blame] | 24 | #elif BUILDFLAG(IS_POSIX) |
[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 25 | return path.substr(pos + 1); |
| 26 | #else |
| 27 | #error "Unsupported platform." |
| 28 | #endif |
| 29 | } |
| 30 | |
| 31 | } // namespace |
| 32 | |
| 33 | bool FileRefCreateInfo::IsValid() const { |
| 34 | return file_system_type != PP_FILESYSTEMTYPE_INVALID; |
| 35 | } |
| 36 | |
[email protected] | 665b5c54 | 2014-02-22 08:06:26 | [diff] [blame] | 37 | FileRefCreateInfo 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] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 42 | 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 |