| 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 "sync/engine/all_status.h" | 5 #include "sync/engine/all_status.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/port.h" | 10 #include "base/port.h" |
| 11 #include "sync/engine/net/server_connection_manager.h" | 11 #include "sync/engine/net/server_connection_manager.h" |
| 12 #include "sync/internal_api/public/syncable/model_type.h" | 12 #include "sync/internal_api/public/syncable/model_type.h" |
| 13 #include "sync/sessions/session_state.h" | 13 #include "sync/sessions/session_state.h" |
| 14 | 14 |
| 15 namespace csync { | 15 namespace syncer { |
| 16 | 16 |
| 17 AllStatus::AllStatus() { | 17 AllStatus::AllStatus() { |
| 18 status_.initial_sync_ended = true; | 18 status_.initial_sync_ended = true; |
| 19 status_.notifications_enabled = false; | 19 status_.notifications_enabled = false; |
| 20 status_.cryptographer_ready = false; | 20 status_.cryptographer_ready = false; |
| 21 status_.crypto_has_pending_keys = false; | 21 status_.crypto_has_pending_keys = false; |
| 22 } | 22 } |
| 23 | 23 |
| 24 AllStatus::~AllStatus() { | 24 AllStatus::~AllStatus() { |
| 25 } | 25 } |
| 26 | 26 |
| 27 csync::SyncStatus AllStatus::CreateBlankStatus() const { | 27 syncer::SyncStatus AllStatus::CreateBlankStatus() const { |
| 28 // Status is initialized with the previous status value. Variables | 28 // Status is initialized with the previous status value. Variables |
| 29 // whose values accumulate (e.g. lifetime counters like updates_received) | 29 // whose values accumulate (e.g. lifetime counters like updates_received) |
| 30 // are not to be cleared here. | 30 // are not to be cleared here. |
| 31 csync::SyncStatus status = status_; | 31 syncer::SyncStatus status = status_; |
| 32 status.encryption_conflicts = 0; | 32 status.encryption_conflicts = 0; |
| 33 status.hierarchy_conflicts = 0; | 33 status.hierarchy_conflicts = 0; |
| 34 status.simple_conflicts = 0; | 34 status.simple_conflicts = 0; |
| 35 status.server_conflicts = 0; | 35 status.server_conflicts = 0; |
| 36 status.committed_count = 0; | 36 status.committed_count = 0; |
| 37 status.initial_sync_ended = false; | 37 status.initial_sync_ended = false; |
| 38 status.updates_available = 0; | 38 status.updates_available = 0; |
| 39 return status; | 39 return status; |
| 40 } | 40 } |
| 41 | 41 |
| 42 csync::SyncStatus AllStatus::CalcSyncing( | 42 syncer::SyncStatus AllStatus::CalcSyncing( |
| 43 const SyncEngineEvent &event) const { | 43 const SyncEngineEvent &event) const { |
| 44 csync::SyncStatus status = CreateBlankStatus(); | 44 syncer::SyncStatus status = CreateBlankStatus(); |
| 45 const sessions::SyncSessionSnapshot& snapshot = event.snapshot; | 45 const sessions::SyncSessionSnapshot& snapshot = event.snapshot; |
| 46 status.encryption_conflicts = snapshot.num_encryption_conflicts(); | 46 status.encryption_conflicts = snapshot.num_encryption_conflicts(); |
| 47 status.hierarchy_conflicts = snapshot.num_hierarchy_conflicts(); | 47 status.hierarchy_conflicts = snapshot.num_hierarchy_conflicts(); |
| 48 status.simple_conflicts = snapshot.num_simple_conflicts(); | 48 status.simple_conflicts = snapshot.num_simple_conflicts(); |
| 49 status.server_conflicts = snapshot.num_server_conflicts(); | 49 status.server_conflicts = snapshot.num_server_conflicts(); |
| 50 status.committed_count = | 50 status.committed_count = |
| 51 snapshot.model_neutral_state().num_successful_commits; | 51 snapshot.model_neutral_state().num_successful_commits; |
| 52 | 52 |
| 53 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_BEGIN) { | 53 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_BEGIN) { |
| 54 status.syncing = true; | 54 status.syncing = true; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 status_ = CreateBlankStatus(); | 113 status_ = CreateBlankStatus(); |
| 114 status_.sync_protocol_error = | 114 status_.sync_protocol_error = |
| 115 event.snapshot.model_neutral_state().sync_protocol_error; | 115 event.snapshot.model_neutral_state().sync_protocol_error; |
| 116 break; | 116 break; |
| 117 default: | 117 default: |
| 118 LOG(ERROR) << "Unrecognized Syncer Event: " << event.what_happened; | 118 LOG(ERROR) << "Unrecognized Syncer Event: " << event.what_happened; |
| 119 break; | 119 break; |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 | 122 |
| 123 csync::SyncStatus AllStatus::status() const { | 123 syncer::SyncStatus AllStatus::status() const { |
| 124 base::AutoLock lock(mutex_); | 124 base::AutoLock lock(mutex_); |
| 125 return status_; | 125 return status_; |
| 126 } | 126 } |
| 127 | 127 |
| 128 void AllStatus::SetNotificationsEnabled(bool notifications_enabled) { | 128 void AllStatus::SetNotificationsEnabled(bool notifications_enabled) { |
| 129 ScopedStatusLock lock(this); | 129 ScopedStatusLock lock(this); |
| 130 status_.notifications_enabled = notifications_enabled; | 130 status_.notifications_enabled = notifications_enabled; |
| 131 } | 131 } |
| 132 | 132 |
| 133 void AllStatus::IncrementNotificationsReceived() { | 133 void AllStatus::IncrementNotificationsReceived() { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 162 | 162 |
| 163 ScopedStatusLock::ScopedStatusLock(AllStatus* allstatus) | 163 ScopedStatusLock::ScopedStatusLock(AllStatus* allstatus) |
| 164 : allstatus_(allstatus) { | 164 : allstatus_(allstatus) { |
| 165 allstatus->mutex_.Acquire(); | 165 allstatus->mutex_.Acquire(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 ScopedStatusLock::~ScopedStatusLock() { | 168 ScopedStatusLock::~ScopedStatusLock() { |
| 169 allstatus_->mutex_.Release(); | 169 allstatus_->mutex_.Release(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 } // namespace csync | 172 } // namespace syncer |
| OLD | NEW |