Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(530)

Side by Side Diff: sync/internal_api/all_status.cc

Issue 10197004: [Sync] Convert SyncSessionSnapshot to a copy-able class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/internal_api/all_status.h ('k') | sync/internal_api/debug_info_event_listener.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/internal_api/all_status.h" 5 #include "sync/internal_api/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"
(...skipping 26 matching lines...) Expand all
37 status.server_conflicts = 0; 37 status.server_conflicts = 0;
38 status.committed_count = 0; 38 status.committed_count = 0;
39 status.initial_sync_ended = false; 39 status.initial_sync_ended = false;
40 status.updates_available = 0; 40 status.updates_available = 0;
41 return status; 41 return status;
42 } 42 }
43 43
44 sync_api::SyncManager::Status AllStatus::CalcSyncing( 44 sync_api::SyncManager::Status AllStatus::CalcSyncing(
45 const SyncEngineEvent &event) const { 45 const SyncEngineEvent &event) const {
46 sync_api::SyncManager::Status status = CreateBlankStatus(); 46 sync_api::SyncManager::Status status = CreateBlankStatus();
47 const sessions::SyncSessionSnapshot* snapshot = event.snapshot; 47 const sessions::SyncSessionSnapshot& snapshot = event.snapshot;
48 status.unsynced_count = static_cast<int>(snapshot->unsynced_count); 48 status.unsynced_count = static_cast<int>(snapshot.unsynced_count());
49 status.encryption_conflicts = snapshot->num_encryption_conflicts; 49 status.encryption_conflicts = snapshot.num_encryption_conflicts();
50 status.hierarchy_conflicts = snapshot->num_hierarchy_conflicts; 50 status.hierarchy_conflicts = snapshot.num_hierarchy_conflicts();
51 status.simple_conflicts = snapshot->num_simple_conflicts; 51 status.simple_conflicts = snapshot.num_simple_conflicts();
52 status.server_conflicts = snapshot->num_server_conflicts; 52 status.server_conflicts = snapshot.num_server_conflicts();
53 status.committed_count = snapshot->syncer_status.num_successful_commits; 53 status.committed_count = snapshot.syncer_status().num_successful_commits;
54 54
55 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_BEGIN) { 55 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_BEGIN) {
56 status.syncing = true; 56 status.syncing = true;
57 } else if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { 57 } else if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) {
58 status.syncing = false; 58 status.syncing = false;
59 } 59 }
60 60
61 status.initial_sync_ended |= snapshot->is_share_usable; 61 status.initial_sync_ended |= snapshot.is_share_usable();
62 62
63 status.updates_available += snapshot->num_server_changes_remaining; 63 status.updates_available += snapshot.num_server_changes_remaining();
64 status.sync_protocol_error = snapshot->errors.sync_protocol_error; 64 status.sync_protocol_error = snapshot.errors().sync_protocol_error;
65 65
66 // Accumulate update count only once per session to avoid double-counting. 66 // Accumulate update count only once per session to avoid double-counting.
67 // TODO(ncarter): Make this realtime by having the syncer_status 67 // TODO(ncarter): Make this realtime by having the syncer_status
68 // counter preserve its value across sessions. http://crbug.com/26339 68 // counter preserve its value across sessions. http://crbug.com/26339
69 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { 69 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) {
70 status.updates_received += 70 status.updates_received +=
71 snapshot->syncer_status.num_updates_downloaded_total; 71 snapshot.syncer_status().num_updates_downloaded_total;
72 status.tombstone_updates_received += 72 status.tombstone_updates_received +=
73 snapshot->syncer_status.num_tombstone_updates_downloaded_total; 73 snapshot.syncer_status().num_tombstone_updates_downloaded_total;
74 status.reflected_updates_received += 74 status.reflected_updates_received +=
75 snapshot->syncer_status.num_reflected_updates_downloaded_total; 75 snapshot.syncer_status().num_reflected_updates_downloaded_total;
76 status.num_local_overwrites_total += 76 status.num_local_overwrites_total +=
77 snapshot->syncer_status.num_local_overwrites; 77 snapshot.syncer_status().num_local_overwrites;
78 status.num_server_overwrites_total += 78 status.num_server_overwrites_total +=
79 snapshot->syncer_status.num_server_overwrites; 79 snapshot.syncer_status().num_server_overwrites;
80 if (snapshot->syncer_status.num_updates_downloaded_total == 0) { 80 if (snapshot.syncer_status().num_updates_downloaded_total == 0) {
81 ++status.empty_get_updates; 81 ++status.empty_get_updates;
82 } else { 82 } else {
83 ++status.nonempty_get_updates; 83 ++status.nonempty_get_updates;
84 } 84 }
85 if (snapshot->syncer_status.num_successful_commits == 0) { 85 if (snapshot.syncer_status().num_successful_commits == 0) {
86 ++status.sync_cycles_without_commits; 86 ++status.sync_cycles_without_commits;
87 } else { 87 } else {
88 ++status.sync_cycles_with_commits; 88 ++status.sync_cycles_with_commits;
89 } 89 }
90 if (snapshot->syncer_status.num_successful_commits == 0 && 90 if (snapshot.syncer_status().num_successful_commits == 0 &&
91 snapshot->syncer_status.num_updates_downloaded_total == 0) { 91 snapshot.syncer_status().num_updates_downloaded_total == 0) {
92 ++status.useless_sync_cycles; 92 ++status.useless_sync_cycles;
93 } else { 93 } else {
94 ++status.useful_sync_cycles; 94 ++status.useful_sync_cycles;
95 } 95 }
96 } 96 }
97 return status; 97 return status;
98 } 98 }
99 99
100 void AllStatus::OnSyncEngineEvent(const SyncEngineEvent& event) { 100 void AllStatus::OnSyncEngineEvent(const SyncEngineEvent& event) {
101 ScopedStatusLock lock(this); 101 ScopedStatusLock lock(this);
102 switch (event.what_happened) { 102 switch (event.what_happened) {
103 case SyncEngineEvent::SYNC_CYCLE_BEGIN: 103 case SyncEngineEvent::SYNC_CYCLE_BEGIN:
104 case SyncEngineEvent::STATUS_CHANGED: 104 case SyncEngineEvent::STATUS_CHANGED:
105 case SyncEngineEvent::SYNC_CYCLE_ENDED: 105 case SyncEngineEvent::SYNC_CYCLE_ENDED:
106 status_ = CalcSyncing(event); 106 status_ = CalcSyncing(event);
107 break; 107 break;
108 case SyncEngineEvent::STOP_SYNCING_PERMANENTLY: 108 case SyncEngineEvent::STOP_SYNCING_PERMANENTLY:
109 case SyncEngineEvent::UPDATED_TOKEN: 109 case SyncEngineEvent::UPDATED_TOKEN:
110 case SyncEngineEvent::CLEAR_SERVER_DATA_FAILED: 110 case SyncEngineEvent::CLEAR_SERVER_DATA_FAILED:
111 case SyncEngineEvent::CLEAR_SERVER_DATA_SUCCEEDED: 111 case SyncEngineEvent::CLEAR_SERVER_DATA_SUCCEEDED:
112 break; 112 break;
113 case SyncEngineEvent::ACTIONABLE_ERROR: 113 case SyncEngineEvent::ACTIONABLE_ERROR:
114 status_ = CreateBlankStatus(); 114 status_ = CreateBlankStatus();
115 status_.sync_protocol_error = event.snapshot->errors.sync_protocol_error; 115 status_.sync_protocol_error = event.snapshot.errors().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 sync_api::SyncManager::Status AllStatus::status() const { 123 sync_api::SyncManager::Status AllStatus::status() const {
124 base::AutoLock lock(mutex_); 124 base::AutoLock lock(mutex_);
125 return status_; 125 return status_;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 ScopedStatusLock::ScopedStatusLock(AllStatus* allstatus) 158 ScopedStatusLock::ScopedStatusLock(AllStatus* allstatus)
159 : allstatus_(allstatus) { 159 : allstatus_(allstatus) {
160 allstatus->mutex_.Acquire(); 160 allstatus->mutex_.Acquire();
161 } 161 }
162 162
163 ScopedStatusLock::~ScopedStatusLock() { 163 ScopedStatusLock::~ScopedStatusLock() {
164 allstatus_->mutex_.Release(); 164 allstatus_->mutex_.Release();
165 } 165 }
166 166
167 } // namespace browser_sync 167 } // namespace browser_sync
OLDNEW
« no previous file with comments | « sync/internal_api/all_status.h ('k') | sync/internal_api/debug_info_event_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698