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

Side by Side Diff: media/cdm/ppapi/cdm_file_io_impl.h

Issue 93243003: Add CDM FileIO tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments addressed Created 7 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
(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_
ddorwin 2013/12/11 21:16:17 Should we drop "Cdm" from the class names "cdm_" f
xhwang 2013/12/13 02:51:47 Let's talk about naming. For easier review, I'll k
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::FileIO {
25 public:
26 CdmFileIOImpl(cdm::FileIOClient* client, PP_Instance pp_instance);
27 virtual ~CdmFileIOImpl();
28
29 // cdm::FileIO 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 FILE_UNOPENED,
38 OPENING_FILE_SYSTEM,
39 OPENING_FILE,
40 FILE_OPENED,
41 READING_FILE,
42 WRITING_FILE,
43 FILE_CLOSED
44 };
45
46 enum ErrorType {
47 OPEN_ERROR,
48 READ_ERROR,
49 WRITE_ERROR
50 };
51
52 void OpenFileSystem();
53 void OnFileSystemOpened(int32_t result, pp::FileSystem file_system);
54 void OpenFile();
55 void OnFileOpened(int32_t result);
56 void ReadFile();
57 void OnFileRead(int32_t bytes_read);
58 void WriteFile();
59 void OnFileWritten(int32_t bytes_written);
60
61 void CloseFile();
62
63 // Calls client_->OnXxxxComplete with kError asynchronously. In some cases we
64 // could actually call them synchronously, but since these errors shouldn't
65 // happen in normal cases, we are not optimizing such cases.
66 void OnError(ErrorType error_type);
67 // Callback to notify client of error asynchronously.
68 void NotifyClientOfError(int32_t result, ErrorType error_type);
69
70 State state_;
71
72 // Non-owning pointer.
73 cdm::FileIOClient* const client_;
74
75 const pp::InstanceHandle pp_instance_handle_;
76
77 std::string file_name_;
78 pp::IsolatedFileSystemPrivate isolated_file_system_;
79 pp::FileSystem file_system_;
80 pp::FileIO file_io_;
81 pp::FileRef file_ref_;
82
83 pp::CompletionCallbackFactory<CdmFileIOImpl> callback_factory_;
84
85 // A temporary buffer to hold (partial) data to write or the data that has
86 // been read. The size of |buffer_| is always "bytes to write" or "bytes to
ddorwin 2013/12/11 21:16:17 buffer_ is no longer a member
xhwang 2013/12/13 02:51:47 Done.
87 // read". Use "char" instead of "unit8_t" because PPB_FileIO uses char* for
88 // binary data read and write.
89 std::vector<char> io_buffer_;
90
91 // Offset into the file for reading/writing data. When writing data to the
92 // file, this is also the offset to the |io_buffer_|.
93 size_t io_offset_;
94
95 // Buffer to hold all read data requested. This buffer is passed to |client_|
96 // when read completes.
97 std::vector<char> cumulative_read_buffer_;
98
99 DISALLOW_COPY_AND_ASSIGN(CdmFileIOImpl);
100 };
101
102 } // namespace media
103
104 #endif // MEDIA_CDM_PPAPI_CDM_FILE_IO_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698