File: selected_file_info.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (101 lines) | stat: -rw-r--r-- 4,113 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_SHELL_DIALOGS_SELECTED_FILE_INFO_H_
#define UI_SHELL_DIALOGS_SELECTED_FILE_INFO_H_

#include <optional>
#include <vector>

#include "base/files/file_path.h"
#include "build/build_config.h"
#include "ui/shell_dialogs/shell_dialogs_export.h"
#include "url/gurl.h"

namespace ui {

// Struct used for returning selected file info.
struct SHELL_DIALOGS_EXPORT SelectedFileInfo {
  // The selected file's user friendly path as seen in the UI.
  base::FilePath file_path;

  // The actual local path to the selected file. This can be a snapshot file
  // with an unreadable name like "/blah/.d41d8cd98f00b204e9800998ecf8427e".
  // `local_path` can differ from `file_path` for drive files (e.g.
  // "/drive_cache/temporary/d41d8cd98f00b204e9800998ecf8427e" vs.
  // "/special/drive/foo.txt").
  base::FilePath local_path;

  // TODO(crbug.com/41486940): Use a variant for the `local_path`, `url`,
  // and `virtual_path` fields, as those are logically mutually exclusive, and
  // code should be used to indicate which to use rather than relying on
  // comments.

  // This field is optional. The display name contains only the base name
  // portion of a file name (ex. no path separators), and used for displaying
  // selected file names. If this field is empty, the base name portion of
  // `path` is used for displaying.
  base::FilePath::StringType display_name;

  // If set, this URL may be used to access the file. If the user is capable of
  // using a URL to access the file, it should be used in preference to
  // `local_path`. For example, when opening a .gdoc file from Google Drive the
  // file is opened by navigating to a docs.google.com URL.
  std::optional<GURL> url;

  // If set, this virtual path may be used to access the file. If the user is
  // capable of using a virtual path to access the file (using the file system
  // abstraction in //storage/browser/file_system with a
  // storage::kFileSystemTypeExternal FileSystemURL), it should be used in
  // preference over `local_path` and `url`.
  std::optional<base::FilePath> virtual_path;

#if BUILDFLAG(IS_MAC)
  // A list of tags specified by the user to be set on the file upon the
  // completion of it being written to disk.
  std::vector<std::string> file_tags;
#endif

  // Constructs an empty object.
  SelectedFileInfo();

  // Constructs an object with both the `file_path` and `local_path` set to the
  // provided `path` value. This also sets a default `display_name` derived from
  // that value.
  explicit SelectedFileInfo(const base::FilePath& path);

  // Constructs an object with both the `file_path` and `local_path` set to the
  // provided values. This also sets a default `display_name` derived from the
  // `in_file_path` value.
  SelectedFileInfo(const base::FilePath& in_file_path,
                   const base::FilePath& in_local_path);
  SelectedFileInfo(const SelectedFileInfo& other);
  SelectedFileInfo(SelectedFileInfo&& other);
  ~SelectedFileInfo();

  SelectedFileInfo& operator=(const SelectedFileInfo& other);
  SelectedFileInfo& operator=(SelectedFileInfo&& other);

  bool operator==(const SelectedFileInfo& other) const;

  // A utility function to return the path to use in most cases; returns
  // `local_path` if not empty, else `file_path`.
  // TODO(crbug.com/41486940): Clean this up; the different path options
  // should be clearer.
  base::FilePath path() const;
};

// Converts a list of FilePaths to a list of ui::SelectedFileInfo.
SHELL_DIALOGS_EXPORT std::vector<SelectedFileInfo>
FilePathListToSelectedFileInfoList(const std::vector<base::FilePath>& paths);

// Converts a list of ui::SelectedFileInfos to a list of FilePaths. This uses
// the path() accessor to use the `local_path` if not empty, else the
// `file_path`.
SHELL_DIALOGS_EXPORT std::vector<base::FilePath>
SelectedFileInfoListToFilePathList(const std::vector<SelectedFileInfo>& files);

}  // namespace ui

#endif  // UI_SHELL_DIALOGS_SELECTED_FILE_INFO_H_