OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 #include "content/child/npapi/plugin_stream.h" | |
6 | |
7 #include <string.h> | |
8 | |
9 #include "base/files/file_path.h" | |
10 #include "base/files/file_util.h" | |
11 #include "base/logging.h" | |
12 #include "content/child/npapi/plugin_instance.h" | |
13 | |
14 namespace content { | |
15 | |
16 void PluginStream::ResetTempFileHandle() { | |
17 temp_file_ = NULL; | |
18 } | |
19 | |
20 void PluginStream::ResetTempFileName() { | |
21 temp_file_path_ = base::FilePath(); | |
22 } | |
23 | |
24 void PluginStream::WriteAsFile() { | |
25 if (RequestedPluginModeIsAsFile()) | |
26 instance_->NPP_StreamAsFile(&stream_, temp_file_path_.value().c_str()); | |
27 } | |
28 | |
29 size_t PluginStream::WriteBytes(const char* buf, size_t length) { | |
30 return fwrite(buf, sizeof(char), length, temp_file_); | |
31 } | |
32 | |
33 bool PluginStream::OpenTempFile() { | |
34 DCHECK_EQ(static_cast<FILE*>(NULL), temp_file_); | |
35 | |
36 if (base::CreateTemporaryFile(&temp_file_path_)) | |
37 temp_file_ = base::OpenFile(temp_file_path_, "a"); | |
38 | |
39 if (!temp_file_) { | |
40 base::DeleteFile(temp_file_path_, false); | |
41 ResetTempFileName(); | |
42 return false; | |
43 } | |
44 return true; | |
45 } | |
46 | |
47 void PluginStream::CloseTempFile() { | |
48 if (!TempFileIsValid()) | |
49 return; | |
50 | |
51 base::CloseFile(temp_file_); | |
52 ResetTempFileHandle(); | |
53 } | |
54 | |
55 bool PluginStream::TempFileIsValid() const { | |
56 return temp_file_ != NULL; | |
57 } | |
58 | |
59 } // namespace content | |
OLD | NEW |