1 // Copyright 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.
4 
5 #ifndef COMPONENTS_SYNC_ENGINE_IMPL_CYCLE_STATUS_CONTROLLER_H_
6 #define COMPONENTS_SYNC_ENGINE_IMPL_CYCLE_STATUS_CONTROLLER_H_
7 
8 #include <map>
9 #include <vector>
10 
11 #include "base/macros.h"
12 #include "base/time/time.h"
13 #include "components/sync/engine/cycle/model_neutral_state.h"
14 
15 namespace syncer {
16 
17 // StatusController handles all counter and status related number crunching and
18 // state tracking on behalf of a SyncCycle.
19 //
20 // This object may be accessed from many different threads.  It will be accessed
21 // most often from the syncer thread.  However, when update application is in
22 // progress it may also be accessed from the worker threads.  This is safe
23 // because only one of them will run at a time, and the syncer thread will be
24 // blocked until update application completes.
25 //
26 // This object contains only global state.  None of its members are per model
27 // type counters.
28 class StatusController {
29  public:
30   StatusController();
31   ~StatusController();
32 
33   // The types included in the get updates client to server requests.
34   const ModelTypeSet get_updates_request_types() const;
35   void set_get_updates_request_types(ModelTypeSet value);
36 
37   // Various conflict counters.
38   int num_encryption_conflicts() const;
39   int num_hierarchy_conflicts() const;
40   int num_server_conflicts() const;
41 
42   // Aggregate sum of all conflicting items over all conflict types.
43   int TotalNumConflictingItems() const;
44 
45   // Number of successfully applied updates.
46   int num_updates_applied() const;
47 
48   int num_server_overwrites() const;
49   int num_local_overwrites() const;
50 
51   // The time at which we started the most recent sync cycle.
sync_start_time()52   base::Time sync_start_time() const { return sync_start_time_; }
53 
54   // If a poll was performed in this cycle, the time at which it finished.
55   // Not set if no poll was performed.
poll_finish_time()56   base::Time poll_finish_time() const { return poll_finish_time_; }
57 
model_neutral_state()58   const ModelNeutralState& model_neutral_state() const {
59     return model_neutral_;
60   }
61 
62   SyncerError last_get_key_result() const;
63 
64   // Download counters.
65   void increment_num_updates_downloaded_by(int value);
66   void increment_num_tombstone_updates_downloaded_by(int value);
67   void increment_num_reflected_updates_downloaded_by(int value);
68 
69   // Update application and conflict resolution counters.
70   void increment_num_updates_applied_by(int value);
71   void increment_num_encryption_conflicts_by(int value);
72   void increment_num_hierarchy_conflicts_by(int value);
73   void increment_num_server_conflicts();
74   void increment_num_local_overwrites();
75   void increment_num_server_overwrites();
76 
77   // Commit counters.
78   void increment_num_successful_commits();
79   void increment_num_successful_bookmark_commits();
80 
81   // Server communication status tracking.
82   void set_last_get_key_result(const SyncerError result);
83   void set_last_download_updates_result(const SyncerError result);
84   void set_commit_result(const SyncerError result);
85 
86   void UpdateStartTime();
87   void UpdatePollTime();
88 
89  private:
90   ModelNeutralState model_neutral_;
91 
92   // Time the last sync cycle began.
93   base::Time sync_start_time_;
94 
95   // If a poll was performed, the time it finished. Not set if not poll was
96   // performed.
97   base::Time poll_finish_time_;
98 
99   DISALLOW_COPY_AND_ASSIGN(StatusController);
100 };
101 
102 }  // namespace syncer
103 
104 #endif  // COMPONENTS_SYNC_ENGINE_IMPL_CYCLE_STATUS_CONTROLLER_H_
105