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

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

Issue 14796018: Cleanup: Deprecate FileSystemCallbackDispatcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | Annotate | Revision Log
« no previous file with comments | « webkit/plugins/ppapi/file_callbacks.h ('k') | webkit/plugins/ppapi/mock_plugin_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/plugins/ppapi/file_callbacks.h"
6
7 #include "base/logging.h"
8 #include "base/utf_string_conversions.h"
9 #include "ppapi/c/pp_file_info.h"
10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/c/ppb_file_system.h"
12 #include "ppapi/shared_impl/file_type_conversion.h"
13 #include "ppapi/shared_impl/ppb_file_ref_shared.h"
14 #include "ppapi/shared_impl/time_conversion.h"
15 #include "ppapi/shared_impl/tracked_callback.h"
16 #include "webkit/fileapi/file_system_types.h"
17 #include "webkit/fileapi/file_system_util.h"
18 #include "webkit/plugins/ppapi/plugin_module.h"
19 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
20
21 using ppapi::Resource;
22 using ppapi::TimeToPPTime;
23 using ppapi::TrackedCallback;
24
25 namespace webkit {
26 namespace ppapi {
27
28 FileCallbacks::FileCallbacks(
29 Resource* resource,
30 scoped_refptr<TrackedCallback> callback)
31 : callback_(callback),
32 file_system_type_(PP_FILESYSTEMTYPE_INVALID),
33 read_entries_dir_ref_(NULL) {
34 }
35
36 FileCallbacks::FileCallbacks(
37 Resource* resource,
38 scoped_refptr<TrackedCallback> callback,
39 linked_ptr<PP_FileInfo> info,
40 PP_FileSystemType file_system_type)
41 : callback_(callback),
42 info_(info),
43 file_system_type_(file_system_type),
44 read_entries_dir_ref_(NULL) {
45 }
46
47 FileCallbacks::FileCallbacks(
48 ::ppapi::Resource* resource,
49 scoped_refptr< ::ppapi::TrackedCallback> callback,
50 const ReadDirectoryEntriesParams& params)
51 : callback_(callback),
52 file_system_type_(PP_FILESYSTEMTYPE_INVALID),
53 read_entries_dir_ref_(params.dir_ref),
54 read_entries_files_(params.files),
55 read_entries_file_types_(params.file_types) {
56 }
57
58 FileCallbacks::~FileCallbacks() {}
59
60 void FileCallbacks::DidSucceed() {
61 if (callback_->completed())
62 return;
63
64 callback_->Run(PP_OK);
65 }
66
67 void FileCallbacks::DidReadMetadata(
68 const base::PlatformFileInfo& file_info,
69 const base::FilePath& unused) {
70 if (callback_->completed())
71 return;
72
73 DCHECK(info_.get());
74 info_->size = file_info.size;
75 info_->creation_time = TimeToPPTime(file_info.creation_time);
76 info_->last_access_time = TimeToPPTime(file_info.last_accessed);
77 info_->last_modified_time = TimeToPPTime(file_info.last_modified);
78 info_->system_type = file_system_type_;
79 if (file_info.is_directory)
80 info_->type = PP_FILETYPE_DIRECTORY;
81 else
82 info_->type = PP_FILETYPE_REGULAR;
83
84 callback_->Run(PP_OK);
85 }
86
87 void FileCallbacks::DidCreateSnapshotFile(
88 const base::PlatformFileInfo& file_info,
89 const base::FilePath& path) {
90 NOTREACHED();
91 }
92
93 void FileCallbacks::DidReadDirectory(
94 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) {
95 if (callback_->completed())
96 return;
97
98 // The current filesystem backend always returns false.
99 DCHECK(!has_more);
100
101 DCHECK(read_entries_dir_ref_);
102 DCHECK(read_entries_files_.get());
103 DCHECK(read_entries_file_types_.get());
104
105 std::string dir_path = read_entries_dir_ref_->GetCreateInfo().path;
106 if (dir_path.empty() || dir_path[dir_path.size() - 1] != '/')
107 dir_path += '/';
108
109 for (size_t i = 0; i < entries.size(); ++i) {
110 const base::FileUtilProxy::Entry& entry = entries[i];
111 scoped_refptr<PPB_FileRef_Impl> file_ref(PPB_FileRef_Impl::CreateInternal(
112 read_entries_dir_ref_->pp_instance(),
113 read_entries_dir_ref_->file_system_resource(),
114 dir_path + fileapi::FilePathToString(base::FilePath(entry.name))));
115 read_entries_files_->push_back(file_ref->GetCreateInfo());
116 read_entries_file_types_->push_back(
117 entry.is_directory ? PP_FILETYPE_DIRECTORY : PP_FILETYPE_REGULAR);
118 // Add a ref count on behalf of the plugin side.
119 file_ref->GetReference();
120 }
121 CHECK_EQ(read_entries_files_->size(), read_entries_file_types_->size());
122
123 callback_->Run(PP_OK);
124 }
125
126 void FileCallbacks::DidOpenFileSystem(const std::string&,
127 const GURL& root_url) {
128 NOTREACHED();
129 }
130
131 void FileCallbacks::DidFail(base::PlatformFileError error_code) {
132 RunCallback(error_code);
133 }
134
135 void FileCallbacks::DidWrite(int64 bytes, bool complete) {
136 NOTREACHED();
137 }
138
139 void FileCallbacks::RunCallback(base::PlatformFileError error_code) {
140 if (callback_->completed())
141 return;
142
143 callback_->Run(::ppapi::PlatformFileErrorToPepperError(error_code));
144 }
145
146 } // namespace ppapi
147 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/file_callbacks.h ('k') | webkit/plugins/ppapi/mock_plugin_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698