OLD | NEW |
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 "chrome/browser/sync_file_system/local/local_file_sync_service.h" | 5 #include "chrome/browser/sync_file_system/local/local_file_sync_service.h" |
6 | 6 |
7 #include "base/single_thread_task_runner.h" | 7 #include "base/single_thread_task_runner.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
10 #include "chrome/browser/extensions/extension_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 namespace { | 35 namespace { |
36 | 36 |
37 void PrepareForProcessRemoteChangeCallbackAdapter( | 37 void PrepareForProcessRemoteChangeCallbackAdapter( |
38 const RemoteChangeProcessor::PrepareChangeCallback& callback, | 38 const RemoteChangeProcessor::PrepareChangeCallback& callback, |
39 SyncStatusCode status, | 39 SyncStatusCode status, |
40 const LocalFileSyncInfo& sync_file_info, | 40 const LocalFileSyncInfo& sync_file_info, |
41 webkit_blob::ScopedFile snapshot) { | 41 webkit_blob::ScopedFile snapshot) { |
42 callback.Run(status, sync_file_info.metadata, sync_file_info.changes); | 42 callback.Run(status, sync_file_info.metadata, sync_file_info.changes); |
43 } | 43 } |
44 | 44 |
| 45 void InvokeCallbackOnNthInvocation(int* count, const base::Closure& callback) { |
| 46 --*count; |
| 47 if (*count <= 0) |
| 48 callback.Run(); |
| 49 } |
| 50 |
45 } // namespace | 51 } // namespace |
46 | 52 |
47 LocalFileSyncService::OriginChangeMap::OriginChangeMap() | 53 LocalFileSyncService::OriginChangeMap::OriginChangeMap() |
48 : next_(change_count_map_.end()) {} | 54 : next_(change_count_map_.end()) {} |
49 LocalFileSyncService::OriginChangeMap::~OriginChangeMap() {} | 55 LocalFileSyncService::OriginChangeMap::~OriginChangeMap() {} |
50 | 56 |
51 bool LocalFileSyncService::OriginChangeMap::NextOriginToProcess(GURL* origin) { | 57 bool LocalFileSyncService::OriginChangeMap::NextOriginToProcess(GURL* origin) { |
52 DCHECK(origin); | 58 DCHECK(origin); |
53 if (change_count_map_.empty()) | 59 if (change_count_map_.empty()) |
54 return false; | 60 return false; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 if (!ContainsKey(origin_to_contexts_, url.origin())) { | 185 if (!ContainsKey(origin_to_contexts_, url.origin())) { |
180 base::ThreadTaskRunnerHandle::Get()->PostTask( | 186 base::ThreadTaskRunnerHandle::Get()->PostTask( |
181 FROM_HERE, | 187 FROM_HERE, |
182 base::Bind(callback, SYNC_FILE_ERROR_INVALID_URL, false)); | 188 base::Bind(callback, SYNC_FILE_ERROR_INVALID_URL, false)); |
183 return; | 189 return; |
184 } | 190 } |
185 sync_context_->HasPendingLocalChanges( | 191 sync_context_->HasPendingLocalChanges( |
186 origin_to_contexts_[url.origin()], url, callback); | 192 origin_to_contexts_[url.origin()], url, callback); |
187 } | 193 } |
188 | 194 |
189 void LocalFileSyncService::PromoteDemotedChanges() { | 195 void LocalFileSyncService::PromoteDemotedChanges( |
| 196 const base::Closure& callback) { |
| 197 if (origin_to_contexts_.empty()) { |
| 198 callback.Run(); |
| 199 return; |
| 200 } |
| 201 |
| 202 base::Closure completion_callback = |
| 203 base::Bind(&InvokeCallbackOnNthInvocation, |
| 204 base::Owned(new int(origin_to_contexts_.size())), callback); |
190 for (OriginToContext::iterator iter = origin_to_contexts_.begin(); | 205 for (OriginToContext::iterator iter = origin_to_contexts_.begin(); |
191 iter != origin_to_contexts_.end(); ++iter) | 206 iter != origin_to_contexts_.end(); ++iter) |
192 sync_context_->PromoteDemotedChanges(iter->first, iter->second); | 207 sync_context_->PromoteDemotedChanges(iter->first, iter->second, |
| 208 completion_callback); |
193 } | 209 } |
194 | 210 |
195 void LocalFileSyncService::GetLocalFileMetadata( | 211 void LocalFileSyncService::GetLocalFileMetadata( |
196 const FileSystemURL& url, const SyncFileMetadataCallback& callback) { | 212 const FileSystemURL& url, const SyncFileMetadataCallback& callback) { |
197 DCHECK(ContainsKey(origin_to_contexts_, url.origin())); | 213 DCHECK(ContainsKey(origin_to_contexts_, url.origin())); |
198 sync_context_->GetFileMetadata(origin_to_contexts_[url.origin()], | 214 sync_context_->GetFileMetadata(origin_to_contexts_[url.origin()], |
199 url, callback); | 215 url, callback); |
200 } | 216 } |
201 | 217 |
202 void LocalFileSyncService::PrepareForProcessRemoteChange( | 218 void LocalFileSyncService::PrepareForProcessRemoteChange( |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 | 500 |
485 LocalChangeProcessor* LocalFileSyncService::GetLocalChangeProcessor( | 501 LocalChangeProcessor* LocalFileSyncService::GetLocalChangeProcessor( |
486 const FileSystemURL& url) { | 502 const FileSystemURL& url) { |
487 if (!get_local_change_processor_.is_null()) | 503 if (!get_local_change_processor_.is_null()) |
488 return get_local_change_processor_.Run(url.origin()); | 504 return get_local_change_processor_.Run(url.origin()); |
489 DCHECK(local_change_processor_); | 505 DCHECK(local_change_processor_); |
490 return local_change_processor_; | 506 return local_change_processor_; |
491 } | 507 } |
492 | 508 |
493 } // namespace sync_file_system | 509 } // namespace sync_file_system |
OLD | NEW |