| Index: ppapi/examples/pluginfs/pluginfs.cc
|
| diff --git a/ppapi/examples/crxfs/crxfs.cc b/ppapi/examples/pluginfs/pluginfs.cc
|
| similarity index 71%
|
| copy from ppapi/examples/crxfs/crxfs.cc
|
| copy to ppapi/examples/pluginfs/pluginfs.cc
|
| index 86a212b98238159994ad36d1a59638108bb6f366..af6282a68f6d4814b552238b448327bcd5d89df8 100644
|
| --- a/ppapi/examples/crxfs/crxfs.cc
|
| +++ b/ppapi/examples/pluginfs/pluginfs.cc
|
| @@ -35,12 +35,16 @@ class MyInstance : public pp::Instance {
|
| virtual void HandleMessage(const pp::Var& message_data);
|
|
|
| private:
|
| - void OpenCrxFsAndReadFile(const std::string& filename);
|
| + void OpenPluginFsAndReadFile(const std::string& filename);
|
|
|
| - void CrxFileSystemCallback(int32_t pp_error, pp::FileSystem file_system);
|
| + void PluginFileSystemCallback(int32_t pp_error, pp::FileSystem file_system);
|
| void FileIOOpenCallback(int32_t pp_error);
|
| + void FileIOWriteCallback(int32_t pp_error);
|
| void FileIOReadCallback(int32_t pp_error);
|
|
|
| + void OpenFile(const std::string& filename);
|
| + void OpenFileCallback(int32_t pp_error);
|
| +
|
| // Forwards the given string to the page.
|
| void ReportResponse(const char* name, int32_t pp_error);
|
|
|
| @@ -48,7 +52,6 @@ class MyInstance : public pp::Instance {
|
| pp::CompletionCallbackFactory<MyInstance> factory_;
|
|
|
| pp::InstanceHandle handle_;
|
| - pp::IsolatedFileSystemPrivate crxfs_;
|
| pp::FileRef file_ref_;
|
| pp::FileIO file_io_;
|
| std::string filename_;
|
| @@ -61,33 +64,33 @@ void MyInstance::HandleMessage(const pp::Var& message_data) {
|
| return;
|
| }
|
| std::string filename = message_data.AsString();
|
| - OpenCrxFsAndReadFile(filename);
|
| + OpenPluginFsAndReadFile(filename);
|
| }
|
|
|
| -void MyInstance::OpenCrxFsAndReadFile(const std::string& filename) {
|
| +void MyInstance::OpenPluginFsAndReadFile(const std::string& filename) {
|
| filename_ = filename;
|
|
|
| pp::CompletionCallbackWithOutput<pp::FileSystem> callback =
|
| - factory_.NewCallbackWithOutput(&MyInstance::CrxFileSystemCallback);
|
| + factory_.NewCallbackWithOutput(&MyInstance::PluginFileSystemCallback);
|
|
|
| - crxfs_ = pp::IsolatedFileSystemPrivate(
|
| - this, PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_CRX);
|
| - int32_t rv = crxfs_.Open(callback);
|
| + pp::IsolatedFileSystemPrivate pluginfs =
|
| + pp::IsolatedFileSystemPrivate(this, PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_PLUGINPRIVATE);
|
| + int32_t rv = pluginfs.Open(callback);
|
| if (rv != PP_OK_COMPLETIONPENDING)
|
| - ReportResponse("ExtCrxFileSystemPrivate::Open", rv);
|
| + ReportResponse("IsolatedFileSystemPrivate::Open", rv);
|
| }
|
|
|
| -void MyInstance::CrxFileSystemCallback(int32_t pp_error,
|
| - pp::FileSystem file_system) {
|
| +void MyInstance::PluginFileSystemCallback(int32_t pp_error,
|
| + pp::FileSystem file_system) {
|
| if (pp_error != PP_OK) {
|
| - ReportResponse("CrxFileSystemCallback", pp_error);
|
| + ReportResponse("PluginFileSystemCallback", pp_error);
|
| return;
|
| }
|
|
|
| file_io_ = pp::FileIO(handle_);
|
| file_ref_ = pp::FileRef(file_system, filename_.c_str());
|
| int32_t rv = file_io_.Open(
|
| - file_ref_, PP_FILEOPENFLAG_READ,
|
| + file_ref_, PP_FILEOPENFLAG_READ | PP_FILEOPENFLAG_WRITE | PP_FILEOPENFLAG_CREATE | PP_FILEOPENFLAG_TRUNCATE,
|
| factory_.NewCallback(&MyInstance::FileIOOpenCallback));
|
| if (rv != PP_OK_COMPLETIONPENDING)
|
| ReportResponse("FileIO::Open", rv);
|
| @@ -99,6 +102,20 @@ void MyInstance::FileIOOpenCallback(int32_t pp_error) {
|
| return;
|
| }
|
|
|
| + int32_t rv = file_io_.Write(0, "hogehoge", 8,
|
| + factory_.NewCallback(&MyInstance::FileIOWriteCallback));
|
| + if (rv != PP_OK) {
|
| + ReportResponse("FileIO::Write", rv);
|
| + return;
|
| + }
|
| +}
|
| +
|
| +void MyInstance::FileIOWriteCallback(int32_t written_bytes) {
|
| + if (written_bytes <= 0) {
|
| + ReportResponse("FileIOWriteCallback", written_bytes);
|
| + return;
|
| + }
|
| +
|
| int32_t rv = file_io_.Read(0, read_buf_, sizeof(read_buf_),
|
| factory_.NewCallback(&MyInstance::FileIOReadCallback));
|
| if (rv != PP_OK_COMPLETIONPENDING) {
|
| @@ -145,4 +162,3 @@ Module* CreateModule() {
|
| }
|
|
|
| } // namespace pp
|
| -
|
|
|