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