File: lost_navigations_recorder.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (58 lines) | stat: -rw-r--r-- 2,299 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SYNC_SESSIONS_LOST_NAVIGATIONS_RECORDER_H_
#define COMPONENTS_SYNC_SESSIONS_LOST_NAVIGATIONS_RECORDER_H_

#include <map>
#include <set>

#include "base/macros.h"
#include "components/sessions/core/session_id.h"
#include "components/sync/model/local_change_observer.h"
#include "components/sync/model/sync_change.h"
#include "components/sync/protocol/session_specifics.pb.h"

namespace sync_sessions {

// Recorder class that tracks the number of navigations written locally that
// aren't synced. This is done by recording set of locally observed navigations
// and  reconciling these sets against what was ultimately synced. These
// navigations ultimately feed chrome history, so losing them prevents them from
// being reflected in the history page.
class LostNavigationsRecorder : public syncer::LocalChangeObserver {
 public:
  typedef SessionID::id_type id_type;
  typedef std::set<id_type> IdSet;
  enum RecorderState { RECORDER_STATE_NOT_SYNCING, RECORDER_STATE_SYNCING };

  LostNavigationsRecorder();
  ~LostNavigationsRecorder() override;

  // syncer::LocalChangeObserver implementation.
  void OnLocalChange(const syncer::syncable::Entry* current_entry,
                     const syncer::SyncChange& change) override;

 private:
  void RecordChange(const syncer::SyncChange& change);
  void DeleteTabs(const sync_pb::SessionHeader& header);
  void TransitionState(bool is_syncing, bool is_unsynced);
  void ReconcileLostNavs();

  // State that records whether the most recently observed directory state was
  // syncing or not syncing.
  RecorderState recorder_state_;

  // The set of all navigation ids we've observed for each tab_id since the last
  // sync.
  std::map<id_type, IdSet> recorded_navigation_ids_;
  // The set of navigation ids most recently recorded for each tab_id.
  std::map<id_type, IdSet> latest_navigation_ids_;
  // The maximum navigation_id recorded for each tab_id.
  std::map<id_type, id_type> max_recorded_for_tab_;
  DISALLOW_COPY_AND_ASSIGN(LostNavigationsRecorder);
};
};  // namespace sync_sessions

#endif  // COMPONENTS_SYNC_SESSIONS_LOST_NAVIGATIONS_RECORDER_H_