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

Side by Side Diff: webkit/fileapi/file_writer_delegate.cc

Issue 10197007: Change webkit/{fileapi,quota} code to use TaskRunner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test fix Created 8 years, 7 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 | « webkit/fileapi/file_writer_delegate.h ('k') | webkit/fileapi/file_writer_delegate_unittest.cc » ('j') | 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/fileapi/file_writer_delegate.h" 5 #include "webkit/fileapi/file_writer_delegate.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/file_util_proxy.h" 9 #include "base/file_util_proxy.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/message_loop_proxy.h"
12 #include "base/sequenced_task_runner.h"
11 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
12 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
13 #include "webkit/fileapi/file_system_context.h" 15 #include "webkit/fileapi/file_system_context.h"
14 #include "webkit/fileapi/file_system_operation.h" 16 #include "webkit/fileapi/file_system_operation.h"
15 #include "webkit/fileapi/file_system_operation_context.h" 17 #include "webkit/fileapi/file_system_operation_context.h"
16 #include "webkit/fileapi/file_system_quota_util.h" 18 #include "webkit/fileapi/file_system_quota_util.h"
17 #include "webkit/fileapi/quota_file_util.h" 19 #include "webkit/fileapi/quota_file_util.h"
18 20
19 namespace fileapi { 21 namespace fileapi {
20 22
21 static const int kReadBufSize = 32768; 23 static const int kReadBufSize = 32768;
22 24
23 namespace { 25 namespace {
24 26
25 typedef base::Callback<void(base::PlatformFileError /* error code */, 27 typedef base::Callback<void(base::PlatformFileError /* error code */,
26 const base::PlatformFileInfo& /* file_info */)> 28 const base::PlatformFileInfo& /* file_info */)>
27 InitializeTaskCallback; 29 InitializeTaskCallback;
28 30
29 class InitializeTask : public base::RefCountedThreadSafe<InitializeTask> { 31 class InitializeTask : public base::RefCountedThreadSafe<InitializeTask> {
30 public: 32 public:
31 InitializeTask( 33 InitializeTask(
32 base::PlatformFile file, 34 base::PlatformFile file,
33 const FileSystemPath& path, 35 const FileSystemPath& path,
34 FileSystemOperationContext* context, 36 FileSystemOperationContext* context,
35 const InitializeTaskCallback& callback) 37 const InitializeTaskCallback& callback)
36 : origin_message_loop_proxy_( 38 : original_loop_(base::MessageLoopProxy::current()),
37 base::MessageLoopProxy::current()),
38 error_code_(base::PLATFORM_FILE_OK), 39 error_code_(base::PLATFORM_FILE_OK),
39 file_(file), 40 file_(file),
40 path_(path), 41 path_(path),
41 context_(*context), 42 context_(*context),
42 callback_(callback) { 43 callback_(callback) {
43 DCHECK_EQ(false, callback.is_null()); 44 DCHECK_EQ(false, callback.is_null());
44 } 45 }
45 46
46 bool Start(scoped_refptr<base::MessageLoopProxy> message_loop_proxy, 47 bool Start(base::SequencedTaskRunner* task_runner,
47 const tracked_objects::Location& from_here) { 48 const tracked_objects::Location& from_here) {
48 return message_loop_proxy->PostTask( 49 return task_runner->PostTask(
49 from_here, 50 from_here,
50 base::Bind(&InitializeTask::ProcessOnTargetThread, this)); 51 base::Bind(&InitializeTask::ProcessOnTargetThread, this));
51 } 52 }
52 53
53 private: 54 private:
54 friend class base::RefCountedThreadSafe<InitializeTask>; 55 friend class base::RefCountedThreadSafe<InitializeTask>;
55 ~InitializeTask() {} 56 ~InitializeTask() {}
56 57
57 void RunCallback() { 58 void RunCallback() {
58 callback_.Run(error_code_, file_info_); 59 callback_.Run(error_code_, file_info_);
59 } 60 }
60 61
61 void ProcessOnTargetThread() { 62 void ProcessOnTargetThread() {
62 DCHECK(context_.file_system_context()); 63 DCHECK(context_.file_system_context());
63 FileSystemQuotaUtil* quota_util = context_.file_system_context()-> 64 FileSystemQuotaUtil* quota_util = context_.file_system_context()->
64 GetQuotaUtil(path_.type()); 65 GetQuotaUtil(path_.type());
65 if (quota_util) { 66 if (quota_util) {
66 DCHECK(quota_util->proxy()); 67 DCHECK(quota_util->proxy());
67 quota_util->proxy()->StartUpdateOrigin(path_.origin(), path_.type()); 68 quota_util->proxy()->StartUpdateOrigin(path_.origin(), path_.type());
68 } 69 }
69 if (!base::GetPlatformFileInfo(file_, &file_info_)) 70 if (!base::GetPlatformFileInfo(file_, &file_info_))
70 error_code_ = base::PLATFORM_FILE_ERROR_FAILED; 71 error_code_ = base::PLATFORM_FILE_ERROR_FAILED;
71 origin_message_loop_proxy_->PostTask( 72 original_loop_->PostTask(
72 FROM_HERE, 73 FROM_HERE,
73 base::Bind(&InitializeTask::RunCallback, this)); 74 base::Bind(&InitializeTask::RunCallback, this));
74 } 75 }
75 76
76 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; 77 scoped_refptr<base::MessageLoopProxy> original_loop_;
77 base::PlatformFileError error_code_; 78 base::PlatformFileError error_code_;
78 79
79 base::PlatformFile file_; 80 base::PlatformFile file_;
80 FileSystemPath path_; 81 FileSystemPath path_;
81 FileSystemOperationContext context_; 82 FileSystemOperationContext context_;
82 InitializeTaskCallback callback_; 83 InitializeTaskCallback callback_;
83 84
84 base::PlatformFileInfo file_info_; 85 base::PlatformFileInfo file_info_;
85 }; 86 };
86 87
87 } // namespace (anonymous) 88 } // namespace (anonymous)
88 89
89 FileWriterDelegate::FileWriterDelegate( 90 FileWriterDelegate::FileWriterDelegate(
90 FileSystemOperation* file_system_operation, 91 FileSystemOperation* file_system_operation,
91 const FileSystemPath& path, 92 const FileSystemPath& path,
92 int64 offset, 93 int64 offset)
93 scoped_refptr<base::MessageLoopProxy> proxy)
94 : file_system_operation_(file_system_operation), 94 : file_system_operation_(file_system_operation),
95 file_(base::kInvalidPlatformFileValue), 95 file_(base::kInvalidPlatformFileValue),
96 path_(path), 96 path_(path),
97 offset_(offset), 97 offset_(offset),
98 proxy_(proxy),
99 bytes_written_backlog_(0), 98 bytes_written_backlog_(0),
100 bytes_written_(0), 99 bytes_written_(0),
101 bytes_read_(0), 100 bytes_read_(0),
102 total_bytes_written_(0), 101 total_bytes_written_(0),
103 allowed_bytes_to_write_(0), 102 allowed_bytes_to_write_(0),
104 io_buffer_(new net::IOBufferWithSize(kReadBufSize)), 103 io_buffer_(new net::IOBufferWithSize(kReadBufSize)),
105 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 104 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
106 } 105 }
107 106
108 FileWriterDelegate::~FileWriterDelegate() { 107 FileWriterDelegate::~FileWriterDelegate() {
(...skipping 26 matching lines...) Expand all
135 void FileWriterDelegate::Start(base::PlatformFile file, 134 void FileWriterDelegate::Start(base::PlatformFile file,
136 net::URLRequest* request) { 135 net::URLRequest* request) {
137 file_ = file; 136 file_ = file;
138 request_ = request; 137 request_ = request;
139 138
140 scoped_refptr<InitializeTask> relay = new InitializeTask( 139 scoped_refptr<InitializeTask> relay = new InitializeTask(
141 file_, path_, 140 file_, path_,
142 file_system_operation_context(), 141 file_system_operation_context(),
143 base::Bind(&FileWriterDelegate::OnGetFileInfoAndCallStartUpdate, 142 base::Bind(&FileWriterDelegate::OnGetFileInfoAndCallStartUpdate,
144 weak_factory_.GetWeakPtr())); 143 weak_factory_.GetWeakPtr()));
145 relay->Start(proxy_, FROM_HERE); 144 relay->Start(file_system_operation_context()->file_task_runner(), FROM_HERE);
146 } 145 }
147 146
148 void FileWriterDelegate::OnReceivedRedirect(net::URLRequest* request, 147 void FileWriterDelegate::OnReceivedRedirect(net::URLRequest* request,
149 const GURL& new_url, 148 const GURL& new_url,
150 bool* defer_redirect) { 149 bool* defer_redirect) {
151 NOTREACHED(); 150 NOTREACHED();
152 OnError(base::PLATFORM_FILE_ERROR_SECURITY); 151 OnError(base::PLATFORM_FILE_ERROR_SECURITY);
153 } 152 }
154 153
155 void FileWriterDelegate::OnAuthRequired(net::URLRequest* request, 154 void FileWriterDelegate::OnAuthRequired(net::URLRequest* request,
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 319
321 FileSystemQuotaUtil* FileWriterDelegate::quota_util() const { 320 FileSystemQuotaUtil* FileWriterDelegate::quota_util() const {
322 DCHECK(file_system_operation_); 321 DCHECK(file_system_operation_);
323 DCHECK(file_system_operation_->file_system_context()); 322 DCHECK(file_system_operation_->file_system_context());
324 DCHECK(file_system_operation_->file_system_operation_context()); 323 DCHECK(file_system_operation_->file_system_operation_context());
325 return file_system_operation_->file_system_context()->GetQuotaUtil( 324 return file_system_operation_->file_system_context()->GetQuotaUtil(
326 path_.type()); 325 path_.type());
327 } 326 }
328 327
329 } // namespace fileapi 328 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_writer_delegate.h ('k') | webkit/fileapi/file_writer_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698