OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/sessions/sync_session.h" | 5 #include "chrome/browser/sync/sessions/sync_session.h" |
6 #include "chrome/browser/sync/syncable/directory_manager.h" | 6 #include "chrome/browser/sync/syncable/directory_manager.h" |
7 #include "chrome/browser/sync/syncable/model_type.h" | 7 #include "chrome/browser/sync/syncable/model_type.h" |
8 | 8 |
9 namespace browser_sync { | 9 namespace browser_sync { |
10 namespace sessions { | 10 namespace sessions { |
11 | 11 |
12 SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate, | 12 SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate, |
13 SyncSourceInfo source, | 13 SyncSourceInfo source, |
14 const ModelSafeRoutingInfo& routing_info, | 14 const ModelSafeRoutingInfo& routing_info, |
15 const std::vector<ModelSafeWorker*>& workers) : | 15 const std::vector<ModelSafeWorker*>& workers) |
16 context_(context), | 16 : context_(context), |
17 source_(source), | 17 source_(source), |
18 write_transaction_(NULL), | 18 write_transaction_(NULL), |
19 delegate_(delegate), | 19 delegate_(delegate), |
20 workers_(workers), | 20 workers_(workers), |
21 routing_info_(routing_info) { | 21 routing_info_(routing_info) { |
22 status_controller_.reset(new StatusController(routing_info_)); | 22 status_controller_.reset(new StatusController(routing_info_)); |
23 } | 23 } |
24 | 24 |
25 SyncSession::~SyncSession() {} | 25 SyncSession::~SyncSession() {} |
26 | 26 |
27 SyncSessionSnapshot SyncSession::TakeSnapshot() const { | 27 SyncSessionSnapshot SyncSession::TakeSnapshot() const { |
28 syncable::ScopedDirLookup dir(context_->directory_manager(), | 28 syncable::ScopedDirLookup dir(context_->directory_manager(), |
29 context_->account_name()); | 29 context_->account_name()); |
30 if (!dir.good()) | 30 if (!dir.good()) |
31 LOG(ERROR) << "Scoped dir lookup failed!"; | 31 LOG(ERROR) << "Scoped dir lookup failed!"; |
32 | 32 |
33 bool is_share_useable = true; | 33 bool is_share_useable = true; |
34 syncable::ModelTypeBitSet initial_sync_ended; | 34 syncable::ModelTypeBitSet initial_sync_ended; |
| 35 std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; |
35 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { | 36 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { |
36 syncable::ModelType type(syncable::ModelTypeFromInt(i)); | 37 syncable::ModelType type(syncable::ModelTypeFromInt(i)); |
37 if (routing_info_.count(type) != 0) { | 38 if (routing_info_.count(type) != 0) { |
38 if (dir->initial_sync_ended_for_type(type)) | 39 if (dir->initial_sync_ended_for_type(type)) |
39 initial_sync_ended.set(type); | 40 initial_sync_ended.set(type); |
40 else | 41 else |
41 is_share_useable = false; | 42 is_share_useable = false; |
| 43 dir->GetDownloadProgressAsString(type, &download_progress_markers[i]); |
42 } | 44 } |
43 } | 45 } |
44 | 46 |
45 return SyncSessionSnapshot( | 47 return SyncSessionSnapshot( |
46 status_controller_->syncer_status(), | 48 status_controller_->syncer_status(), |
47 status_controller_->error_counters(), | 49 status_controller_->error_counters(), |
48 status_controller_->num_server_changes_remaining(), | 50 status_controller_->num_server_changes_remaining(), |
49 status_controller_->ComputeMaxLocalTimestamp(), | |
50 is_share_useable, | 51 is_share_useable, |
51 initial_sync_ended, | 52 initial_sync_ended, |
| 53 download_progress_markers, |
52 HasMoreToSync(), | 54 HasMoreToSync(), |
53 delegate_->IsSyncingCurrentlySilenced(), | 55 delegate_->IsSyncingCurrentlySilenced(), |
54 status_controller_->unsynced_handles().size(), | 56 status_controller_->unsynced_handles().size(), |
55 status_controller_->TotalNumConflictingItems(), | 57 status_controller_->TotalNumConflictingItems(), |
56 status_controller_->did_commit_items()); | 58 status_controller_->did_commit_items()); |
57 } | 59 } |
58 | 60 |
59 SyncSourceInfo SyncSession::TestAndSetSource() { | 61 SyncSourceInfo SyncSession::TestAndSetSource() { |
60 SyncSourceInfo old_source = source_; | 62 SyncSourceInfo old_source = source_; |
61 source_ = SyncSourceInfo( | 63 source_ = SyncSourceInfo( |
62 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, | 64 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, |
63 source_.second); | 65 source_.second); |
64 return old_source; | 66 return old_source; |
65 } | 67 } |
66 | 68 |
67 bool SyncSession::HasMoreToSync() const { | 69 bool SyncSession::HasMoreToSync() const { |
68 const StatusController* status = status_controller_.get(); | 70 const StatusController* status = status_controller_.get(); |
69 return ((status->commit_ids().size() < status->unsynced_handles().size()) && | 71 return ((status->commit_ids().size() < status->unsynced_handles().size()) && |
70 status->syncer_status().num_successful_commits > 0) || | 72 status->syncer_status().num_successful_commits > 0) || |
71 status->conflict_sets_built() || | 73 status->conflict_sets_built() || |
72 status->conflicts_resolved(); | 74 status->conflicts_resolved(); |
73 // Or, we have conflicting updates, but we're making progress on | 75 // Or, we have conflicting updates, but we're making progress on |
74 // resolving them... | 76 // resolving them... |
75 } | 77 } |
76 | 78 |
77 } // namespace sessions | 79 } // namespace sessions |
78 } // namespace browser_sync | 80 } // namespace browser_sync |
OLD | NEW |