Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: webkit/plugins/ppapi/file_callbacks.h

Issue 14784002: Move DirectoryReader::ReadEntries to FileRef::ReadDirectoryEntries (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: address comments by dmichael and raymes Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef WEBKIT_PLUGINS_PPAPI_FILE_CALLBACKS_H_ 5 #ifndef WEBKIT_PLUGINS_PPAPI_FILE_CALLBACKS_H_
6 #define WEBKIT_PLUGINS_PPAPI_FILE_CALLBACKS_H_ 6 #define WEBKIT_PLUGINS_PPAPI_FILE_CALLBACKS_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/linked_ptr.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "base/platform_file.h" 14 #include "base/platform_file.h"
14 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 #include "ppapi/c/pp_array_output.h"
15 #include "ppapi/c/pp_completion_callback.h" 17 #include "ppapi/c/pp_completion_callback.h"
16 #include "ppapi/c/pp_file_info.h" 18 #include "ppapi/c/pp_file_info.h"
17 #include "ppapi/c/pp_resource.h" 19 #include "ppapi/c/pp_resource.h"
18 #include "webkit/fileapi/file_system_callback_dispatcher.h" 20 #include "webkit/fileapi/file_system_callback_dispatcher.h"
19 21
20 struct PP_FileInfo; 22 struct PP_FileInfo;
21 23
22 namespace base { 24 namespace base {
23 class FilePath; 25 class FilePath;
24 } 26 }
25 27
26 namespace ppapi { 28 namespace ppapi {
27 class Resource; 29 class Resource;
28 class TrackedCallback; 30 class TrackedCallback;
31 struct PPB_FileRef_CreateInfo;
29 } 32 }
30 33
31 namespace webkit { 34 namespace webkit {
32 namespace ppapi { 35 namespace ppapi {
33 36
37 class PPB_FileRef_Impl;
38
39 // A wrapper class which encapsulates the difference between
40 // linked_ptr and a raw pointer. For in-process mode, the caller must
41 // maintain the lifetime of heap objects so we use a raw pointer.
42 // Renderers in out-of-process mode will use a linked_ptr because
43 // it's renderers' responsibility to manage the lifetime of the heap
44 // objects properly.
45 template <class T> class maybe_linked_ptr {
46 public:
47 maybe_linked_ptr()
48 : raw_(NULL) {
49 }
50 explicit maybe_linked_ptr(T* p)
51 : raw_(p) {
52 }
53 explicit maybe_linked_ptr(linked_ptr<T> p)
54 : raw_(NULL), linked_(p) {
55 }
56
57 T* get() const {
58 return raw_ ? raw_ : linked_.get();
59 }
60 T* operator->() const {
61 return get();
62 }
63
64 private:
65 T* raw_;
66 linked_ptr<T> linked_;
67 };
68
34 // Instances of this class are deleted by FileSystemDispatcher. 69 // Instances of this class are deleted by FileSystemDispatcher.
35 class FileCallbacks : public fileapi::FileSystemCallbackDispatcher { 70 class FileCallbacks : public fileapi::FileSystemCallbackDispatcher {
71 typedef std::vector< ::ppapi::PPB_FileRef_CreateInfo> CreateInfos;
72 typedef std::vector<PP_FileType> FileTypes;
73
36 public: 74 public:
75 // Doesn't take the ownership of members.
76 struct ReadDirectoryEntriesParams {
77 PPB_FileRef_Impl* dir_ref;
78 linked_ptr<CreateInfos> files;
79 linked_ptr<FileTypes> file_types;
80 };
81
82 FileCallbacks(::ppapi::Resource* resource,
83 scoped_refptr< ::ppapi::TrackedCallback> callback);
37 FileCallbacks(::ppapi::Resource* resource, 84 FileCallbacks(::ppapi::Resource* resource,
38 scoped_refptr< ::ppapi::TrackedCallback> callback, 85 scoped_refptr< ::ppapi::TrackedCallback> callback,
39 PP_FileInfo* info); 86 maybe_linked_ptr<PP_FileInfo> info,
87 PP_FileSystemType file_system_type);
40 FileCallbacks(::ppapi::Resource* resource, 88 FileCallbacks(::ppapi::Resource* resource,
41 scoped_refptr< ::ppapi::TrackedCallback> callback, 89 scoped_refptr< ::ppapi::TrackedCallback> callback,
42 PP_FileInfo* info, 90 const ReadDirectoryEntriesParams& params);
43 PP_FileSystemType file_system_type);
44 virtual ~FileCallbacks(); 91 virtual ~FileCallbacks();
45 92
46 // FileSystemCallbackDispatcher implementation. 93 // FileSystemCallbackDispatcher implementation.
47 virtual void DidSucceed(); 94 virtual void DidSucceed();
48 virtual void DidReadMetadata( 95 virtual void DidReadMetadata(
49 const base::PlatformFileInfo& file_info, 96 const base::PlatformFileInfo& file_info,
50 const base::FilePath& unused); 97 const base::FilePath& unused);
51 virtual void DidCreateSnapshotFile( 98 virtual void DidCreateSnapshotFile(
52 const base::PlatformFileInfo& file_info, 99 const base::PlatformFileInfo& file_info,
53 const base::FilePath& path); 100 const base::FilePath& path);
54 virtual void DidReadDirectory( 101 virtual void DidReadDirectory(
55 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more); 102 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more);
56 virtual void DidOpenFileSystem(const std::string&, 103 virtual void DidOpenFileSystem(const std::string&,
57 const GURL& root_url); 104 const GURL& root_url);
58 virtual void DidFail(base::PlatformFileError error_code); 105 virtual void DidFail(base::PlatformFileError error_code);
59 virtual void DidWrite(int64 bytes, bool complete); 106 virtual void DidWrite(int64 bytes, bool complete);
60 107
61 scoped_refptr< ::ppapi::TrackedCallback> GetTrackedCallback() const; 108 scoped_refptr< ::ppapi::TrackedCallback> GetTrackedCallback() const;
62 109
63 private: 110 private:
64 void RunCallback(base::PlatformFileError error_code); 111 void RunCallback(base::PlatformFileError error_code);
65 112
66 scoped_refptr< ::ppapi::TrackedCallback> callback_; 113 scoped_refptr< ::ppapi::TrackedCallback> callback_;
67 PP_FileInfo* info_; 114 maybe_linked_ptr<PP_FileInfo> info_;
68 PP_FileSystemType file_system_type_; 115 PP_FileSystemType file_system_type_;
116 PPB_FileRef_Impl* read_entries_dir_ref_;
117 linked_ptr<CreateInfos> read_entries_files_;
118 linked_ptr<FileTypes> read_entries_file_types_;
69 }; 119 };
70 120
71 } // namespace ppapi 121 } // namespace ppapi
72 } // namespace webkit 122 } // namespace webkit
73 123
74 #endif // WEBKIT_PLUGINS_PPAPI_FILE_CALLBACKS_H_ 124 #endif // WEBKIT_PLUGINS_PPAPI_FILE_CALLBACKS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698