| OLD | NEW |
| 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 "webkit/fileapi/syncable/local_file_sync_context.h" | 5 #include "webkit/fileapi/syncable/local_file_sync_context.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/location.h" | 9 #include "base/location.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/fileapi/file_system_context.h" | 13 #include "webkit/fileapi/file_system_context.h" |
| 14 #include "webkit/fileapi/file_system_task_runners.h" | 14 #include "webkit/fileapi/file_system_task_runners.h" |
| 15 #include "webkit/fileapi/syncable/local_file_change_tracker.h" | 15 #include "webkit/fileapi/syncable/local_file_change_tracker.h" |
| 16 #include "webkit/fileapi/syncable/syncable_file_operation_runner.h" | 16 #include "webkit/fileapi/syncable/syncable_file_operation_runner.h" |
| 17 | 17 |
| 18 namespace fileapi { | 18 namespace fileapi { |
| 19 | 19 |
| 20 namespace { |
| 21 const int kMaxConcurrentSyncableOperation = 3; |
| 22 } // namespace |
| 23 |
| 20 LocalFileSyncContext::LocalFileSyncContext( | 24 LocalFileSyncContext::LocalFileSyncContext( |
| 21 base::SingleThreadTaskRunner* ui_task_runner, | 25 base::SingleThreadTaskRunner* ui_task_runner, |
| 22 base::SingleThreadTaskRunner* io_task_runner) | 26 base::SingleThreadTaskRunner* io_task_runner) |
| 23 : ui_task_runner_(ui_task_runner), | 27 : ui_task_runner_(ui_task_runner), |
| 24 io_task_runner_(io_task_runner) { | 28 io_task_runner_(io_task_runner) { |
| 25 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 29 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 26 } | 30 } |
| 27 | 31 |
| 28 void LocalFileSyncContext::MaybeInitializeFileSystemContext( | 32 void LocalFileSyncContext::MaybeInitializeFileSystemContext( |
| 29 const GURL& source_url, | 33 const GURL& source_url, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 65 } |
| 62 | 66 |
| 63 base::WeakPtr<SyncableFileOperationRunner> | 67 base::WeakPtr<SyncableFileOperationRunner> |
| 64 LocalFileSyncContext::operation_runner() const { | 68 LocalFileSyncContext::operation_runner() const { |
| 65 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 69 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 66 if (operation_runner_.get()) | 70 if (operation_runner_.get()) |
| 67 return operation_runner_->AsWeakPtr(); | 71 return operation_runner_->AsWeakPtr(); |
| 68 return base::WeakPtr<SyncableFileOperationRunner>(); | 72 return base::WeakPtr<SyncableFileOperationRunner>(); |
| 69 } | 73 } |
| 70 | 74 |
| 75 LocalFileSyncStatus* LocalFileSyncContext::sync_status() const { |
| 76 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 77 return sync_status_.get(); |
| 78 } |
| 79 |
| 71 LocalFileSyncContext::~LocalFileSyncContext() { | 80 LocalFileSyncContext::~LocalFileSyncContext() { |
| 72 } | 81 } |
| 73 | 82 |
| 74 void LocalFileSyncContext::ShutdownOnIOThread() { | 83 void LocalFileSyncContext::ShutdownOnIOThread() { |
| 75 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 84 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 76 operation_runner_.reset(); | 85 operation_runner_.reset(); |
| 86 sync_status_.reset(); |
| 77 } | 87 } |
| 78 | 88 |
| 79 void LocalFileSyncContext::InitializeFileSystemContextOnIOThread( | 89 void LocalFileSyncContext::InitializeFileSystemContextOnIOThread( |
| 80 const GURL& source_url, | 90 const GURL& source_url, |
| 81 FileSystemContext* file_system_context) { | 91 FileSystemContext* file_system_context) { |
| 82 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 92 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 83 DCHECK(file_system_context); | 93 DCHECK(file_system_context); |
| 84 if (!file_system_context->change_tracker()) { | 94 if (!file_system_context->change_tracker()) { |
| 85 // Create and initialize LocalFileChangeTracker and call back this method | 95 // Create and initialize LocalFileChangeTracker and call back this method |
| 86 // later again. | 96 // later again. |
| 87 scoped_ptr<LocalFileChangeTracker>* tracker_ptr( | 97 scoped_ptr<LocalFileChangeTracker>* tracker_ptr( |
| 88 new scoped_ptr<LocalFileChangeTracker>); | 98 new scoped_ptr<LocalFileChangeTracker>); |
| 89 base::PostTaskAndReplyWithResult( | 99 base::PostTaskAndReplyWithResult( |
| 90 file_system_context->task_runners()->file_task_runner(), | 100 file_system_context->task_runners()->file_task_runner(), |
| 91 FROM_HERE, | 101 FROM_HERE, |
| 92 base::Bind(&LocalFileSyncContext::InitializeChangeTrackerOnFileThread, | 102 base::Bind(&LocalFileSyncContext::InitializeChangeTrackerOnFileThread, |
| 93 this, tracker_ptr, | 103 this, tracker_ptr, |
| 94 make_scoped_refptr(file_system_context)), | 104 make_scoped_refptr(file_system_context)), |
| 95 base::Bind(&LocalFileSyncContext::DidInitializeChangeTracker, this, | 105 base::Bind(&LocalFileSyncContext::DidInitializeChangeTracker, this, |
| 96 base::Owned(tracker_ptr), | 106 base::Owned(tracker_ptr), |
| 97 source_url, | 107 source_url, |
| 98 make_scoped_refptr(file_system_context))); | 108 make_scoped_refptr(file_system_context))); |
| 99 return; | 109 return; |
| 100 } | 110 } |
| 101 if (!operation_runner_.get()) | 111 if (!operation_runner_.get()) { |
| 102 operation_runner_.reset(new SyncableFileOperationRunner); | 112 DCHECK(!sync_status_.get()); |
| 113 sync_status_.reset(new LocalFileSyncStatus); |
| 114 operation_runner_.reset(new SyncableFileOperationRunner( |
| 115 kMaxConcurrentSyncableOperation, |
| 116 sync_status_.get())); |
| 117 } |
| 103 file_system_context->set_sync_context(this); | 118 file_system_context->set_sync_context(this); |
| 104 DidInitialize(source_url, file_system_context, SYNC_STATUS_OK); | 119 DidInitialize(source_url, file_system_context, SYNC_STATUS_OK); |
| 105 } | 120 } |
| 106 | 121 |
| 107 SyncStatusCode LocalFileSyncContext::InitializeChangeTrackerOnFileThread( | 122 SyncStatusCode LocalFileSyncContext::InitializeChangeTrackerOnFileThread( |
| 108 scoped_ptr<LocalFileChangeTracker>* tracker_ptr, | 123 scoped_ptr<LocalFileChangeTracker>* tracker_ptr, |
| 109 FileSystemContext* file_system_context) { | 124 FileSystemContext* file_system_context) { |
| 110 DCHECK(file_system_context); | 125 DCHECK(file_system_context); |
| 111 DCHECK(tracker_ptr); | 126 DCHECK(tracker_ptr); |
| 112 tracker_ptr->reset(new LocalFileChangeTracker( | 127 tracker_ptr->reset(new LocalFileChangeTracker( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 StatusCallbackQueue& callback_queue = | 169 StatusCallbackQueue& callback_queue = |
| 155 pending_initialize_callbacks_[file_system_context]; | 170 pending_initialize_callbacks_[file_system_context]; |
| 156 for (StatusCallbackQueue::iterator iter = callback_queue.begin(); | 171 for (StatusCallbackQueue::iterator iter = callback_queue.begin(); |
| 157 iter != callback_queue.end(); ++iter) { | 172 iter != callback_queue.end(); ++iter) { |
| 158 ui_task_runner_->PostTask(FROM_HERE, base::Bind(*iter, status)); | 173 ui_task_runner_->PostTask(FROM_HERE, base::Bind(*iter, status)); |
| 159 } | 174 } |
| 160 pending_initialize_callbacks_.erase(file_system_context); | 175 pending_initialize_callbacks_.erase(file_system_context); |
| 161 } | 176 } |
| 162 | 177 |
| 163 } // namespace fileapi | 178 } // namespace fileapi |
| OLD | NEW |