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

Side by Side Diff: content/renderer/pepper/pepper_file_io_host.cc

Issue 13726024: Refactor FileSystem (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 8 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/pepper/pepper_file_io_host.h" 5 #include "content/renderer/pepper/pepper_file_io_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h"
8 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/files/file_util_proxy.h" 11 #include "base/files/file_util_proxy.h"
11 #include "content/public/common/content_client.h" 12 #include "content/public/common/content_client.h"
12 #include "content/public/renderer/content_renderer_client.h" 13 #include "content/public/renderer/content_renderer_client.h"
14 #include "content/renderer/pepper/null_file_system_callback_dispatcher.h"
13 #include "ppapi/c/pp_errors.h" 15 #include "ppapi/c/pp_errors.h"
14 #include "ppapi/host/dispatch_host_message.h" 16 #include "ppapi/host/dispatch_host_message.h"
15 #include "ppapi/host/ppapi_host.h" 17 #include "ppapi/host/ppapi_host.h"
16 #include "ppapi/proxy/ppapi_messages.h" 18 #include "ppapi/proxy/ppapi_messages.h"
17 #include "ppapi/shared_impl/file_type_conversion.h" 19 #include "ppapi/shared_impl/file_type_conversion.h"
18 #include "ppapi/shared_impl/time_conversion.h" 20 #include "ppapi/shared_impl/time_conversion.h"
19 #include "ppapi/thunk/enter.h" 21 #include "ppapi/thunk/enter.h"
20 #include "webkit/fileapi/file_system_callback_dispatcher.h"
21 #include "webkit/plugins/ppapi/file_callbacks.h" 22 #include "webkit/plugins/ppapi/file_callbacks.h"
22 #include "webkit/plugins/ppapi/host_globals.h" 23 #include "webkit/plugins/ppapi/host_globals.h"
23 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 24 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
24 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" 25 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
25 #include "webkit/plugins/ppapi/quota_file_io.h" 26 #include "webkit/plugins/ppapi/quota_file_io.h"
26 27
27 namespace content { 28 namespace content {
28 29
29 using ppapi::FileIOStateManager; 30 using ppapi::FileIOStateManager;
30 using ppapi::PPTimeToTime; 31 using ppapi::PPTimeToTime;
31 using ppapi::TimeToPPTime; 32 using ppapi::TimeToPPTime;
32 using ppapi::host::ReplyMessageContext; 33 using ppapi::host::ReplyMessageContext;
33 using ppapi::thunk::EnterResourceNoLock; 34 using ppapi::thunk::EnterResourceNoLock;
34 using ppapi::thunk::PPB_FileRef_API; 35 using ppapi::thunk::PPB_FileRef_API;
35 using webkit::ppapi::PPB_FileRef_Impl; 36 using webkit::ppapi::PPB_FileRef_Impl;
36 using webkit::ppapi::PluginDelegate; 37 using webkit::ppapi::PluginDelegate;
37 38
38 namespace { 39 namespace {
39 40
40 // The maximum size we'll support reading in one chunk. The renderer process 41 // The maximum size we'll support reading in one chunk. The renderer process
41 // must allocate a buffer sized according to the request of the plugin. To 42 // must allocate a buffer sized according to the request of the plugin. To
42 // keep things from getting out of control, we cap the read size to this value. 43 // keep things from getting out of control, we cap the read size to this value.
43 // This should generally be OK since the API specifies that it may perform a 44 // This should generally be OK since the API specifies that it may perform a
44 // partial read. 45 // partial read.
45 static const int32_t kMaxReadSize = 32 * 1024 * 1024; // 32MB 46 static const int32_t kMaxReadSize = 32 * 1024 * 1024; // 32MB
46 47
47 typedef base::Callback<void (base::PlatformFileError)> PlatformGeneralCallback; 48 typedef base::Callback<void (base::PlatformFileError)> PlatformGeneralCallback;
48 49
49 class PlatformGeneralCallbackTranslator 50 class PlatformGeneralCallbackTranslator
50 : public fileapi::FileSystemCallbackDispatcher { 51 : public NullFileSystemCallbackDispatcher {
51 public: 52 public:
52 explicit PlatformGeneralCallbackTranslator( 53 explicit PlatformGeneralCallbackTranslator(
53 const PlatformGeneralCallback& callback) 54 const PlatformGeneralCallback& callback)
54 : callback_(callback) {} 55 : callback_(callback) {}
55 56
56 virtual ~PlatformGeneralCallbackTranslator() {} 57 virtual ~PlatformGeneralCallbackTranslator() {}
57 58
58 virtual void DidSucceed() OVERRIDE { 59 virtual void DidSucceed() OVERRIDE {
59 callback_.Run(base::PLATFORM_FILE_OK); 60 callback_.Run(base::PLATFORM_FILE_OK);
60 } 61 }
61 62
62 virtual void DidReadMetadata(const base::PlatformFileInfo& file_info,
63 const base::FilePath& platform_path) OVERRIDE {
64 NOTREACHED();
65 }
66
67 virtual void DidCreateSnapshotFile(
68 const base::PlatformFileInfo& file_info,
69 const base::FilePath& platform_path) OVERRIDE {
70 NOTREACHED();
71 }
72
73 virtual void DidReadDirectory(
74 const std::vector<base::FileUtilProxy::Entry>& entries,
75 bool has_more) OVERRIDE {
76 NOTREACHED();
77 }
78
79 virtual void DidOpenFileSystem(const std::string& name,
80 const GURL& root) OVERRIDE {
81 NOTREACHED();
82 }
83
84 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE {
85 callback_.Run(error_code);
yzshen1 2013/04/08 21:05:16 Did you miss one?
victorhsieh 2013/04/08 23:44:38 Thanks for catching. And I removed ExecutePlatfor
86 }
87
88 virtual void DidWrite(int64 bytes, bool complete) OVERRIDE {
89 NOTREACHED();
90 }
91
92 virtual void DidOpenFile(base::PlatformFile file) OVERRIDE {
93 NOTREACHED();
94 }
95
96 private: 63 private:
97 PlatformGeneralCallback callback_; 64 PlatformGeneralCallback callback_;
98 }; 65 };
99 66
100 int32_t ErrorOrByteNumber(int32_t pp_error, int32_t byte_number) { 67 int32_t ErrorOrByteNumber(int32_t pp_error, int32_t byte_number) {
101 // On the plugin side, some callbacks expect a parameter that means different 68 // On the plugin side, some callbacks expect a parameter that means different
102 // things depending on whether is negative or not. We translate for those 69 // things depending on whether is negative or not. We translate for those
103 // callbacks here. 70 // callbacks here.
104 return pp_error == PP_OK ? byte_number : pp_error; 71 return pp_error == PP_OK ? byte_number : pp_error;
105 } 72 }
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 // On the plugin side, the callback expects a parameter with different meaning 560 // On the plugin side, the callback expects a parameter with different meaning
594 // depends on whether is negative or not. It is the result here. We translate 561 // depends on whether is negative or not. It is the result here. We translate
595 // for the callback. 562 // for the callback.
596 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); 563 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code);
597 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); 564 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written));
598 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); 565 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply());
599 state_manager_.SetOperationFinished(); 566 state_manager_.SetOperationFinished();
600 } 567 }
601 568
602 } // namespace content 569 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698