1// Copyright (c) 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#ifndef CONTENT_RENDERER_PEPPER_PEPPER_FILE_SYSTEM_HOST_H_
6#define CONTENT_RENDERER_PEPPER_PEPPER_FILE_SYSTEM_HOST_H_
7
8#include "base/basictypes.h"
9#include "base/memory/weak_ptr.h"
10#include "ppapi/c/pp_file_info.h"
11#include "ppapi/host/host_message_context.h"
12#include "ppapi/host/resource_host.h"
13#include "url/gurl.h"
14
15namespace content {
16
17class RendererPpapiHost;
18
19class PepperFileSystemHost :
20    public ppapi::host::ResourceHost,
21    public base::SupportsWeakPtr<PepperFileSystemHost> {
22 public:
23  PepperFileSystemHost(RendererPpapiHost* host,
24                       PP_Instance instance,
25                       PP_Resource resource,
26                       PP_FileSystemType type);
27  virtual ~PepperFileSystemHost();
28
29  // ppapi::host::ResourceHost override.
30  virtual int32_t OnResourceMessageReceived(
31      const IPC::Message& msg,
32      ppapi::host::HostMessageContext* context) OVERRIDE;
33  virtual bool IsFileSystemHost() OVERRIDE;
34
35  // Supports FileRefs direct access on the host side.
36  PP_FileSystemType GetType() const { return type_; }
37  bool IsOpened() const { return opened_; }
38  GURL GetRootUrl() const { return root_url_; }
39
40 private:
41  // Callback for OpenFileSystem.
42  void DidOpenFileSystem(const std::string& name_unused, const GURL& root);
43  void DidFailOpenFileSystem(base::PlatformFileError error);
44
45  int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context,
46                        int64_t expected_size);
47  int32_t OnHostMsgInitIsolatedFileSystem(
48      ppapi::host::HostMessageContext* context,
49      const std::string& fsid);
50
51  RendererPpapiHost* renderer_ppapi_host_;
52  ppapi::host::ReplyMessageContext reply_context_;
53  base::WeakPtrFactory<PepperFileSystemHost> weak_factory_;
54
55  PP_FileSystemType type_;
56  bool opened_;  // whether open is successful.
57  GURL root_url_;
58  bool called_open_;  // whether open has been called.
59
60  DISALLOW_COPY_AND_ASSIGN(PepperFileSystemHost);
61};
62
63}  // namespace content
64
65#endif  // CONTENT_RENDERER_PEPPER_PEPPER_FILE_SYSTEM_HOST_H_
66