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

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

Issue 5828003: Move the Pepper implementation from webkit/glue/plugins/pepper_* to... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/glue/plugins/pepper_directory_reader.h" 5 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "ppapi/c/pp_completion_callback.h" 9 #include "ppapi/c/pp_completion_callback.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/c/dev/ppb_directory_reader_dev.h" 11 #include "ppapi/c/dev/ppb_directory_reader_dev.h"
12 #include "webkit/glue/plugins/pepper_file_callbacks.h" 12 #include "webkit/plugins/ppapi/common.h"
13 #include "webkit/glue/plugins/pepper_common.h" 13 #include "webkit/plugins/ppapi/file_callbacks.h"
14 #include "webkit/glue/plugins/pepper_file_ref.h" 14 #include "webkit/plugins/ppapi/plugin_delegate.h"
15 #include "webkit/glue/plugins/pepper_file_system.h" 15 #include "webkit/plugins/ppapi/plugin_instance.h"
16 #include "webkit/glue/plugins/pepper_plugin_delegate.h" 16 #include "webkit/plugins/ppapi/plugin_module.h"
17 #include "webkit/glue/plugins/pepper_plugin_instance.h" 17 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
18 #include "webkit/glue/plugins/pepper_plugin_module.h" 18 #include "webkit/plugins/ppapi/ppb_file_system_impl.h"
19 #include "webkit/glue/plugins/pepper_resource_tracker.h" 19 #include "webkit/plugins/ppapi/resource_tracker.h"
20 20
21 namespace pepper { 21 namespace webkit {
22 namespace plugins {
23 namespace ppapi {
22 24
23 namespace { 25 namespace {
24 26
25 std::string FilePathStringToUTF8String(const FilePath::StringType& str) { 27 std::string FilePathStringToUTF8String(const FilePath::StringType& str) {
26 #if defined(OS_WIN) 28 #if defined(OS_WIN)
27 return WideToUTF8(str); 29 return WideToUTF8(str);
28 #elif defined(OS_POSIX) 30 #elif defined(OS_POSIX)
29 return str; 31 return str;
30 #else 32 #else
31 #error "Unsupported platform." 33 #error "Unsupported platform."
32 #endif 34 #endif
33 } 35 }
34 36
35 FilePath::StringType UTF8StringToFilePathString(const std::string& str) { 37 FilePath::StringType UTF8StringToFilePathString(const std::string& str) {
36 #if defined(OS_WIN) 38 #if defined(OS_WIN)
37 return UTF8ToWide(str); 39 return UTF8ToWide(str);
38 #elif defined(OS_POSIX) 40 #elif defined(OS_POSIX)
39 return str; 41 return str;
40 #else 42 #else
41 #error "Unsupported platform." 43 #error "Unsupported platform."
42 #endif 44 #endif
43 } 45 }
44 46
45 PP_Resource Create(PP_Resource directory_ref_id) { 47 PP_Resource Create(PP_Resource directory_ref_id) {
46 scoped_refptr<FileRef> directory_ref( 48 scoped_refptr<PPB_FileRef_Impl> directory_ref(
47 Resource::GetAs<FileRef>(directory_ref_id)); 49 Resource::GetAs<PPB_FileRef_Impl>(directory_ref_id));
48 if (!directory_ref) 50 if (!directory_ref)
49 return 0; 51 return 0;
50 52
51 DirectoryReader* reader = new DirectoryReader(directory_ref); 53 PPB_DirectoryReader_Impl* reader = new PPB_DirectoryReader_Impl(directory_ref) ;
52 return reader->GetReference(); 54 return reader->GetReference();
53 } 55 }
54 56
55 PP_Bool IsDirectoryReader(PP_Resource resource) { 57 PP_Bool IsDirectoryReader(PP_Resource resource) {
56 return BoolToPPBool(!!Resource::GetAs<DirectoryReader>(resource)); 58 return BoolToPPBool(!!Resource::GetAs<PPB_DirectoryReader_Impl>(resource));
57 } 59 }
58 60
59 int32_t GetNextEntry(PP_Resource reader_id, 61 int32_t GetNextEntry(PP_Resource reader_id,
60 PP_DirectoryEntry_Dev* entry, 62 PP_DirectoryEntry_Dev* entry,
61 PP_CompletionCallback callback) { 63 PP_CompletionCallback callback) {
62 scoped_refptr<DirectoryReader> reader( 64 scoped_refptr<PPB_DirectoryReader_Impl> reader(
63 Resource::GetAs<DirectoryReader>(reader_id)); 65 Resource::GetAs<PPB_DirectoryReader_Impl>(reader_id));
64 if (!reader) 66 if (!reader)
65 return PP_ERROR_BADRESOURCE; 67 return PP_ERROR_BADRESOURCE;
66 68
67 return reader->GetNextEntry(entry, callback); 69 return reader->GetNextEntry(entry, callback);
68 } 70 }
69 71
70 const PPB_DirectoryReader_Dev ppb_directoryreader = { 72 const PPB_DirectoryReader_Dev ppb_directoryreader = {
71 &Create, 73 &Create,
72 &IsDirectoryReader, 74 &IsDirectoryReader,
73 &GetNextEntry 75 &GetNextEntry
74 }; 76 };
75 77
76 } // namespace 78 } // namespace
77 79
78 DirectoryReader::DirectoryReader(FileRef* directory_ref) 80 PPB_DirectoryReader_Impl::PPB_DirectoryReader_Impl(
81 PPB_FileRef_Impl* directory_ref)
79 : Resource(directory_ref->module()), 82 : Resource(directory_ref->module()),
80 directory_ref_(directory_ref), 83 directory_ref_(directory_ref),
81 has_more_(true), 84 has_more_(true),
82 entry_(NULL) { 85 entry_(NULL) {
83 } 86 }
84 87
85 DirectoryReader::~DirectoryReader() { 88 PPB_DirectoryReader_Impl::~PPB_DirectoryReader_Impl() {
86 } 89 }
87 90
88 const PPB_DirectoryReader_Dev* DirectoryReader::GetInterface() { 91 const PPB_DirectoryReader_Dev* PPB_DirectoryReader_Impl::GetInterface() {
89 return &ppb_directoryreader; 92 return &ppb_directoryreader;
90 } 93 }
91 94
92 DirectoryReader* DirectoryReader::AsDirectoryReader() { 95 PPB_DirectoryReader_Impl* PPB_DirectoryReader_Impl::AsDirectoryReader() {
93 return this; 96 return this;
94 } 97 }
95 98
96 int32_t DirectoryReader::GetNextEntry(PP_DirectoryEntry_Dev* entry, 99 int32_t PPB_DirectoryReader_Impl::GetNextEntry(
97 PP_CompletionCallback callback) { 100 PP_DirectoryEntry_Dev* entry,
101 PP_CompletionCallback callback) {
98 if (directory_ref_->GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) 102 if (directory_ref_->GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL)
99 return PP_ERROR_FAILED; 103 return PP_ERROR_FAILED;
100 104
101 entry_ = entry; 105 entry_ = entry;
102 if (FillUpEntry()) { 106 if (FillUpEntry()) {
103 entry_ = NULL; 107 entry_ = NULL;
104 return PP_OK; 108 return PP_OK;
105 } 109 }
106 110
107 PluginInstance* instance = directory_ref_->GetFileSystem()->instance(); 111 PluginInstance* instance = directory_ref_->GetFileSystem()->instance();
108 if (!instance->delegate()->ReadDirectory( 112 if (!instance->delegate()->ReadDirectory(
109 directory_ref_->GetSystemPath(), 113 directory_ref_->GetSystemPath(),
110 new FileCallbacks(instance->module()->AsWeakPtr(), 114 new FileCallbacks(instance->module()->AsWeakPtr(),
111 callback, NULL, NULL, this))) 115 callback, NULL, NULL, this)))
112 return PP_ERROR_FAILED; 116 return PP_ERROR_FAILED;
113 117
114 return PP_ERROR_WOULDBLOCK; 118 return PP_ERROR_WOULDBLOCK;
115 } 119 }
116 120
117 void DirectoryReader::AddNewEntries( 121 void PPB_DirectoryReader_Impl::AddNewEntries(
118 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { 122 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) {
119 DCHECK(!entries.empty()); 123 DCHECK(!entries.empty());
120 has_more_ = has_more; 124 has_more_ = has_more;
121 std::string dir_path = directory_ref_->GetPath(); 125 std::string dir_path = directory_ref_->GetPath();
122 if (dir_path[dir_path.size() - 1] != '/') 126 if (dir_path[dir_path.size() - 1] != '/')
123 dir_path += '/'; 127 dir_path += '/';
124 FilePath::StringType dir_file_path = UTF8StringToFilePathString(dir_path); 128 FilePath::StringType dir_file_path = UTF8StringToFilePathString(dir_path);
125 for (std::vector<base::FileUtilProxy::Entry>::const_iterator it = 129 for (std::vector<base::FileUtilProxy::Entry>::const_iterator it =
126 entries.begin(); it != entries.end(); it++) { 130 entries.begin(); it != entries.end(); it++) {
127 base::FileUtilProxy::Entry entry; 131 base::FileUtilProxy::Entry entry;
128 entry.name = dir_file_path + it->name; 132 entry.name = dir_file_path + it->name;
129 entry.is_directory = it->is_directory; 133 entry.is_directory = it->is_directory;
130 entries_.push(entry); 134 entries_.push(entry);
131 } 135 }
132 136
133 FillUpEntry(); 137 FillUpEntry();
134 entry_ = NULL; 138 entry_ = NULL;
135 } 139 }
136 140
137 bool DirectoryReader::FillUpEntry() { 141 bool PPB_DirectoryReader_Impl::FillUpEntry() {
138 DCHECK(entry_); 142 DCHECK(entry_);
139 if (!entries_.empty()) { 143 if (!entries_.empty()) {
140 base::FileUtilProxy::Entry dir_entry = entries_.front(); 144 base::FileUtilProxy::Entry dir_entry = entries_.front();
141 entries_.pop(); 145 entries_.pop();
142 if (entry_->file_ref) 146 if (entry_->file_ref)
143 ResourceTracker::Get()->UnrefResource(entry_->file_ref); 147 ResourceTracker::Get()->UnrefResource(entry_->file_ref);
144 FileRef* file_ref = new FileRef(module(), directory_ref_->GetFileSystem(), 148 PPB_FileRef_Impl* file_ref =
145 FilePathStringToUTF8String(dir_entry.name)); 149 new PPB_FileRef_Impl(module(), directory_ref_->GetFileSystem(),
150 FilePathStringToUTF8String(dir_entry.name));
146 entry_->file_ref = file_ref->GetReference(); 151 entry_->file_ref = file_ref->GetReference();
147 entry_->file_type = 152 entry_->file_type =
148 (dir_entry.is_directory ? PP_FILETYPE_DIRECTORY : PP_FILETYPE_REGULAR); 153 (dir_entry.is_directory ? PP_FILETYPE_DIRECTORY : PP_FILETYPE_REGULAR);
149 return true; 154 return true;
150 } 155 }
151 156
152 if (!has_more_) { 157 if (!has_more_) {
153 entry_->file_ref = 0; 158 entry_->file_ref = 0;
154 return true; 159 return true;
155 } 160 }
156 161
157 return false; 162 return false;
158 } 163 }
159 164
160 } // namespace pepper 165 } // namespace ppapi
166 } // namespace plugins
167 } // namespace webkit
168
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698