| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // StatusController handles all counter and status related number crunching and |
| 6 // state tracking on behalf of a SyncSession. It 'controls' the model data |
| 7 // defined in session_state.h. It can track if changes occur to certain parts |
| 8 // of state so that various parts of the sync engine can avoid broadcasting |
| 9 // notifications if no changes occurred. It also separates transient state |
| 10 // from long-lived SyncSession state for explicitness and to facilitate |
| 11 // resetting transient state. |
| 12 |
| 13 #ifndef CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_ |
| 14 #define CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_ |
| 15 |
| 16 #include "base/scoped_ptr.h" |
| 17 #include "chrome/browser/sync/sessions/session_state.h" |
| 18 |
| 19 namespace browser_sync { |
| 20 namespace sessions { |
| 21 |
| 22 class StatusController { |
| 23 public: |
| 24 StatusController(); |
| 25 |
| 26 // Returns true if some portion of the session state has changed (is dirty) |
| 27 // since it was created or was last reset. |
| 28 bool TestAndClearIsDirty(); |
| 29 |
| 30 // Discards the current transient state components that should not carry over |
| 31 // to a subsequent sync cycle (a run between states in SyncShare), and keeps |
| 32 // everything else intact. After the call, |this| is ready for use |
| 33 // as part of a new sync cycle. |
| 34 void ResetTransientState(); |
| 35 |
| 36 ConflictProgress const* conflict_progress() const { |
| 37 return &conflict_progress_; |
| 38 } |
| 39 ConflictProgress* mutable_conflict_progress() { |
| 40 return &conflict_progress_; |
| 41 } |
| 42 const UpdateProgress& update_progress() { |
| 43 return transient_->value()->update_progress; |
| 44 } |
| 45 UpdateProgress* mutable_update_progress() { |
| 46 return &transient_->value()->update_progress; |
| 47 } |
| 48 ClientToServerMessage* mutable_commit_message() { |
| 49 return &transient_->value()->commit_message; |
| 50 } |
| 51 const ClientToServerResponse& commit_response() const { |
| 52 return transient_->value()->commit_response; |
| 53 } |
| 54 ClientToServerResponse* mutable_commit_response() { |
| 55 return &transient_->value()->commit_response; |
| 56 } |
| 57 const ClientToServerResponse& updates_response() { |
| 58 return transient_->value()->updates_response; |
| 59 } |
| 60 ClientToServerResponse* mutable_updates_response() { |
| 61 return &transient_->value()->updates_response; |
| 62 } |
| 63 const ErrorCounters& error_counters() const { |
| 64 return error_counters_.value(); |
| 65 } |
| 66 const SyncerStatus& syncer_status() const { |
| 67 return syncer_status_.value(); |
| 68 } |
| 69 const ChangelogProgress& change_progress() const { |
| 70 return change_progress_.value(); |
| 71 } |
| 72 const std::vector<syncable::Id>& commit_ids() const { |
| 73 return transient_->value()->commit_ids; |
| 74 } |
| 75 const std::vector<int64>& unsynced_handles() const { |
| 76 return transient_->value()->unsynced_handles; |
| 77 } |
| 78 bool conflict_sets_built() const { |
| 79 return transient_->value()->conflict_sets_built; |
| 80 } |
| 81 bool conflicts_resolved() const { |
| 82 return transient_->value()->conflicts_resolved; |
| 83 } |
| 84 bool timestamp_dirty() const { |
| 85 return transient_->value()->timestamp_dirty; |
| 86 } |
| 87 bool did_commit_items() const { |
| 88 return transient_->value()->items_committed; |
| 89 } |
| 90 |
| 91 // Returns the number of updates received from the sync server. |
| 92 int64 CountUpdates() const; |
| 93 |
| 94 bool got_zero_updates() const { return CountUpdates() == 0; } |
| 95 |
| 96 // A toolbelt full of methods for updating counters and flags. |
| 97 void set_num_conflicting_commits(int value); |
| 98 void set_num_consecutive_problem_get_updates(int value); |
| 99 void increment_num_consecutive_problem_get_updates(); |
| 100 void set_num_consecutive_problem_commits(int value); |
| 101 void increment_num_consecutive_problem_commits(); |
| 102 void set_num_consecutive_transient_error_commits(int value); |
| 103 void increment_num_consecutive_transient_error_commits_by(int value); |
| 104 void set_num_consecutive_errors(int value); |
| 105 void increment_num_consecutive_errors(); |
| 106 void increment_num_consecutive_errors_by(int value); |
| 107 void set_current_sync_timestamp(int64 current_timestamp); |
| 108 void set_num_server_changes_remaining(int64 changes_remaining); |
| 109 void set_over_quota(bool over_quota); |
| 110 void set_invalid_store(bool invalid_store); |
| 111 void set_syncer_stuck(bool syncer_stuck); |
| 112 void set_syncing(bool syncing); |
| 113 void set_num_successful_commits(int value); |
| 114 void increment_num_successful_commits(); |
| 115 void set_unsynced_handles(const std::vector<int64>& unsynced_handles); |
| 116 |
| 117 void set_commit_ids(const std::vector<syncable::Id>& commit_ids); |
| 118 void set_conflict_sets_built(bool built); |
| 119 void set_conflicts_resolved(bool resolved); |
| 120 void set_items_committed(bool items_committed); |
| 121 void set_timestamp_dirty(bool dirty); |
| 122 |
| 123 private: |
| 124 // Dirtyable keeps a dirty bit that can be set, cleared, and checked to |
| 125 // determine if a notification should be sent due to state change. |
| 126 // This is useful when applied to any session state object if you want to know |
| 127 // that some part of that object changed. |
| 128 template <typename T> |
| 129 class Dirtyable { |
| 130 public: |
| 131 Dirtyable() : dirty_(false) {} |
| 132 void set_dirty() { dirty_ = true; } |
| 133 bool TestAndClearIsDirty(); |
| 134 T* value() { return &t_; } |
| 135 const T& value() const { return t_; } |
| 136 private: |
| 137 T t_; |
| 138 bool dirty_; |
| 139 }; |
| 140 |
| 141 // Various pieces of state we track dirtiness of. |
| 142 Dirtyable<ChangelogProgress> change_progress_; |
| 143 Dirtyable<SyncerStatus> syncer_status_; |
| 144 Dirtyable<ErrorCounters> error_counters_; |
| 145 |
| 146 // The transient parts of a sync session that can be reset during the session. |
| 147 // For some parts of this state, we want to track whether changes occurred so |
| 148 // we allocate a Dirtyable version. |
| 149 scoped_ptr<Dirtyable<TransientState> > transient_; |
| 150 |
| 151 ConflictProgress conflict_progress_; |
| 152 |
| 153 DISALLOW_COPY_AND_ASSIGN(StatusController); |
| 154 }; |
| 155 |
| 156 } |
| 157 } |
| 158 |
| 159 #endif // CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_ |
| OLD | NEW |