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 #ifndef SYNC_INTERNAL_API_PUBLIC_SESSIONS_SYNC_SESSION_SNAPSHOT_H_
      6 #define SYNC_INTERNAL_API_PUBLIC_SESSIONS_SYNC_SESSION_SNAPSHOT_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/time/time.h"
     12 #include "sync/base/sync_export.h"
     13 #include "sync/internal_api/public/base/model_type.h"
     14 #include "sync/internal_api/public/base/progress_marker_map.h"
     15 #include "sync/internal_api/public/sessions/model_neutral_state.h"
     16 
     17 namespace base {
     18 class DictionaryValue;
     19 }
     20 
     21 namespace syncer {
     22 namespace sessions {
     23 
     24 // An immutable snapshot of state from a SyncSession.  Convenient to use as
     25 // part of notifications as it is inherently thread-safe.
     26 // TODO(zea): if copying this all over the place starts getting expensive,
     27 // consider passing around immutable references instead of values.
     28 // Default copy and assign welcome.
     29 class SYNC_EXPORT SyncSessionSnapshot {
     30  public:
     31   SyncSessionSnapshot();
     32   SyncSessionSnapshot(
     33       const ModelNeutralState& model_neutral_state,
     34       const ProgressMarkerMap& download_progress_markers,
     35       bool is_silenced,
     36       int num_encryption_conflicts,
     37       int num_hierarchy_conflicts,
     38       int num_server_conflicts,
     39       bool notifications_enabled,
     40       size_t num_entries,
     41       base::Time sync_start_time,
     42       const std::vector<int>& num_entries_by_type,
     43       const std::vector<int>& num_to_delete_entries_by_type,
     44       sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source);
     45   ~SyncSessionSnapshot();
     46 
     47   // Caller takes ownership of the returned dictionary.
     48   base::DictionaryValue* ToValue() const;
     49 
     50   std::string ToString() const;
     51 
     52   ModelNeutralState model_neutral_state() const {
     53     return model_neutral_state_;
     54   }
     55   int64 num_server_changes_remaining() const;
     56   const ProgressMarkerMap& download_progress_markers() const;
     57   bool is_silenced() const;
     58   int num_encryption_conflicts() const;
     59   int num_hierarchy_conflicts() const;
     60   int num_server_conflicts() const;
     61   bool notifications_enabled() const;
     62   size_t num_entries() const;
     63   base::Time sync_start_time() const;
     64   const std::vector<int>& num_entries_by_type() const;
     65   const std::vector<int>& num_to_delete_entries_by_type() const;
     66   sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source() const;
     67 
     68   // Set iff this snapshot was not built using the default constructor.
     69   bool is_initialized() const;
     70 
     71  private:
     72   ModelNeutralState model_neutral_state_;
     73   ProgressMarkerMap download_progress_markers_;
     74   bool is_silenced_;
     75   int num_encryption_conflicts_;
     76   int num_hierarchy_conflicts_;
     77   int num_server_conflicts_;
     78   bool notifications_enabled_;
     79   size_t num_entries_;
     80   base::Time sync_start_time_;
     81 
     82   std::vector<int> num_entries_by_type_;
     83   std::vector<int> num_to_delete_entries_by_type_;
     84 
     85   // This enum value used to be an important part of the sync protocol, but is
     86   // now deprecated.  We continue to use it in the snapshot because there is
     87   // still some value in displaying it on the about:sync page.
     88   sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source_;
     89 
     90   bool is_initialized_;
     91 };
     92 
     93 }  // namespace sessions
     94 }  // namespace syncer
     95 
     96 #endif  // SYNC_INTERNAL_API_PUBLIC_SESSIONS_SYNC_SESSION_SNAPSHOT_H_
     97