Add a nacl module args file.
[chromium-blink-merge.git] / sync / engine / all_status.cc
blob36fb23ef3dddda2e7a544855f8f2a7e351635d7f
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
3 // found in the LICENSE file.
5 #include "sync/engine/all_status.h"
7 #include <algorithm>
9 #include "base/logging.h"
10 #include "sync/engine/net/server_connection_manager.h"
11 #include "sync/engine/sync_cycle_event.h"
12 #include "sync/internal_api/public/base/model_type.h"
14 namespace syncer {
16 AllStatus::AllStatus() {
17 status_.notifications_enabled = false;
18 status_.cryptographer_ready = false;
19 status_.crypto_has_pending_keys = false;
22 AllStatus::~AllStatus() {
25 SyncStatus AllStatus::CreateBlankStatus() const {
26 // Status is initialized with the previous status value. Variables
27 // whose values accumulate (e.g. lifetime counters like updates_received)
28 // are not to be cleared here.
29 SyncStatus status = status_;
30 status.encryption_conflicts = 0;
31 status.hierarchy_conflicts = 0;
32 status.server_conflicts = 0;
33 status.committed_count = 0;
34 return status;
37 SyncStatus AllStatus::CalcSyncing(const SyncCycleEvent &event) const {
38 SyncStatus status = CreateBlankStatus();
39 const sessions::SyncSessionSnapshot& snapshot = event.snapshot;
40 status.encryption_conflicts = snapshot.num_encryption_conflicts();
41 status.hierarchy_conflicts = snapshot.num_hierarchy_conflicts();
42 status.server_conflicts = snapshot.num_server_conflicts();
43 status.committed_count =
44 snapshot.model_neutral_state().num_successful_commits;
46 if (event.what_happened == SyncCycleEvent::SYNC_CYCLE_BEGIN) {
47 status.syncing = true;
48 } else if (event.what_happened == SyncCycleEvent::SYNC_CYCLE_ENDED) {
49 status.syncing = false;
52 status.num_entries_by_type = snapshot.num_entries_by_type();
53 status.num_to_delete_entries_by_type =
54 snapshot.num_to_delete_entries_by_type();
56 // Accumulate update count only once per session to avoid double-counting.
57 if (event.what_happened == SyncCycleEvent::SYNC_CYCLE_ENDED) {
58 status.updates_received +=
59 snapshot.model_neutral_state().num_updates_downloaded_total;
60 status.tombstone_updates_received +=
61 snapshot.model_neutral_state().num_tombstone_updates_downloaded_total;
62 status.reflected_updates_received +=
63 snapshot.model_neutral_state().num_reflected_updates_downloaded_total;
64 status.num_commits_total +=
65 snapshot.model_neutral_state().num_successful_commits;
66 status.num_local_overwrites_total +=
67 snapshot.model_neutral_state().num_local_overwrites;
68 status.num_server_overwrites_total +=
69 snapshot.model_neutral_state().num_server_overwrites;
71 return status;
74 void AllStatus::OnSyncCycleEvent(const SyncCycleEvent& event) {
75 ScopedStatusLock lock(this);
76 switch (event.what_happened) {
77 case SyncCycleEvent::SYNC_CYCLE_BEGIN:
78 case SyncCycleEvent::STATUS_CHANGED:
79 case SyncCycleEvent::SYNC_CYCLE_ENDED:
80 status_ = CalcSyncing(event);
81 break;
82 default:
83 LOG(ERROR) << "Unrecognized Syncer Event: " << event.what_happened;
84 break;
88 void AllStatus::OnActionableError(
89 const SyncProtocolError& sync_protocol_error) {
90 ScopedStatusLock lock(this);
91 status_ = CreateBlankStatus();
92 status_.sync_protocol_error = sync_protocol_error;
95 void AllStatus::OnRetryTimeChanged(base::Time retry_time) {
96 ScopedStatusLock lock(this);
97 status_.retry_time = retry_time;
100 void AllStatus::OnThrottledTypesChanged(ModelTypeSet throttled_types) {
101 ScopedStatusLock lock(this);
102 status_.throttled_types = throttled_types;
105 void AllStatus::OnMigrationRequested(ModelTypeSet) {}
107 void AllStatus::OnProtocolEvent(const ProtocolEvent&) {}
109 SyncStatus AllStatus::status() const {
110 base::AutoLock lock(mutex_);
111 return status_;
114 void AllStatus::SetNotificationsEnabled(bool notifications_enabled) {
115 ScopedStatusLock lock(this);
116 status_.notifications_enabled = notifications_enabled;
119 void AllStatus::IncrementNotificationsReceived() {
120 ScopedStatusLock lock(this);
121 ++status_.notifications_received;
124 void AllStatus::SetEncryptedTypes(ModelTypeSet types) {
125 ScopedStatusLock lock(this);
126 status_.encrypted_types = types;
129 void AllStatus::SetCryptographerReady(bool ready) {
130 ScopedStatusLock lock(this);
131 status_.cryptographer_ready = ready;
134 void AllStatus::SetCryptoHasPendingKeys(bool has_pending_keys) {
135 ScopedStatusLock lock(this);
136 status_.crypto_has_pending_keys = has_pending_keys;
139 void AllStatus::SetPassphraseType(PassphraseType type) {
140 ScopedStatusLock lock(this);
141 status_.passphrase_type = type;
144 void AllStatus::SetHasKeystoreKey(bool has_keystore_key) {
145 ScopedStatusLock lock(this);
146 status_.has_keystore_key = has_keystore_key;
149 void AllStatus::SetKeystoreMigrationTime(const base::Time& migration_time) {
150 ScopedStatusLock lock(this);
151 status_.keystore_migration_time = migration_time;
154 void AllStatus::SetSyncId(const std::string& sync_id) {
155 ScopedStatusLock lock(this);
156 status_.sync_id = sync_id;
159 void AllStatus::SetInvalidatorClientId(
160 const std::string& invalidator_client_id) {
161 ScopedStatusLock lock(this);
162 status_.invalidator_client_id = invalidator_client_id;
165 void AllStatus::IncrementNudgeCounter(NudgeSource source) {
166 ScopedStatusLock lock(this);
167 switch(source) {
168 case NUDGE_SOURCE_LOCAL_REFRESH:
169 status_.nudge_source_local_refresh++;
170 return;
171 case NUDGE_SOURCE_LOCAL:
172 status_.nudge_source_local++;
173 return;
174 case NUDGE_SOURCE_NOTIFICATION:
175 status_.nudge_source_notification++;
176 return;
177 case NUDGE_SOURCE_UNKNOWN:
178 break;
180 // If we're here, the source is most likely
181 // NUDGE_SOURCE_UNKNOWN. That shouldn't happen.
182 NOTREACHED();
185 ScopedStatusLock::ScopedStatusLock(AllStatus* allstatus)
186 : allstatus_(allstatus) {
187 allstatus->mutex_.Acquire();
190 ScopedStatusLock::~ScopedStatusLock() {
191 allstatus_->mutex_.Release();
194 } // namespace syncer