chromium/extensions/browser/api/file_system/file_system_api.h

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef EXTENSIONS_BROWSER_API_FILE_SYSTEM_FILE_SYSTEM_API_H_
#define EXTENSIONS_BROWSER_API_FILE_SYSTEM_FILE_SYSTEM_API_H_

#include <memory>
#include <string>
#include <vector>

#include "base/auto_reset.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/memory/raw_ptr.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "extensions/browser/extension_function.h"
#include "extensions/common/api/file_system.h"
#include "extensions/common/extension_id.h"
#include "ui/shell_dialogs/select_file_dialog.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "extensions/browser/api/file_system/consent_provider.h"
#endif  // BUILDFLAG(IS_CHROMEOS)

namespace extensions {
class ExtensionPrefs;

namespace file_system_api {

// Methods to get and set the path of the directory containing the last file
// chosen by the user in response to a chrome.fileSystem.chooseEntry() call for
// the given extension.

// Returns an empty path on failure.
base::FilePath GetLastChooseEntryDirectory(const ExtensionPrefs* prefs,
                                           const ExtensionId& extension_id);

void SetLastChooseEntryDirectory(ExtensionPrefs* prefs,
                                 const ExtensionId& extension_id,
                                 const base::FilePath& path);

}  // namespace file_system_api

class FileSystemGetDisplayPathFunction : public ExtensionFunction {};

class FileSystemEntryFunction : public ExtensionFunction {};

class FileSystemGetWritableEntryFunction : public FileSystemEntryFunction {};

class FileSystemIsWritableEntryFunction : public ExtensionFunction {};

class FileSystemChooseEntryFunction : public FileSystemEntryFunction {};

class FileSystemRetainEntryFunction : public ExtensionFunction {};

class FileSystemIsRestorableFunction : public ExtensionFunction {};

class FileSystemRestoreEntryFunction : public FileSystemEntryFunction {};

#if BUILDFLAG(IS_CHROMEOS)
// Requests a file system for the specified volume id.
class FileSystemRequestFileSystemFunction : public ExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("fileSystem.requestFileSystem",
                             FILESYSTEM_REQUESTFILESYSTEM)
  FileSystemRequestFileSystemFunction();

 protected:
  ~FileSystemRequestFileSystemFunction() override;

  // ExtensionFunction overrides.
  ExtensionFunction::ResponseAction Run() override;

 private:
  // Called when a user grants or rejects permissions for the file system
  // access.
  void OnGotFileSystem(const std::string& id, const std::string& path);
  void OnError(const std::string& error);

  std::unique_ptr<ConsentProvider> consent_provider_;
};

// Requests a list of available volumes.
class FileSystemGetVolumeListFunction : public ExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("fileSystem.getVolumeList",
                             FILESYSTEM_GETVOLUMELIST)
  FileSystemGetVolumeListFunction();

 protected:
  ~FileSystemGetVolumeListFunction() override;

  // ExtensionFunction overrides.
  ExtensionFunction::ResponseAction Run() override;

 private:
  void OnGotVolumeList(const std::vector<api::file_system::Volume>& volumes);
  void OnError(const std::string& error);

  std::unique_ptr<ConsentProvider> consent_provider_;
};
#else   // BUILDFLAG(IS_CHROMEOS)
// Stub for non Chrome OS operating systems.
class FileSystemRequestFileSystemFunction : public ExtensionFunction {};

// Stub for non Chrome OS operating systems.
class FileSystemGetVolumeListFunction : public ExtensionFunction {};
#endif  // BUILDFLAG(IS_CHROMEOS)

}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_API_FILE_SYSTEM_FILE_SYSTEM_API_H_