OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 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 #ifndef MEDIA_CDM_PPAPI_CDM_FILE_IO_IMPL_H_ | |
6 #define MEDIA_CDM_PPAPI_CDM_FILE_IO_IMPL_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "media/cdm/ppapi/api/content_decryption_module.h" | |
13 #include "ppapi/c/ppb_file_io.h" | |
14 #include "ppapi/cpp/file_io.h" | |
15 #include "ppapi/cpp/file_ref.h" | |
16 #include "ppapi/cpp/instance.h" | |
17 #include "ppapi/cpp/module.h" | |
18 #include "ppapi/cpp/private/isolated_file_system_private.h" | |
19 #include "ppapi/utility/completion_callback_factory.h" | |
20 | |
21 namespace media { | |
22 | |
23 // Due to PPAPI limitations, all functions must be called on the main thread. | |
24 class CdmFileIOImpl : public cdm::CdmFileIO { | |
25 public: | |
26 CdmFileIOImpl(cdm::CdmFileIOClient* client, PP_Instance pp_instance); | |
27 virtual ~CdmFileIOImpl(); | |
28 | |
29 // cdm::CdmFileIO implementation. | |
30 virtual void Open(const char* file_name, uint32_t file_name_size) OVERRIDE; | |
31 virtual void Read() OVERRIDE; | |
32 virtual void Write(const uint8_t* data, uint32_t data_size) OVERRIDE; | |
33 virtual void Close() OVERRIDE; | |
34 | |
35 private: | |
36 enum State { | |
37 OPENING_FILE_SYSTEM, | |
38 OPENING_FILE, | |
39 FILE_OPENED, | |
40 READING_FILE, | |
41 WRITING_FILE, | |
42 FILE_CLOSED | |
43 }; | |
44 | |
45 enum ErrorType { | |
46 OPEN_ERROR, | |
47 READ_ERROR, | |
48 WRITE_ERROR | |
49 }; | |
50 | |
51 void OpenFileSystem(); | |
52 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.
| |
53 void OpenFile(); | |
54 void OnFileOpen(int32_t result); | |
55 void ReadFile(); | |
56 void OnFileRead(int32_t bytes_read); | |
57 void WriteFile(); | |
58 void OnFileWritten(int32_t bytes_written); | |
59 | |
60 void CloseFile(); | |
61 | |
62 // Calls client_->OnXxxxComplete with kError asynchronously. In some cases we | |
63 // could actually call them synchronously, but since these errors shouldn't | |
64 // 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.
| |
65 void OnError(ErrorType error_type, const std::string& error_msg); | |
66 // Callback to notify client of error asynchronously. | |
67 void NotifyClientOfError(int32_t result, | |
68 ErrorType error_type, | |
69 const std::string& error_msg); | |
70 | |
71 State state_; | |
72 | |
73 // Non-owning pointer. | |
74 cdm::CdmFileIOClient* const client_; | |
75 | |
76 const pp::InstanceHandle pp_instance_handle_; | |
77 | |
78 std::string file_name_; | |
79 pp::FileRef file_ref_; | |
80 pp::FileIO file_io_; | |
81 pp::FileSystem file_system_; | |
82 | |
83 pp::CompletionCallbackFactory<CdmFileIOImpl> callback_factory_; | |
84 | |
85 // 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
| |
86 // The size of |buffer_| is always "bytes to write" or "bytes to read". | |
87 // Use "char" instead of "unit8_t" because PPB_FileIO uses char* for binary | |
88 // data read and write. | |
89 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.
| |
90 | |
91 // Offset into the file for reading/writing data. | |
92 size_t file_offset_; | |
93 | |
94 // Buffer to hold all read data requested. This buffer is passed to | |
95 // |client_| when read completes. | |
96 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.
| |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(CdmFileIOImpl); | |
99 }; | |
100 | |
101 } // namespace media | |
102 | |
103 #endif // MEDIA_CDM_PPAPI_CDM_FILE_IO_IMPL_H_ | |
OLD | NEW |