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

content / renderer / pepper / pepper_file_system_host.h [blame]

// 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 CONTENT_RENDERER_PEPPER_PEPPER_FILE_SYSTEM_HOST_H_
#define CONTENT_RENDERER_PEPPER_PEPPER_FILE_SYSTEM_HOST_H_

#include <stdint.h>

#include <string>

#include "base/files/file.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "ppapi/c/pp_file_info.h"
#include "ppapi/c/private/ppb_isolated_file_system_private.h"
#include "ppapi/host/host_message_context.h"
#include "ppapi/host/resource_host.h"
#include "third_party/blink/public/mojom/filesystem/file_system.mojom.h"
#include "url/gurl.h"

namespace content {

class RendererPpapiHost;

class PepperFileSystemHost final : public ppapi::host::ResourceHost {
 public:
  // Creates a new PepperFileSystemHost for a file system of a given |type|. The
  // host will not be connected to any specific file system, and will need to
  // subsequently be opened before use.
  PepperFileSystemHost(RendererPpapiHost* host,
                       PP_Instance instance,
                       PP_Resource resource,
                       PP_FileSystemType type);
  // Creates a new PepperFileSystemHost with an existing file system at the
  // given |root_url| and of the given |type|. The file system must already be
  // opened. Once created, the PepperFileSystemHost is already opened for use.
  PepperFileSystemHost(RendererPpapiHost* host,
                       PP_Instance instance,
                       PP_Resource resource,
                       const GURL& root_url,
                       PP_FileSystemType type);

  PepperFileSystemHost(const PepperFileSystemHost&) = delete;
  PepperFileSystemHost& operator=(const PepperFileSystemHost&) = delete;

  ~PepperFileSystemHost() override;

  // ppapi::host::ResourceHost override.
  int32_t OnResourceMessageReceived(
      const IPC::Message& msg,
      ppapi::host::HostMessageContext* context) override;
  bool IsFileSystemHost() override;

  // Supports FileRefs direct access on the host side.
  PP_FileSystemType GetType() const { return type_; }
  bool IsOpened() const { return opened_; }
  GURL GetRootUrl() const { return root_url_; }

  base::WeakPtr<PepperFileSystemHost> AsWeakPtr() {
    return weak_ptr_factory_.GetWeakPtr();
  }

 private:
  // Callback for OpenFileSystem.
  void DidOpenFileSystem(const std::string& name_unused,
                         const GURL& root,
                         base::File::Error error);
  void DidFailOpenFileSystem(base::File::Error error);

  int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context,
                        int64_t expected_size);
  int32_t OnHostMsgInitIsolatedFileSystem(
      ppapi::host::HostMessageContext* context,
      const std::string& fsid,
      PP_IsolatedFileSystemType_Private type);

  blink::mojom::FileSystemManager* GetFileSystemManager();

  raw_ptr<RendererPpapiHost> renderer_ppapi_host_;
  ppapi::host::ReplyMessageContext reply_context_;

  PP_FileSystemType type_;
  bool opened_;  // whether open is successful.
  GURL root_url_;
  bool called_open_;  // whether open has been called.
  mojo::Remote<blink::mojom::FileSystemManager> file_system_manager_remote_;

  base::WeakPtrFactory<PepperFileSystemHost> weak_ptr_factory_{this};
};

}  // namespace content

#endif  // CONTENT_RENDERER_PEPPER_PEPPER_FILE_SYSTEM_HOST_H_