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

Side by Side Diff: webkit/plugins/ppapi/quota_file_io.cc

Issue 11615036: Reduce copy on QuotaFileIO::Write (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "webkit/plugins/ppapi/quota_file_io.h" 5 #include "webkit/plugins/ppapi/quota_file_io.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/message_loop_proxy.h" 12 #include "base/message_loop_proxy.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/task_runner_util.h"
14 #include "webkit/plugins/ppapi/host_globals.h" 15 #include "webkit/plugins/ppapi/host_globals.h"
15 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 16 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
16 #include "webkit/plugins/ppapi/resource_helper.h" 17 #include "webkit/plugins/ppapi/resource_helper.h"
17 18
18 using base::PlatformFile; 19 using base::PlatformFile;
19 using base::PlatformFileError; 20 using base::PlatformFileError;
20 using quota::StorageType; 21 using quota::StorageType;
21 22
22 namespace webkit { 23 namespace webkit {
23 namespace ppapi { 24 namespace ppapi {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 return; 94 return;
94 } 95 }
95 DCHECK(buffer_.get()); 96 DCHECK(buffer_.get());
96 97
97 PluginDelegate* plugin_delegate = quota_io_->GetPluginDelegate(); 98 PluginDelegate* plugin_delegate = quota_io_->GetPluginDelegate();
98 if (!plugin_delegate) { 99 if (!plugin_delegate) {
99 DidFail(base::PLATFORM_FILE_ERROR_FAILED); 100 DidFail(base::PLATFORM_FILE_ERROR_FAILED);
100 return; 101 return;
101 } 102 }
102 103
103 if (!base::FileUtilProxy::Write( 104 if (!base::PostTaskAndReplyWithResult(
104 plugin_delegate->GetFileThreadMessageLoopProxy(), 105 plugin_delegate->GetFileThreadMessageLoopProxy(), FROM_HERE,
105 quota_io_->file_, offset_, buffer_.get(), bytes_to_write_, 106 base::Bind(&base::WritePlatformFile,
106 base::Bind(&WriteOperation::DidFinish, 107 quota_io_->file_, offset_,
108 base::Owned(buffer_.release()),
109 bytes_to_write_),
110 base::Bind(&WriteOperation::DidWrite,
107 weak_factory_.GetWeakPtr()))) { 111 weak_factory_.GetWeakPtr()))) {
108 DidFail(base::PLATFORM_FILE_ERROR_FAILED); 112 DidFail(base::PLATFORM_FILE_ERROR_FAILED);
109 return; 113 return;
110 } 114 }
111 } 115 }
112 116
113 virtual void DidFail(PlatformFileError error) OVERRIDE { 117 virtual void DidFail(PlatformFileError error) OVERRIDE {
114 DidFinish(error, 0); 118 DidFinish(error, 0);
115 } 119 }
116 120
117 bool finished() const { return finished_; } 121 bool finished() const { return finished_; }
118 122
119 virtual void WillRunCallback() { 123 virtual void WillRunCallback() {
120 base::MessageLoopProxy::current()->PostTask( 124 base::MessageLoopProxy::current()->PostTask(
121 FROM_HERE, 125 FROM_HERE,
122 base::Bind(&WriteOperation::RunCallback, weak_factory_.GetWeakPtr())); 126 base::Bind(&WriteOperation::RunCallback, weak_factory_.GetWeakPtr()));
123 } 127 }
124 128
125 private: 129 private:
130 void DidWrite(int bytes_written) {
131 base::PlatformFileError error = bytes_written >= 0 ?
brettw 2013/01/09 20:17:10 What happens if you write 0 bytes? It looks like b
tzik 2013/01/10 04:02:36 Right, this changes its behavior for 0-byte write.
132 base::PLATFORM_FILE_OK : base::PLATFORM_FILE_ERROR_FAILED;
133 DidFinish(error, bytes_written);
134 }
135
126 void DidFinish(PlatformFileError status, int bytes_written) { 136 void DidFinish(PlatformFileError status, int bytes_written) {
127 finished_ = true; 137 finished_ = true;
128 status_ = status; 138 status_ = status;
129 bytes_written_ = bytes_written; 139 bytes_written_ = bytes_written;
130 int64_t max_offset = 140 int64_t max_offset =
131 (status != base::PLATFORM_FILE_OK) ? 0 : offset_ + bytes_written; 141 (status != base::PLATFORM_FILE_OK) ? 0 : offset_ + bytes_written;
132 // This may delete itself by calling RunCallback. 142 // This may delete itself by calling RunCallback.
133 quota_io_->DidWrite(this, max_offset); 143 quota_io_->DidWrite(this, max_offset);
134 } 144 }
135 145
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 405
396 406
397 PluginDelegate* plugin_delegate = GetPluginDelegate(); 407 PluginDelegate* plugin_delegate = GetPluginDelegate();
398 if (plugin_delegate) 408 if (plugin_delegate)
399 plugin_delegate->DidUpdateFile(file_url_, delta); 409 plugin_delegate->DidUpdateFile(file_url_, delta);
400 inflight_operations_ = 0; 410 inflight_operations_ = 0;
401 } 411 }
402 412
403 } // namespace ppapi 413 } // namespace ppapi
404 } // namespace webkit 414 } // namespace webkit
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698