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

Side by Side Diff: webkit/browser/fileapi/syncable/local_file_sync_context.cc

Issue 20989003: Deprecate FileSystemTaskRunners (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased 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 | 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 "webkit/browser/fileapi/syncable/local_file_sync_context.h" 5 #include "webkit/browser/fileapi/syncable/local_file_sync_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/platform_file.h" 9 #include "base/platform_file.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/task_runner_util.h" 12 #include "base/task_runner_util.h"
13 #include "webkit/browser/fileapi/file_system_context.h" 13 #include "webkit/browser/fileapi/file_system_context.h"
14 #include "webkit/browser/fileapi/file_system_file_util.h" 14 #include "webkit/browser/fileapi/file_system_file_util.h"
15 #include "webkit/browser/fileapi/file_system_operation_context.h" 15 #include "webkit/browser/fileapi/file_system_operation_context.h"
16 #include "webkit/browser/fileapi/file_system_operation_runner.h" 16 #include "webkit/browser/fileapi/file_system_operation_runner.h"
17 #include "webkit/browser/fileapi/file_system_task_runners.h"
18 #include "webkit/browser/fileapi/syncable/file_change.h" 17 #include "webkit/browser/fileapi/syncable/file_change.h"
19 #include "webkit/browser/fileapi/syncable/local_file_change_tracker.h" 18 #include "webkit/browser/fileapi/syncable/local_file_change_tracker.h"
20 #include "webkit/browser/fileapi/syncable/local_origin_change_observer.h" 19 #include "webkit/browser/fileapi/syncable/local_origin_change_observer.h"
21 #include "webkit/browser/fileapi/syncable/sync_file_metadata.h" 20 #include "webkit/browser/fileapi/syncable/sync_file_metadata.h"
22 #include "webkit/browser/fileapi/syncable/sync_file_system_backend.h" 21 #include "webkit/browser/fileapi/syncable/sync_file_system_backend.h"
23 #include "webkit/browser/fileapi/syncable/syncable_file_operation_runner.h" 22 #include "webkit/browser/fileapi/syncable/syncable_file_operation_runner.h"
24 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h" 23 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h"
25 #include "webkit/common/fileapi/file_system_util.h" 24 #include "webkit/common/fileapi/file_system_util.h"
26 25
27 using fileapi::FileSystemContext; 26 using fileapi::FileSystemContext;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 this)); 85 this));
87 } 86 }
88 87
89 void LocalFileSyncContext::GetFileForLocalSync( 88 void LocalFileSyncContext::GetFileForLocalSync(
90 FileSystemContext* file_system_context, 89 FileSystemContext* file_system_context,
91 const LocalFileSyncInfoCallback& callback) { 90 const LocalFileSyncInfoCallback& callback) {
92 DCHECK(file_system_context); 91 DCHECK(file_system_context);
93 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 92 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
94 93
95 std::deque<FileSystemURL>* urls = new std::deque<FileSystemURL>; 94 std::deque<FileSystemURL>* urls = new std::deque<FileSystemURL>;
96 file_system_context->task_runners()->file_task_runner()->PostTaskAndReply( 95 file_system_context->default_file_task_runner()->PostTaskAndReply(
97 FROM_HERE, 96 FROM_HERE,
98 base::Bind(&LocalFileSyncContext::GetNextURLsForSyncOnFileThread, 97 base::Bind(&LocalFileSyncContext::GetNextURLsForSyncOnFileThread,
99 this, make_scoped_refptr(file_system_context), 98 this, make_scoped_refptr(file_system_context),
100 base::Unretained(urls)), 99 base::Unretained(urls)),
101 base::Bind(&LocalFileSyncContext::TryPrepareForLocalSync, 100 base::Bind(&LocalFileSyncContext::TryPrepareForLocalSync,
102 this, make_scoped_refptr(file_system_context), 101 this, make_scoped_refptr(file_system_context),
103 base::Owned(urls), callback)); 102 base::Owned(urls), callback));
104 } 103 }
105 104
106 void LocalFileSyncContext::ClearChangesForURL( 105 void LocalFileSyncContext::ClearChangesForURL(
107 FileSystemContext* file_system_context, 106 FileSystemContext* file_system_context,
108 const FileSystemURL& url, 107 const FileSystemURL& url,
109 const base::Closure& done_callback) { 108 const base::Closure& done_callback) {
110 // This is initially called on UI thread and to be relayed to FILE thread. 109 // This is initially called on UI thread and to be relayed to FILE thread.
111 DCHECK(file_system_context); 110 DCHECK(file_system_context);
112 if (!file_system_context->task_runners()->file_task_runner()-> 111 if (!file_system_context->default_file_task_runner()->
113 RunsTasksOnCurrentThread()) { 112 RunsTasksOnCurrentThread()) {
114 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 113 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
115 file_system_context->task_runners()->file_task_runner()->PostTask( 114 file_system_context->default_file_task_runner()->PostTask(
116 FROM_HERE, 115 FROM_HERE,
117 base::Bind(&LocalFileSyncContext::ClearChangesForURL, 116 base::Bind(&LocalFileSyncContext::ClearChangesForURL,
118 this, make_scoped_refptr(file_system_context), 117 this, make_scoped_refptr(file_system_context),
119 url, done_callback)); 118 url, done_callback));
120 return; 119 return;
121 } 120 }
122 121
123 SyncFileSystemBackend* backend = 122 SyncFileSystemBackend* backend =
124 SyncFileSystemBackend::GetBackend(file_system_context); 123 SyncFileSystemBackend::GetBackend(file_system_context);
125 DCHECK(backend); 124 DCHECK(backend);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 } 288 }
290 } 289 }
291 290
292 void LocalFileSyncContext::RecordFakeLocalChange( 291 void LocalFileSyncContext::RecordFakeLocalChange(
293 FileSystemContext* file_system_context, 292 FileSystemContext* file_system_context,
294 const FileSystemURL& url, 293 const FileSystemURL& url,
295 const FileChange& change, 294 const FileChange& change,
296 const SyncStatusCallback& callback) { 295 const SyncStatusCallback& callback) {
297 // This is called on UI thread and to be relayed to FILE thread. 296 // This is called on UI thread and to be relayed to FILE thread.
298 DCHECK(file_system_context); 297 DCHECK(file_system_context);
299 if (!file_system_context->task_runners()->file_task_runner()-> 298 if (!file_system_context->default_file_task_runner()->
300 RunsTasksOnCurrentThread()) { 299 RunsTasksOnCurrentThread()) {
301 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 300 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
302 file_system_context->task_runners()->file_task_runner()->PostTask( 301 file_system_context->default_file_task_runner()->PostTask(
303 FROM_HERE, 302 FROM_HERE,
304 base::Bind(&LocalFileSyncContext::RecordFakeLocalChange, 303 base::Bind(&LocalFileSyncContext::RecordFakeLocalChange,
305 this, make_scoped_refptr(file_system_context), 304 this, make_scoped_refptr(file_system_context),
306 url, change, callback)); 305 url, change, callback));
307 return; 306 return;
308 } 307 }
309 308
310 SyncFileSystemBackend* backend = 309 SyncFileSystemBackend* backend =
311 SyncFileSystemBackend::GetBackend(file_system_context); 310 SyncFileSystemBackend::GetBackend(file_system_context);
312 DCHECK(backend); 311 DCHECK(backend);
(...skipping 28 matching lines...) Expand all
341 url_for_sync, base::Bind(&LocalFileSyncContext::DidGetFileMetadata, 340 url_for_sync, base::Bind(&LocalFileSyncContext::DidGetFileMetadata,
342 this, callback)); 341 this, callback));
343 } 342 }
344 343
345 void LocalFileSyncContext::HasPendingLocalChanges( 344 void LocalFileSyncContext::HasPendingLocalChanges(
346 FileSystemContext* file_system_context, 345 FileSystemContext* file_system_context,
347 const FileSystemURL& url, 346 const FileSystemURL& url,
348 const HasPendingLocalChangeCallback& callback) { 347 const HasPendingLocalChangeCallback& callback) {
349 // This gets called on UI thread and relays the task on FILE thread. 348 // This gets called on UI thread and relays the task on FILE thread.
350 DCHECK(file_system_context); 349 DCHECK(file_system_context);
351 if (!file_system_context->task_runners()->file_task_runner()-> 350 if (!file_system_context->default_file_task_runner()->
352 RunsTasksOnCurrentThread()) { 351 RunsTasksOnCurrentThread()) {
353 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 352 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
354 file_system_context->task_runners()->file_task_runner()->PostTask( 353 file_system_context->default_file_task_runner()->PostTask(
355 FROM_HERE, 354 FROM_HERE,
356 base::Bind(&LocalFileSyncContext::HasPendingLocalChanges, 355 base::Bind(&LocalFileSyncContext::HasPendingLocalChanges,
357 this, make_scoped_refptr(file_system_context), 356 this, make_scoped_refptr(file_system_context),
358 url, callback)); 357 url, callback));
359 return; 358 return;
360 } 359 }
361 360
362 SyncFileSystemBackend* backend = 361 SyncFileSystemBackend* backend =
363 SyncFileSystemBackend::GetBackend(file_system_context); 362 SyncFileSystemBackend::GetBackend(file_system_context);
364 DCHECK(backend); 363 DCHECK(backend);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 DCHECK(backend); 460 DCHECK(backend);
462 if (!backend->change_tracker()) { 461 if (!backend->change_tracker()) {
463 // First registers the service name. 462 // First registers the service name.
464 RegisterSyncableFileSystem(); 463 RegisterSyncableFileSystem();
465 // Create and initialize LocalFileChangeTracker and call back this method 464 // Create and initialize LocalFileChangeTracker and call back this method
466 // later again. 465 // later again.
467 std::set<GURL>* origins_with_changes = new std::set<GURL>; 466 std::set<GURL>* origins_with_changes = new std::set<GURL>;
468 scoped_ptr<LocalFileChangeTracker>* tracker_ptr( 467 scoped_ptr<LocalFileChangeTracker>* tracker_ptr(
469 new scoped_ptr<LocalFileChangeTracker>); 468 new scoped_ptr<LocalFileChangeTracker>);
470 base::PostTaskAndReplyWithResult( 469 base::PostTaskAndReplyWithResult(
471 file_system_context->task_runners()->file_task_runner(), 470 file_system_context->default_file_task_runner(),
472 FROM_HERE, 471 FROM_HERE,
473 base::Bind(&LocalFileSyncContext::InitializeChangeTrackerOnFileThread, 472 base::Bind(&LocalFileSyncContext::InitializeChangeTrackerOnFileThread,
474 this, tracker_ptr, 473 this, tracker_ptr,
475 make_scoped_refptr(file_system_context), 474 make_scoped_refptr(file_system_context),
476 origins_with_changes), 475 origins_with_changes),
477 base::Bind(&LocalFileSyncContext::DidInitializeChangeTrackerOnIOThread, 476 base::Bind(&LocalFileSyncContext::DidInitializeChangeTrackerOnIOThread,
478 this, base::Owned(tracker_ptr), 477 this, base::Owned(tracker_ptr),
479 source_url, 478 source_url,
480 make_scoped_refptr(file_system_context), 479 make_scoped_refptr(file_system_context),
481 base::Owned(origins_with_changes))); 480 base::Owned(origins_with_changes)));
(...skipping 16 matching lines...) Expand all
498 497
499 SyncStatusCode LocalFileSyncContext::InitializeChangeTrackerOnFileThread( 498 SyncStatusCode LocalFileSyncContext::InitializeChangeTrackerOnFileThread(
500 scoped_ptr<LocalFileChangeTracker>* tracker_ptr, 499 scoped_ptr<LocalFileChangeTracker>* tracker_ptr,
501 FileSystemContext* file_system_context, 500 FileSystemContext* file_system_context,
502 std::set<GURL>* origins_with_changes) { 501 std::set<GURL>* origins_with_changes) {
503 DCHECK(file_system_context); 502 DCHECK(file_system_context);
504 DCHECK(tracker_ptr); 503 DCHECK(tracker_ptr);
505 DCHECK(origins_with_changes); 504 DCHECK(origins_with_changes);
506 tracker_ptr->reset(new LocalFileChangeTracker( 505 tracker_ptr->reset(new LocalFileChangeTracker(
507 file_system_context->partition_path(), 506 file_system_context->partition_path(),
508 file_system_context->task_runners()->file_task_runner())); 507 file_system_context->default_file_task_runner()));
509 const SyncStatusCode status = (*tracker_ptr)->Initialize(file_system_context); 508 const SyncStatusCode status = (*tracker_ptr)->Initialize(file_system_context);
510 if (status != SYNC_STATUS_OK) 509 if (status != SYNC_STATUS_OK)
511 return status; 510 return status;
512 511
513 // Get all origins that have pending changes. 512 // Get all origins that have pending changes.
514 std::deque<FileSystemURL> urls; 513 std::deque<FileSystemURL> urls;
515 (*tracker_ptr)->GetNextChangedURLs(&urls, 0); 514 (*tracker_ptr)->GetNextChangedURLs(&urls, 0);
516 for (std::deque<FileSystemURL>::iterator iter = urls.begin(); 515 for (std::deque<FileSystemURL>::iterator iter = urls.begin();
517 iter != urls.end(); ++iter) { 516 iter != urls.end(); ++iter) {
518 origins_with_changes->insert(iter->origin()); 517 origins_with_changes->insert(iter->origin());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 iter != callback_queue.end(); ++iter) { 574 iter != callback_queue.end(); ++iter) {
576 ui_task_runner_->PostTask(FROM_HERE, base::Bind(*iter, status)); 575 ui_task_runner_->PostTask(FROM_HERE, base::Bind(*iter, status));
577 } 576 }
578 pending_initialize_callbacks_.erase(file_system_context); 577 pending_initialize_callbacks_.erase(file_system_context);
579 } 578 }
580 579
581 void LocalFileSyncContext::GetNextURLsForSyncOnFileThread( 580 void LocalFileSyncContext::GetNextURLsForSyncOnFileThread(
582 FileSystemContext* file_system_context, 581 FileSystemContext* file_system_context,
583 std::deque<FileSystemURL>* urls) { 582 std::deque<FileSystemURL>* urls) {
584 DCHECK(file_system_context); 583 DCHECK(file_system_context);
585 DCHECK(file_system_context->task_runners()->file_task_runner()-> 584 DCHECK(file_system_context->default_file_task_runner()->
586 RunsTasksOnCurrentThread()); 585 RunsTasksOnCurrentThread());
587 SyncFileSystemBackend* backend = 586 SyncFileSystemBackend* backend =
588 SyncFileSystemBackend::GetBackend(file_system_context); 587 SyncFileSystemBackend::GetBackend(file_system_context);
589 DCHECK(backend); 588 DCHECK(backend);
590 DCHECK(backend->change_tracker()); 589 DCHECK(backend->change_tracker());
591 backend->change_tracker()->GetNextChangedURLs( 590 backend->change_tracker()->GetNextChangedURLs(
592 urls, kMaxURLsToFetchForLocalSync); 591 urls, kMaxURLsToFetchForLocalSync);
593 } 592 }
594 593
595 void LocalFileSyncContext::TryPrepareForLocalSync( 594 void LocalFileSyncContext::TryPrepareForLocalSync(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 TryPrepareForLocalSync(file_system_context, remaining_urls, callback); 636 TryPrepareForLocalSync(file_system_context, remaining_urls, callback);
638 } 637 }
639 638
640 void LocalFileSyncContext::DidGetWritingStatusForSync( 639 void LocalFileSyncContext::DidGetWritingStatusForSync(
641 FileSystemContext* file_system_context, 640 FileSystemContext* file_system_context,
642 SyncStatusCode status, 641 SyncStatusCode status,
643 const FileSystemURL& url, 642 const FileSystemURL& url,
644 const LocalFileSyncInfoCallback& callback) { 643 const LocalFileSyncInfoCallback& callback) {
645 // This gets called on UI thread and relays the task on FILE thread. 644 // This gets called on UI thread and relays the task on FILE thread.
646 DCHECK(file_system_context); 645 DCHECK(file_system_context);
647 if (!file_system_context->task_runners()->file_task_runner()-> 646 if (!file_system_context->default_file_task_runner()->
648 RunsTasksOnCurrentThread()) { 647 RunsTasksOnCurrentThread()) {
649 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 648 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
650 if (shutdown_on_ui_) { 649 if (shutdown_on_ui_) {
651 callback.Run(SYNC_STATUS_ABORT, LocalFileSyncInfo()); 650 callback.Run(SYNC_STATUS_ABORT, LocalFileSyncInfo());
652 return; 651 return;
653 } 652 }
654 file_system_context->task_runners()->file_task_runner()->PostTask( 653 file_system_context->default_file_task_runner()->PostTask(
655 FROM_HERE, 654 FROM_HERE,
656 base::Bind(&LocalFileSyncContext::DidGetWritingStatusForSync, 655 base::Bind(&LocalFileSyncContext::DidGetWritingStatusForSync,
657 this, make_scoped_refptr(file_system_context), 656 this, make_scoped_refptr(file_system_context),
658 status, url, callback)); 657 status, url, callback));
659 return; 658 return;
660 } 659 }
661 660
662 SyncFileSystemBackend* backend = 661 SyncFileSystemBackend* backend =
663 SyncFileSystemBackend::GetBackend(file_system_context); 662 SyncFileSystemBackend::GetBackend(file_system_context);
664 DCHECK(backend); 663 DCHECK(backend);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 return; 761 return;
763 } 762 }
764 763
765 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( 764 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync(
766 file_system_context, dest_url); 765 file_system_context, dest_url);
767 file_system_context->operation_runner()->CopyInForeignFile( 766 file_system_context->operation_runner()->CopyInForeignFile(
768 local_path, url_for_sync, callback); 767 local_path, url_for_sync, callback);
769 } 768 }
770 769
771 } // namespace sync_file_system 770 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698