Index: media/cdm/ppapi/cdm_file_io_impl.h |
diff --git a/media/cdm/ppapi/cdm_file_io_impl.h b/media/cdm/ppapi/cdm_file_io_impl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..de8789312ea213e4f59aac2028db4ed1e1efea2e |
--- /dev/null |
+++ b/media/cdm/ppapi/cdm_file_io_impl.h |
@@ -0,0 +1,103 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MEDIA_CDM_PPAPI_CDM_FILE_IO_IMPL_H_ |
+#define MEDIA_CDM_PPAPI_CDM_FILE_IO_IMPL_H_ |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "base/basictypes.h" |
+#include "media/cdm/ppapi/api/content_decryption_module.h" |
+#include "ppapi/c/ppb_file_io.h" |
+#include "ppapi/cpp/file_io.h" |
+#include "ppapi/cpp/file_ref.h" |
+#include "ppapi/cpp/instance.h" |
+#include "ppapi/cpp/module.h" |
+#include "ppapi/cpp/private/isolated_file_system_private.h" |
+#include "ppapi/utility/completion_callback_factory.h" |
+ |
+namespace media { |
+ |
+// Due to PPAPI limitations, all functions must be called on the main thread. |
+class CdmFileIOImpl : public cdm::CdmFileIO { |
+ public: |
+ CdmFileIOImpl(cdm::CdmFileIOClient* client, PP_Instance pp_instance); |
+ virtual ~CdmFileIOImpl(); |
+ |
+ // cdm::CdmFileIO implementation. |
+ virtual void Open(const char* file_name, uint32_t file_name_size) OVERRIDE; |
+ virtual void Read() OVERRIDE; |
+ virtual void Write(const uint8_t* data, uint32_t data_size) OVERRIDE; |
+ virtual void Close() OVERRIDE; |
+ |
+ private: |
+ enum State { |
+ OPENING_FILE_SYSTEM, |
+ OPENING_FILE, |
+ FILE_OPENED, |
+ READING_FILE, |
+ WRITING_FILE, |
+ FILE_CLOSED |
+ }; |
+ |
+ enum ErrorType { |
+ OPEN_ERROR, |
+ READ_ERROR, |
+ WRITE_ERROR |
+ }; |
+ |
+ void OpenFileSystem(); |
+ void OnFileSystemOpen(int32_t result, pp::FileSystem file_system); |
ddorwin
2013/12/04 05:27:08
Open_ed_?
ditto at 54.
xhwang
2013/12/10 01:24:25
Done.
|
+ void OpenFile(); |
+ void OnFileOpen(int32_t result); |
+ void ReadFile(); |
+ void OnFileRead(int32_t bytes_read); |
+ void WriteFile(); |
+ void OnFileWritten(int32_t bytes_written); |
+ |
+ void CloseFile(); |
+ |
+ // Calls client_->OnXxxxComplete with kError asynchronously. In some cases we |
+ // could actually call them synchronously, but since these errors shouldn't |
+ // happen in normal cases, we are not optimizing these cases. |
ddorwin
2013/12/04 05:27:08
nit: s/these/such/ sounds better IMO
xhwang
2013/12/10 01:24:25
Done.
|
+ void OnError(ErrorType error_type, const std::string& error_msg); |
+ // Callback to notify client of error asynchronously. |
+ void NotifyClientOfError(int32_t result, |
+ ErrorType error_type, |
+ const std::string& error_msg); |
+ |
+ State state_; |
+ |
+ // Non-owning pointer. |
+ cdm::CdmFileIOClient* const client_; |
+ |
+ const pp::InstanceHandle pp_instance_handle_; |
+ |
+ std::string file_name_; |
+ pp::FileRef file_ref_; |
+ pp::FileIO file_io_; |
+ pp::FileSystem file_system_; |
+ |
+ pp::CompletionCallbackFactory<CdmFileIOImpl> callback_factory_; |
+ |
+ // A temporary buffer to hold data to write or the data that has been read. |
ddorwin
2013/12/04 05:27:08
If this holds read data, why do we have read_buffe
xhwang
2013/12/10 01:24:25
This holds "partial" read/write data. Renamed to i
|
+ // The size of |buffer_| is always "bytes to write" or "bytes to read". |
+ // Use "char" instead of "unit8_t" because PPB_FileIO uses char* for binary |
+ // data read and write. |
+ std::vector<char> buffer_; |
ddorwin
2013/12/04 05:27:08
It seems we should name this such that it's clear
xhwang
2013/12/10 01:24:25
Done.
|
+ |
+ // Offset into the file for reading/writing data. |
+ size_t file_offset_; |
+ |
+ // Buffer to hold all read data requested. This buffer is passed to |
+ // |client_| when read completes. |
+ std::vector<char> read_buffer_; |
ddorwin
2013/12/04 05:27:08
cumulative_read_buffer_? Or something similar to i
xhwang
2013/12/10 01:24:25
Done.
|
+ |
+ DISALLOW_COPY_AND_ASSIGN(CdmFileIOImpl); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_CDM_PPAPI_CDM_FILE_IO_IMPL_H_ |