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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/throttled_file_system.cc

Issue 845083005: [fsp] Simplify aborting logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed a comment. Created 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/file_system_provider/throttled_file_system.h" 5 #include "chrome/browser/chromeos/file_system_provider/throttled_file_system.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/files/file.h" 10 #include "base/files/file.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 int64 offset, 50 int64 offset,
51 int length, 51 int length,
52 const ReadChunkReceivedCallback& callback) { 52 const ReadChunkReceivedCallback& callback) {
53 return file_system_->ReadFile(file_handle, buffer, offset, length, callback); 53 return file_system_->ReadFile(file_handle, buffer, offset, length, callback);
54 } 54 }
55 55
56 AbortCallback ThrottledFileSystem::OpenFile(const base::FilePath& file_path, 56 AbortCallback ThrottledFileSystem::OpenFile(const base::FilePath& file_path,
57 OpenFileMode mode, 57 OpenFileMode mode,
58 const OpenFileCallback& callback) { 58 const OpenFileCallback& callback) {
59 const size_t task_token = open_queue_->NewToken(); 59 const size_t task_token = open_queue_->NewToken();
60 return open_queue_->Enqueue( 60 open_queue_->Enqueue(
61 task_token, 61 task_token,
62 base::Bind( 62 base::Bind(
63 &ProvidedFileSystemInterface::OpenFile, 63 &ProvidedFileSystemInterface::OpenFile,
64 base::Unretained(file_system_.get()), // Outlives the queue. 64 base::Unretained(file_system_.get()), // Outlives the queue.
65 file_path, mode, 65 file_path, mode,
66 base::Bind(&ThrottledFileSystem::OnOpenFileCompleted, 66 base::Bind(&ThrottledFileSystem::OnOpenFileCompleted,
67 weak_ptr_factory_.GetWeakPtr(), task_token, callback))); 67 weak_ptr_factory_.GetWeakPtr(), task_token, callback)));
68 return base::Bind(&ThrottledFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(),
69 task_token);
68 } 70 }
69 71
70 AbortCallback ThrottledFileSystem::CloseFile( 72 AbortCallback ThrottledFileSystem::CloseFile(
71 int file_handle, 73 int file_handle,
72 const storage::AsyncFileUtil::StatusCallback& callback) { 74 const storage::AsyncFileUtil::StatusCallback& callback) {
73 return file_system_->CloseFile( 75 return file_system_->CloseFile(
74 file_handle, 76 file_handle,
75 base::Bind(&ThrottledFileSystem::OnCloseFileCompleted, 77 base::Bind(&ThrottledFileSystem::OnCloseFileCompleted,
76 weak_ptr_factory_.GetWeakPtr(), file_handle, callback)); 78 weak_ptr_factory_.GetWeakPtr(), file_handle, callback));
77 } 79 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 const std::string& tag, 176 const std::string& tag,
175 const storage::AsyncFileUtil::StatusCallback& callback) { 177 const storage::AsyncFileUtil::StatusCallback& callback) {
176 return file_system_->Notify(entry_path, recursive, change_type, 178 return file_system_->Notify(entry_path, recursive, change_type,
177 changes.Pass(), tag, callback); 179 changes.Pass(), tag, callback);
178 } 180 }
179 181
180 base::WeakPtr<ProvidedFileSystemInterface> ThrottledFileSystem::GetWeakPtr() { 182 base::WeakPtr<ProvidedFileSystemInterface> ThrottledFileSystem::GetWeakPtr() {
181 return weak_ptr_factory_.GetWeakPtr(); 183 return weak_ptr_factory_.GetWeakPtr();
182 } 184 }
183 185
186 void ThrottledFileSystem::Abort(int queue_token) {
187 open_queue_->Abort(queue_token);
188 }
189
184 void ThrottledFileSystem::OnOpenFileCompleted(int queue_token, 190 void ThrottledFileSystem::OnOpenFileCompleted(int queue_token,
185 const OpenFileCallback& callback, 191 const OpenFileCallback& callback,
186 int file_handle, 192 int file_handle,
187 base::File::Error result) { 193 base::File::Error result) {
188 open_queue_->Complete(queue_token); 194 open_queue_->Complete(queue_token);
189 195
190 // If the file is opened successfully then hold the queue token until the file 196 // If the file is opened successfully then hold the queue token until the file
191 // is closed. 197 // is closed.
192 if (result == base::File::FILE_OK) 198 if (result == base::File::FILE_OK)
193 opened_files_[file_handle] = queue_token; 199 opened_files_[file_handle] = queue_token;
(...skipping 15 matching lines...) Expand all
209 215
210 const int queue_token = it->second; 216 const int queue_token = it->second;
211 open_queue_->Remove(queue_token); 217 open_queue_->Remove(queue_token);
212 opened_files_.erase(file_handle); 218 opened_files_.erase(file_handle);
213 219
214 callback.Run(result); 220 callback.Run(result);
215 } 221 }
216 222
217 } // namespace file_system_provider 223 } // namespace file_system_provider
218 } // namespace chromeos 224 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698