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

Side by Side Diff: chrome/browser/extensions/api/file_system/file_system_api.cc

Issue 22336003: Manage fan-in for writable file entry checking on the UI thread. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 4 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
« 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 "chrome/browser/extensions/api/file_system/file_system_api.h" 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
6 6
7 #include "apps/saved_files_service.h" 7 #include "apps/saved_files_service.h"
8 #include "apps/shell_window.h" 8 #include "apps/shell_window.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 content::BrowserThread::FILE, 308 content::BrowserThread::FILE,
309 FROM_HERE, 309 FROM_HERE,
310 base::Bind(&WritableFileChecker::CheckLocalWritableFiles, this, paths)); 310 base::Bind(&WritableFileChecker::CheckLocalWritableFiles, this, paths));
311 } 311 }
312 312
313 private: 313 private:
314 friend class base::RefCountedThreadSafe<WritableFileChecker>; 314 friend class base::RefCountedThreadSafe<WritableFileChecker>;
315 virtual ~WritableFileChecker() {} 315 virtual ~WritableFileChecker() {}
316 316
317 // Called when a work item is completed. If all work items are done, this 317 // Called when a work item is completed. If all work items are done, this
318 // posts a task to run AllTasksDone on the UI thread. 318 // calls the success or failure callback.
319 void TaskDone() { 319 void TaskDone() {
320 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 320 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
321 if (--outstanding_tasks_ == 0) { 321 if (--outstanding_tasks_ == 0) {
322 content::BrowserThread::PostTask( 322 if (error_.empty())
323 content::BrowserThread::UI, 323 on_success_.Run();
324 FROM_HERE, 324 else
325 base::Bind(&WritableFileChecker::AllTasksDone, this)); 325 on_failure_.Run(error_);
326 } 326 }
327 } 327 }
328 328
329 // Called on the UI thread when all tasks are done.
330 void AllTasksDone() {
331 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
332 if (error_.empty())
333 on_success_.Run();
334 else
335 on_failure_.Run(error_);
336 }
337
338 // Reports an error in completing a work item. This may be called more than 329 // Reports an error in completing a work item. This may be called more than
339 // once, but only the last message will be retained. 330 // once, but only the last message will be retained.
340 void Error(const std::string& message) { 331 void Error(const std::string& message) {
341 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
342 DCHECK(!message.empty()); 332 DCHECK(!message.empty());
343 error_ = message; 333 error_ = message;
344 TaskDone(); 334 TaskDone();
345 } 335 }
346 336
347 void CheckLocalWritableFiles(const std::vector<base::FilePath>& paths) { 337 void CheckLocalWritableFiles(const std::vector<base::FilePath>& paths) {
348 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 338 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
349 std::string error; 339 std::string error;
350 for (std::vector<base::FilePath>::const_iterator it = paths.begin(); 340 for (std::vector<base::FilePath>::const_iterator it = paths.begin();
351 it != paths.end(); ++it) { 341 it != paths.end(); ++it) {
352 if (!DoCheckWritableFile(*it, extension_path_, &error)) { 342 if (!DoCheckWritableFile(*it, extension_path_, &error)) {
353 Error(error); 343 content::BrowserThread::PostTask(
344 content::BrowserThread::UI,
345 FROM_HERE,
346 base::Bind(&WritableFileChecker::Error, this, error));
354 return; 347 return;
355 } 348 }
356 } 349 }
357 TaskDone(); 350 content::BrowserThread::PostTask(
351 content::BrowserThread::UI,
352 FROM_HERE,
353 base::Bind(&WritableFileChecker::TaskDone, this));
358 } 354 }
359 355
360 #if defined(OS_CHROMEOS) 356 #if defined(OS_CHROMEOS)
361 void CheckRemoteWritableFile(drive::FileError error, 357 void CheckRemoteWritableFile(drive::FileError error,
362 const base::FilePath& path) { 358 const base::FilePath& path) {
363 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
364 if (error == drive::FILE_ERROR_OK) { 359 if (error == drive::FILE_ERROR_OK) {
365 TaskDone(); 360 content::BrowserThread::PostTask(
361 content::BrowserThread::UI,
362 FROM_HERE,
363 base::Bind(&WritableFileChecker::TaskDone, this));
366 } else { 364 } else {
367 Error(base::StringPrintf(kWritableFileErrorFormat, 365 content::BrowserThread::PostTask(
368 path.BaseName().AsUTF8Unsafe().c_str())); 366 content::BrowserThread::UI,
367 FROM_HERE,
368 base::Bind(
369 &WritableFileChecker::Error,
370 this,
371 base::StringPrintf(kWritableFileErrorFormat,
372 path.BaseName().AsUTF8Unsafe().c_str())));
369 } 373 }
370 } 374 }
371 #endif 375 #endif
372 376
373 int outstanding_tasks_; 377 int outstanding_tasks_;
374 const base::FilePath extension_path_; 378 const base::FilePath extension_path_;
375 std::string error_; 379 std::string error_;
376 base::Closure on_success_; 380 base::Closure on_success_;
377 base::Callback<void(const std::string&)> on_failure_; 381 base::Callback<void(const std::string&)> on_failure_;
378 }; 382 };
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 if (needs_new_entry) { 1030 if (needs_new_entry) {
1027 entry_type_ = file_entry->writable ? WRITABLE : READ_ONLY; 1031 entry_type_ = file_entry->writable ? WRITABLE : READ_ONLY;
1028 CreateResponse(); 1032 CreateResponse();
1029 AddEntryToResponse(file_entry->path, file_entry->id); 1033 AddEntryToResponse(file_entry->path, file_entry->id);
1030 } 1034 }
1031 SendResponse(true); 1035 SendResponse(true);
1032 return true; 1036 return true;
1033 } 1037 }
1034 1038
1035 } // namespace extensions 1039 } // namespace extensions
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