Chromium Code Reviews| 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 if (!--*count) | |
|
peria
2014/07/22 07:19:29
nit:
Could you split this "if" statement?
Current
tzik
2014/07/22 07:28:22
Done.
| |
| 47 callback.Run(); | |
| 48 } | |
| 49 | |
| 45 } // namespace | 50 } // namespace |
| 46 | 51 |
| 47 LocalFileSyncService::OriginChangeMap::OriginChangeMap() | 52 LocalFileSyncService::OriginChangeMap::OriginChangeMap() |
| 48 : next_(change_count_map_.end()) {} | 53 : next_(change_count_map_.end()) {} |
| 49 LocalFileSyncService::OriginChangeMap::~OriginChangeMap() {} | 54 LocalFileSyncService::OriginChangeMap::~OriginChangeMap() {} |
| 50 | 55 |
| 51 bool LocalFileSyncService::OriginChangeMap::NextOriginToProcess(GURL* origin) { | 56 bool LocalFileSyncService::OriginChangeMap::NextOriginToProcess(GURL* origin) { |
| 52 DCHECK(origin); | 57 DCHECK(origin); |
| 53 if (change_count_map_.empty()) | 58 if (change_count_map_.empty()) |
| 54 return false; | 59 return false; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 if (!ContainsKey(origin_to_contexts_, url.origin())) { | 184 if (!ContainsKey(origin_to_contexts_, url.origin())) { |
| 180 base::ThreadTaskRunnerHandle::Get()->PostTask( | 185 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 181 FROM_HERE, | 186 FROM_HERE, |
| 182 base::Bind(callback, SYNC_FILE_ERROR_INVALID_URL, false)); | 187 base::Bind(callback, SYNC_FILE_ERROR_INVALID_URL, false)); |
| 183 return; | 188 return; |
| 184 } | 189 } |
| 185 sync_context_->HasPendingLocalChanges( | 190 sync_context_->HasPendingLocalChanges( |
| 186 origin_to_contexts_[url.origin()], url, callback); | 191 origin_to_contexts_[url.origin()], url, callback); |
| 187 } | 192 } |
| 188 | 193 |
| 189 void LocalFileSyncService::PromoteDemotedChanges() { | 194 void LocalFileSyncService::PromoteDemotedChanges( |
| 195 const base::Closure& callback) { | |
| 196 if (origin_to_contexts_.empty()) { | |
| 197 callback.Run(); | |
| 198 return; | |
| 199 } | |
| 200 | |
| 201 base::Closure completion_callback = | |
| 202 base::Bind(&InvokeCallbackOnNthInvocation, | |
| 203 base::Owned(new int(origin_to_contexts_.size())), callback); | |
| 190 for (OriginToContext::iterator iter = origin_to_contexts_.begin(); | 204 for (OriginToContext::iterator iter = origin_to_contexts_.begin(); |
| 191 iter != origin_to_contexts_.end(); ++iter) | 205 iter != origin_to_contexts_.end(); ++iter) |
| 192 sync_context_->PromoteDemotedChanges(iter->first, iter->second); | 206 sync_context_->PromoteDemotedChanges(iter->first, iter->second, |
| 207 completion_callback); | |
| 193 } | 208 } |
| 194 | 209 |
| 195 void LocalFileSyncService::GetLocalFileMetadata( | 210 void LocalFileSyncService::GetLocalFileMetadata( |
| 196 const FileSystemURL& url, const SyncFileMetadataCallback& callback) { | 211 const FileSystemURL& url, const SyncFileMetadataCallback& callback) { |
| 197 DCHECK(ContainsKey(origin_to_contexts_, url.origin())); | 212 DCHECK(ContainsKey(origin_to_contexts_, url.origin())); |
| 198 sync_context_->GetFileMetadata(origin_to_contexts_[url.origin()], | 213 sync_context_->GetFileMetadata(origin_to_contexts_[url.origin()], |
| 199 url, callback); | 214 url, callback); |
| 200 } | 215 } |
| 201 | 216 |
| 202 void LocalFileSyncService::PrepareForProcessRemoteChange( | 217 void LocalFileSyncService::PrepareForProcessRemoteChange( |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 | 499 |
| 485 LocalChangeProcessor* LocalFileSyncService::GetLocalChangeProcessor( | 500 LocalChangeProcessor* LocalFileSyncService::GetLocalChangeProcessor( |
| 486 const FileSystemURL& url) { | 501 const FileSystemURL& url) { |
| 487 if (!get_local_change_processor_.is_null()) | 502 if (!get_local_change_processor_.is_null()) |
| 488 return get_local_change_processor_.Run(url.origin()); | 503 return get_local_change_processor_.Run(url.origin()); |
| 489 DCHECK(local_change_processor_); | 504 DCHECK(local_change_processor_); |
| 490 return local_change_processor_; | 505 return local_change_processor_; |
| 491 } | 506 } |
| 492 | 507 |
| 493 } // namespace sync_file_system | 508 } // namespace sync_file_system |
| OLD | NEW |