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

Side by Side Diff: chrome/browser/chromeos/drive/local_file_reader.cc

Issue 16998003: Update CrOS to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/chromeos/drive/local_file_reader.h" 5 #include "chrome/browser/chromeos/drive/local_file_reader.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 base::PlatformFile platform_file_; 110 base::PlatformFile platform_file_;
111 111
112 DISALLOW_COPY_AND_ASSIGN(ScopedPlatformFile); 112 DISALLOW_COPY_AND_ASSIGN(ScopedPlatformFile);
113 }; 113 };
114 114
115 LocalFileReader::LocalFileReader( 115 LocalFileReader::LocalFileReader(
116 base::SequencedTaskRunner* sequenced_task_runner) 116 base::SequencedTaskRunner* sequenced_task_runner)
117 : sequenced_task_runner_(sequenced_task_runner), 117 : sequenced_task_runner_(sequenced_task_runner),
118 platform_file_(base::kInvalidPlatformFileValue), 118 platform_file_(base::kInvalidPlatformFileValue),
119 weak_ptr_factory_(this) { 119 weak_ptr_factory_(this) {
120 DCHECK(sequenced_task_runner_); 120 DCHECK(sequenced_task_runner_.get());
121 } 121 }
122 122
123 LocalFileReader::~LocalFileReader() { 123 LocalFileReader::~LocalFileReader() {
124 PostCloseIfNeeded(sequenced_task_runner_.get(), platform_file_); 124 PostCloseIfNeeded(sequenced_task_runner_.get(), platform_file_);
125 } 125 }
126 126
127 void LocalFileReader::Open(const base::FilePath& file_path, 127 void LocalFileReader::Open(const base::FilePath& file_path,
128 int64 offset, 128 int64 offset,
129 const net::CompletionCallback& callback) { 129 const net::CompletionCallback& callback) {
130 DCHECK(!callback.is_null()); 130 DCHECK(!callback.is_null());
131 DCHECK_EQ(base::kInvalidPlatformFileValue, platform_file_); 131 DCHECK_EQ(base::kInvalidPlatformFileValue, platform_file_);
132 132
133 ScopedPlatformFile* platform_file = 133 ScopedPlatformFile* platform_file =
134 new ScopedPlatformFile(sequenced_task_runner_); 134 new ScopedPlatformFile(sequenced_task_runner_.get());
135 base::PostTaskAndReplyWithResult( 135 base::PostTaskAndReplyWithResult(
136 sequenced_task_runner_, 136 sequenced_task_runner_.get(),
137 FROM_HERE, 137 FROM_HERE,
138 base::Bind(&OpenAndSeekOnBlockingPool, 138 base::Bind(
139 file_path, offset, platform_file->ptr()), 139 &OpenAndSeekOnBlockingPool, file_path, offset, platform_file->ptr()),
140 base::Bind(&LocalFileReader::OpenAfterBlockingPoolTask, 140 base::Bind(&LocalFileReader::OpenAfterBlockingPoolTask,
141 weak_ptr_factory_.GetWeakPtr(), 141 weak_ptr_factory_.GetWeakPtr(),
142 callback, base::Owned(platform_file))); 142 callback,
143 base::Owned(platform_file)));
143 } 144 }
144 145
145 void LocalFileReader::Read(net::IOBuffer* in_buffer, 146 void LocalFileReader::Read(net::IOBuffer* in_buffer,
146 int buffer_length, 147 int buffer_length,
147 const net::CompletionCallback& callback) { 148 const net::CompletionCallback& callback) {
148 DCHECK(!callback.is_null()); 149 DCHECK(!callback.is_null());
149 DCHECK_NE(base::kInvalidPlatformFileValue, platform_file_); 150 DCHECK_NE(base::kInvalidPlatformFileValue, platform_file_);
150 151
151 scoped_refptr<net::IOBuffer> buffer(in_buffer); 152 scoped_refptr<net::IOBuffer> buffer(in_buffer);
152 base::PostTaskAndReplyWithResult( 153 base::PostTaskAndReplyWithResult(
153 sequenced_task_runner_, 154 sequenced_task_runner_.get(),
154 FROM_HERE, 155 FROM_HERE,
155 base::Bind(&ReadOnBlockingPool, platform_file_, buffer, buffer_length), 156 base::Bind(&ReadOnBlockingPool, platform_file_, buffer, buffer_length),
156 callback); 157 callback);
157 } 158 }
158 159
159 void LocalFileReader::OpenAfterBlockingPoolTask( 160 void LocalFileReader::OpenAfterBlockingPoolTask(
160 const net::CompletionCallback& callback, 161 const net::CompletionCallback& callback,
161 ScopedPlatformFile* platform_file, 162 ScopedPlatformFile* platform_file,
162 int open_result) { 163 int open_result) {
163 DCHECK(!callback.is_null()); 164 DCHECK(!callback.is_null());
164 DCHECK(platform_file); 165 DCHECK(platform_file);
165 DCHECK_EQ(base::kInvalidPlatformFileValue, platform_file_); 166 DCHECK_EQ(base::kInvalidPlatformFileValue, platform_file_);
166 167
167 if (open_result == net::OK) { 168 if (open_result == net::OK) {
168 DCHECK_NE(base::kInvalidPlatformFileValue, *platform_file->ptr()); 169 DCHECK_NE(base::kInvalidPlatformFileValue, *platform_file->ptr());
169 platform_file_ = platform_file->release(); 170 platform_file_ = platform_file->release();
170 } 171 }
171 172
172 callback.Run(open_result); 173 callback.Run(open_result);
173 } 174 }
174 175
175 } // namespace util 176 } // namespace util
176 } // namespace drive 177 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system_util_unittest.cc ('k') | chrome/browser/chromeos/drive/resource_metadata.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698