summaryrefslogtreecommitdiffstats
path: root/webkit/plugins/ppapi/file_callbacks.h
blob: 4bdaa1dca2201c95d53535576b3a5d127b882cf4 (plain)
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
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef WEBKIT_PLUGINS_PPAPI_FILE_CALLBACKS_H_
#define WEBKIT_PLUGINS_PPAPI_FILE_CALLBACKS_H_

#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/platform_file.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_resource.h"
#include "webkit/fileapi/file_system_callback_dispatcher.h"

struct PP_FileInfo_Dev;

namespace base {
class FilePath;
}

namespace webkit {
namespace ppapi {

class PPB_DirectoryReader_Impl;
class PPB_FileSystem_Impl;
class PluginModule;
class TrackedCompletionCallback;

// Instances of this class are deleted by FileSystemDispatcher.
class FileCallbacks : public fileapi::FileSystemCallbackDispatcher {
 public:
  FileCallbacks(const base::WeakPtr<PluginModule>& module,
                PP_Resource resource_id,
                PP_CompletionCallback callback,
                PP_FileInfo_Dev* info,
                scoped_refptr<PPB_FileSystem_Impl> file_system,
                scoped_refptr<PPB_DirectoryReader_Impl> directory_reader);
  virtual ~FileCallbacks();

  // FileSystemCallbackDispatcher implementation.
  virtual void DidSucceed();
  virtual void DidReadMetadata(
      const base::PlatformFileInfo& file_info,
      const FilePath& unused);
  virtual void DidReadDirectory(
      const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more);
  virtual void DidOpenFileSystem(const std::string&,
                                 const GURL& root_url);
  virtual void DidFail(base::PlatformFileError error_code);
  virtual void DidWrite(int64 bytes, bool complete);

  scoped_refptr<TrackedCompletionCallback> GetTrackedCompletionCallback() const;

 private:
  void RunCallback(base::PlatformFileError error_code);

  scoped_refptr<TrackedCompletionCallback> callback_;
  PP_FileInfo_Dev* info_;
  scoped_refptr<PPB_FileSystem_Impl> file_system_;
  scoped_refptr<PPB_DirectoryReader_Impl> directory_reader_;
};

}  // namespace ppapi
}  // namespace webkit

#endif  // WEBKIT_PLUGINS_PPAPI_FILE_CALLBACKS_H_