File: local_session_event_handler_impl.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (113 lines) | stat: -rw-r--r-- 3,979 bytes parent folder | download | duplicates (4)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SYNC_SESSIONS_LOCAL_SESSION_EVENT_HANDLER_IMPL_H_
#define COMPONENTS_SYNC_SESSIONS_LOCAL_SESSION_EVENT_HANDLER_IMPL_H_

#include <memory>
#include <set>
#include <string>

#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "components/sessions/core/session_id.h"
#include "components/sessions/core/session_types.h"
#include "components/sync_sessions/local_session_event_router.h"
#include "components/sync_sessions/synced_session.h"

namespace sync_pb {
class SessionSpecifics;
class SessionTab;
}  // namespace sync_pb

namespace sync_sessions {

class SyncedSessionTracker;
class SyncedTabDelegate;
class SyncSessionsClient;

// Class responsible for propagating local session changes to the sessions
// model including SyncedSessionTracker (in-memory representation) as well as
// the persistency and sync layers (via delegate).
class LocalSessionEventHandlerImpl : public LocalSessionEventHandler {
 public:
  class WriteBatch {
   public:
    WriteBatch();

    WriteBatch(const WriteBatch&) = delete;
    WriteBatch& operator=(const WriteBatch&) = delete;

    virtual ~WriteBatch();
    virtual void Delete(int tab_node_id) = 0;
    virtual void Put(std::unique_ptr<sync_pb::SessionSpecifics> specifics) = 0;
    virtual void Commit() = 0;
  };

  class Delegate {
   public:
    virtual ~Delegate();
    virtual std::unique_ptr<WriteBatch> CreateLocalSessionWriteBatch() = 0;
    virtual bool IsTabNodeUnsynced(int tab_node_id) = 0;
    // Analogous to SessionsGlobalIdMapper.
    virtual void TrackLocalNavigationId(base::Time timestamp,
                                        int unique_id) = 0;
  };

  // Raw pointers must not be null and all pointees must outlive this object.
  // A side effect of this constructor could include (unless session restore is
  // ongoing) the creation of a write batch (via |delegate| and committing
  // changes).
  LocalSessionEventHandlerImpl(Delegate* delegate,
                               SyncSessionsClient* sessions_client,
                               SyncedSessionTracker* session_tracker,
                               bool is_new_session);

  LocalSessionEventHandlerImpl(const LocalSessionEventHandlerImpl&) = delete;
  LocalSessionEventHandlerImpl& operator=(const LocalSessionEventHandlerImpl&) =
      delete;

  ~LocalSessionEventHandlerImpl() override;

  // LocalSessionEventHandler implementation.
  void OnSessionRestoreComplete() override;
  void OnLocalTabModified(SyncedTabDelegate* modified_tab) override;
  void OnLocalTabClosed() override;

  // Returns tab specifics from |tab_delegate|. Exposed publicly for testing.
  sync_pb::SessionTab GetTabSpecificsFromDelegateForTest(
      SyncedTabDelegate& tab_delegate) const;

 private:
  enum ReloadTabsOption { RELOAD_TABS, DONT_RELOAD_TABS };

  void CleanupLocalTabs(WriteBatch* batch);

  void AssociateWindows(ReloadTabsOption option,
                        WriteBatch* batch,
                        bool is_session_restore);

  // Loads and reassociates the local tab referenced in |tab|.
  // |batch| must not be null. This function will append necessary
  // changes for processing later.
  void AssociateTab(SyncedTabDelegate* const tab, WriteBatch* batch);

  // Set |session_tab| from |tab_delegate|.
  sync_pb::SessionTab GetTabSpecificsFromDelegate(
      SyncedTabDelegate& tab_delegate) const;

  bool AssociatePlaceholderTab(std::unique_ptr<SyncedTabDelegate> snapshot,
                               WriteBatch* batch);

  // Injected dependencies (not owned).
  const raw_ptr<Delegate> delegate_;
  const raw_ptr<SyncSessionsClient> sessions_client_;
  const raw_ptr<SyncedSessionTracker> session_tracker_;

  std::string current_session_tag_;
};

}  // namespace sync_sessions

#endif  // COMPONENTS_SYNC_SESSIONS_LOCAL_SESSION_EVENT_HANDLER_IMPL_H_