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

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

Issue 14784002: Move DirectoryReader::ReadEntries to FileRef::ReadDirectoryEntries (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix naclsdk 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 #include "webkit/plugins/ppapi/file_callbacks.h" 5 #include "webkit/plugins/ppapi/file_callbacks.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/utf_string_conversions.h"
8 #include "ppapi/c/pp_file_info.h" 9 #include "ppapi/c/pp_file_info.h"
9 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/ppb_file_system.h" 11 #include "ppapi/c/ppb_file_system.h"
11 #include "ppapi/shared_impl/file_type_conversion.h" 12 #include "ppapi/shared_impl/file_type_conversion.h"
13 #include "ppapi/shared_impl/ppb_file_ref_shared.h"
12 #include "ppapi/shared_impl/time_conversion.h" 14 #include "ppapi/shared_impl/time_conversion.h"
13 #include "ppapi/shared_impl/tracked_callback.h" 15 #include "ppapi/shared_impl/tracked_callback.h"
14 #include "webkit/fileapi/file_system_types.h" 16 #include "webkit/fileapi/file_system_types.h"
15 #include "webkit/plugins/ppapi/plugin_module.h" 17 #include "webkit/plugins/ppapi/plugin_module.h"
18 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
16 19
17 using ppapi::Resource; 20 using ppapi::Resource;
18 using ppapi::TimeToPPTime; 21 using ppapi::TimeToPPTime;
19 using ppapi::TrackedCallback; 22 using ppapi::TrackedCallback;
20 23
21 namespace webkit { 24 namespace webkit {
22 namespace ppapi { 25 namespace ppapi {
23 26
27 namespace {
28
29 std::string FilePathStringToUTF8String(const base::FilePath::StringType& str) {
teravest 2013/05/02 17:32:10 This is a weird place to have platform-specific tr
hamaji 2013/05/02 18:49:40 Removed, by using fileapi::FilePathToString.
30 #if defined(OS_WIN)
31 return WideToUTF8(str);
32 #elif defined(OS_POSIX)
33 return str;
34 #else
35 #error "Unsupported platform."
36 #endif
37 }
38
39 base::FilePath::StringType UTF8StringToFilePathString(const std::string& str) {
40 #if defined(OS_WIN)
41 return UTF8ToWide(str);
42 #elif defined(OS_POSIX)
43 return str;
44 #else
45 #error "Unsupported platform."
46 #endif
47 }
48
49 } // namespace
50
24 FileCallbacks::FileCallbacks( 51 FileCallbacks::FileCallbacks(
25 Resource* resource, 52 Resource* resource,
26 scoped_refptr<TrackedCallback> callback, 53 scoped_refptr<TrackedCallback> callback,
27 PP_FileInfo* info) 54 PP_FileInfo* info)
28 : callback_(callback), 55 : callback_(callback),
29 info_(info), 56 info_(info),
30 file_system_type_(PP_FILESYSTEMTYPE_INVALID) { 57 file_system_type_(PP_FILESYSTEMTYPE_INVALID),
58 read_entries_params_(NULL) {
31 } 59 }
32 60
33 FileCallbacks::FileCallbacks( 61 FileCallbacks::FileCallbacks(
34 Resource* resource, 62 Resource* resource,
35 scoped_refptr<TrackedCallback> callback, 63 scoped_refptr<TrackedCallback> callback,
36 PP_FileInfo* info, 64 PP_FileInfo* info,
37 PP_FileSystemType file_system_type) 65 PP_FileSystemType file_system_type)
38 : callback_(callback), 66 : callback_(callback),
39 info_(info), 67 info_(info),
40 file_system_type_(file_system_type) { 68 file_system_type_(file_system_type),
69 read_entries_params_(NULL) {
70 }
71
72 FileCallbacks::FileCallbacks(
73 ::ppapi::Resource* resource,
74 scoped_refptr< ::ppapi::TrackedCallback> callback,
75 base::internal::OwnedWrapper<ReadEntriesParams> params)
76 : callback_(callback),
77 info_(NULL),
78 file_system_type_(PP_FILESYSTEMTYPE_INVALID),
79 read_entries_params_(params) {
41 } 80 }
42 81
43 FileCallbacks::~FileCallbacks() {} 82 FileCallbacks::~FileCallbacks() {}
44 83
45 void FileCallbacks::DidSucceed() { 84 void FileCallbacks::DidSucceed() {
46 if (callback_->completed()) 85 if (callback_->completed())
47 return; 86 return;
48 87
49 callback_->Run(PP_OK); 88 callback_->Run(PP_OK);
50 } 89 }
(...skipping 19 matching lines...) Expand all
70 } 109 }
71 110
72 void FileCallbacks::DidCreateSnapshotFile( 111 void FileCallbacks::DidCreateSnapshotFile(
73 const base::PlatformFileInfo& file_info, 112 const base::PlatformFileInfo& file_info,
74 const base::FilePath& path) { 113 const base::FilePath& path) {
75 NOTREACHED(); 114 NOTREACHED();
76 } 115 }
77 116
78 void FileCallbacks::DidReadDirectory( 117 void FileCallbacks::DidReadDirectory(
79 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { 118 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) {
80 NOTREACHED(); 119 if (callback_->completed())
120 return;
121
122 // The current filesystem backend always returns false.
123 DCHECK(!has_more);
124
125 PPB_FileRef_Impl* dir_ref = read_entries_params_.get()->dir_ref;
126 std::vector< ::ppapi::PPB_FileRef_CreateInfo>* files
teravest 2013/05/02 17:32:10 '=' should be on the first line here.
hamaji 2013/05/02 18:49:40 Done.
127 = read_entries_params_.get()->files;
128 std::vector<PP_FileType>* file_types =
129 read_entries_params_.get()->file_types;
130 DCHECK(dir_ref);
131 DCHECK(files);
132 DCHECK(file_types);
133
134 std::string dir_path = dir_ref->GetCreateInfo().path;
135 if (dir_path[dir_path.size() - 1] != '/')
136 dir_path += '/';
137 base::FilePath::StringType dir_file_path =
138 UTF8StringToFilePathString(dir_path);
teravest 2013/05/02 17:32:10 I feel like there has to be a better way to handle
hamaji 2013/05/02 18:49:40 I just moved this code from pepper_directory_reade
139
140 files->resize(entries.size());
141 file_types->resize(entries.size());
142 for (size_t i = 0; i < entries.size(); ++i) {
143 const base::FileUtilProxy::Entry& entry = entries[i];
144 scoped_refptr<PPB_FileRef_Impl> file_ref(PPB_FileRef_Impl::CreateInternal(
145 dir_ref->pp_instance(),
146 dir_ref->file_system_resource(),
147 FilePathStringToUTF8String(dir_file_path + entry.name)));
148 (*files)[i] = file_ref->GetCreateInfo();
149 (*file_types)[i] =
150 entry.is_directory ? PP_FILETYPE_DIRECTORY : PP_FILETYPE_REGULAR;
151 // Add a ref count on behalf of the plugin side.
152 file_ref->GetReference();
153 }
154
155 callback_->Run(PP_OK);
81 } 156 }
82 157
83 void FileCallbacks::DidOpenFileSystem(const std::string&, 158 void FileCallbacks::DidOpenFileSystem(const std::string&,
84 const GURL& root_url) { 159 const GURL& root_url) {
85 NOTREACHED(); 160 NOTREACHED();
86 } 161 }
87 162
88 void FileCallbacks::DidFail(base::PlatformFileError error_code) { 163 void FileCallbacks::DidFail(base::PlatformFileError error_code) {
89 RunCallback(error_code); 164 RunCallback(error_code);
90 } 165 }
91 166
92 void FileCallbacks::DidWrite(int64 bytes, bool complete) { 167 void FileCallbacks::DidWrite(int64 bytes, bool complete) {
93 NOTREACHED(); 168 NOTREACHED();
94 } 169 }
95 170
96 void FileCallbacks::RunCallback(base::PlatformFileError error_code) { 171 void FileCallbacks::RunCallback(base::PlatformFileError error_code) {
97 if (callback_->completed()) 172 if (callback_->completed())
98 return; 173 return;
99 174
100 callback_->Run(::ppapi::PlatformFileErrorToPepperError(error_code)); 175 callback_->Run(::ppapi::PlatformFileErrorToPepperError(error_code));
101 } 176 }
102 177
103 } // namespace ppapi 178 } // namespace ppapi
104 } // namespace webkit 179 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698