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

Side by Side Diff: storage/browser/fileapi/async_file_util_adapter.cc

Issue 1120553002: [storage] Replace MessageLoopProxy usage with ThreadTaskRunnerHandle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Review Nits Created 5 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "storage/browser/fileapi/async_file_util_adapter.h" 5 #include "storage/browser/fileapi/async_file_util_adapter.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/sequenced_task_runner.h" 10 #include "base/sequenced_task_runner.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 base::File::Error error_; 79 base::File::Error error_;
80 base::File::Info file_info_; 80 base::File::Info file_info_;
81 base::FilePath platform_path_; 81 base::FilePath platform_path_;
82 storage::ScopedFile scoped_file_; 82 storage::ScopedFile scoped_file_;
83 DISALLOW_COPY_AND_ASSIGN(GetFileInfoHelper); 83 DISALLOW_COPY_AND_ASSIGN(GetFileInfoHelper);
84 }; 84 };
85 85
86 void ReadDirectoryHelper(FileSystemFileUtil* file_util, 86 void ReadDirectoryHelper(FileSystemFileUtil* file_util,
87 FileSystemOperationContext* context, 87 FileSystemOperationContext* context,
88 const FileSystemURL& url, 88 const FileSystemURL& url,
89 base::SingleThreadTaskRunner* origin_loop, 89 base::SingleThreadTaskRunner* origin_runner,
90 const AsyncFileUtil::ReadDirectoryCallback& callback) { 90 const AsyncFileUtil::ReadDirectoryCallback& callback) {
91 base::File::Info file_info; 91 base::File::Info file_info;
92 base::FilePath platform_path; 92 base::FilePath platform_path;
93 base::File::Error error = file_util->GetFileInfo( 93 base::File::Error error = file_util->GetFileInfo(
94 context, url, &file_info, &platform_path); 94 context, url, &file_info, &platform_path);
95 95
96 if (error == base::File::FILE_OK && !file_info.is_directory) 96 if (error == base::File::FILE_OK && !file_info.is_directory)
97 error = base::File::FILE_ERROR_NOT_A_DIRECTORY; 97 error = base::File::FILE_ERROR_NOT_A_DIRECTORY;
98 98
99 std::vector<DirectoryEntry> entries; 99 std::vector<DirectoryEntry> entries;
100 if (error != base::File::FILE_OK) { 100 if (error != base::File::FILE_OK) {
101 origin_loop->PostTask( 101 origin_runner->PostTask(
102 FROM_HERE, base::Bind(callback, error, entries, false /* has_more */)); 102 FROM_HERE, base::Bind(callback, error, entries, false /* has_more */));
103 return; 103 return;
104 } 104 }
105 105
106 // Note: Increasing this value may make some tests in LayoutTests meaningless. 106 // Note: Increasing this value may make some tests in LayoutTests meaningless.
107 // (Namely, read-directory-many.html and read-directory-sync-many.html are 107 // (Namely, read-directory-many.html and read-directory-sync-many.html are
108 // assuming that they are reading much more entries than this constant.) 108 // assuming that they are reading much more entries than this constant.)
109 const size_t kResultChunkSize = 100; 109 const size_t kResultChunkSize = 100;
110 110
111 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( 111 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum(
112 file_util->CreateFileEnumerator(context, url)); 112 file_util->CreateFileEnumerator(context, url));
113 113
114 base::FilePath current; 114 base::FilePath current;
115 while (!(current = file_enum->Next()).empty()) { 115 while (!(current = file_enum->Next()).empty()) {
116 DirectoryEntry entry; 116 DirectoryEntry entry;
117 entry.is_directory = file_enum->IsDirectory(); 117 entry.is_directory = file_enum->IsDirectory();
118 entry.name = VirtualPath::BaseName(current).value(); 118 entry.name = VirtualPath::BaseName(current).value();
119 entry.size = file_enum->Size(); 119 entry.size = file_enum->Size();
120 entry.last_modified_time = file_enum->LastModifiedTime(); 120 entry.last_modified_time = file_enum->LastModifiedTime();
121 entries.push_back(entry); 121 entries.push_back(entry);
122 122
123 if (entries.size() == kResultChunkSize) { 123 if (entries.size() == kResultChunkSize) {
124 origin_loop->PostTask( 124 origin_runner->PostTask(
125 FROM_HERE, base::Bind(callback, base::File::FILE_OK, entries, 125 FROM_HERE, base::Bind(callback, base::File::FILE_OK, entries,
126 true /* has_more */)); 126 true /* has_more */));
127 entries.clear(); 127 entries.clear();
128 } 128 }
129 } 129 }
130 origin_loop->PostTask( 130 origin_runner->PostTask(
131 FROM_HERE, base::Bind(callback, base::File::FILE_OK, entries, 131 FROM_HERE, base::Bind(callback, base::File::FILE_OK, entries,
132 false /* has_more */)); 132 false /* has_more */));
133 } 133 }
134 134
135 void RunCreateOrOpenCallback( 135 void RunCreateOrOpenCallback(
136 FileSystemOperationContext* context, 136 FileSystemOperationContext* context,
137 const AsyncFileUtil::CreateOrOpenCallback& callback, 137 const AsyncFileUtil::CreateOrOpenCallback& callback,
138 base::File file) { 138 base::File file) {
139 callback.Run(file.Pass(), base::Closure()); 139 callback.Run(file.Pass(), base::Closure());
140 } 140 }
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 GetFileInfoHelper* helper = new GetFileInfoHelper; 343 GetFileInfoHelper* helper = new GetFileInfoHelper;
344 const bool success = context_ptr->task_runner()->PostTaskAndReply( 344 const bool success = context_ptr->task_runner()->PostTaskAndReply(
345 FROM_HERE, 345 FROM_HERE,
346 Bind(&GetFileInfoHelper::CreateSnapshotFile, Unretained(helper), 346 Bind(&GetFileInfoHelper::CreateSnapshotFile, Unretained(helper),
347 sync_file_util_.get(), base::Owned(context_ptr), url), 347 sync_file_util_.get(), base::Owned(context_ptr), url),
348 Bind(&GetFileInfoHelper::ReplySnapshotFile, Owned(helper), callback)); 348 Bind(&GetFileInfoHelper::ReplySnapshotFile, Owned(helper), callback));
349 DCHECK(success); 349 DCHECK(success);
350 } 350 }
351 351
352 } // namespace storage 352 } // namespace storage
OLDNEW
« no previous file with comments | « storage/browser/database/database_tracker.cc ('k') | storage/browser/fileapi/file_system_dir_url_request_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698