File: glic_zero_state_suggestions_manager.h

package info (click to toggle)
chromium 140.0.7339.127-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,192,880 kB
  • sloc: cpp: 35,093,808; ansic: 7,161,670; javascript: 4,199,694; python: 1,441,797; asm: 949,904; xml: 747,503; pascal: 187,748; perl: 88,691; sh: 88,248; objc: 79,953; sql: 52,714; cs: 44,599; fortran: 24,137; makefile: 22,114; tcl: 15,277; php: 13,980; yacc: 9,000; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (105 lines) | stat: -rw-r--r-- 3,712 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
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_GLIC_GLIC_ZERO_STATE_SUGGESTIONS_MANAGER_H_
#define CHROME_BROWSER_GLIC_GLIC_ZERO_STATE_SUGGESTIONS_MANAGER_H_

#include <optional>
#include <string>
#include <vector>

#include "chrome/browser/glic/host/context/glic_tab_data.h"

namespace contextual_cueing {
class ContextualCueingService;
}  // namespace contextual_cueing

namespace glic {
class GlicSharingManagerImpl;
class GlicWindowController;
class Host;

// A class for managing sending zero state suggestions through the mojo api.
class GlicZeroStateSuggestionsManager {
 public:
  explicit GlicZeroStateSuggestionsManager(
      GlicSharingManagerImpl* sharing_manager,
      GlicWindowController* window_controller,
      contextual_cueing::ContextualCueingService* contextual_cueing_service,
      Host* host);
  virtual ~GlicZeroStateSuggestionsManager();

  // Callback to send zero state suggestions to the webui on tab changes.
  void NotifyZeroStateSuggestionsOnFocusedTabDataChanged(
      bool is_first_run,
      const std::vector<std::string>& supported_tools,
      const mojom::TabData* focused_tab_data);

  // Callback to send zero state suggestions to the webui on pinned tab changes.
  void NotifyZeroStateSuggestionsOnPinnedTabChanged(
      bool is_first_run,
      const std::vector<std::string>& supported_tools,
      const std::vector<content::WebContents*>& pinned_tab_data);

  // Callback to send zero state suggestions to the webui when pinned tab data
  // changes.
  void NotifyZeroStateSuggestionsOnPinnedTabDataChanged(
      bool is_first_run,
      const std::vector<std::string>& supported_tools,
      const mojom::TabData* data);

  // This handles calls from the webui to return a suggestion, and begin to
  // notify the webui of changes to the zero state suggestsions.
  void ObserveZeroStateSuggestions(
      bool is_notifying,
      bool is_first_run,
      const std::vector<std::string>& supported_tools,
      glic::mojom::WebClientHandler::GetZeroStateSuggestionsAndSubscribeCallback
          callback);

  void Reset();

 private:
  // A helper function to route GetZeroStateSuggestionsForFocusedTabCallback
  // callbacks.
  void OnZeroStateSuggestionsFetched(
      mojom::WebClientHandler::GetZeroStateSuggestionsAndSubscribeCallback
          callback,
      std::vector<std::string> returned_suggestions);

  // A helper function to route NotifyZeroStateSuggestions callbacks.
  void OnZeroStateSuggestionsNotify(
      bool is_first_run,
      const std::vector<std::string>& supported_tools,
      std::vector<std::string> returned_suggestions);

  base::WeakPtr<GlicZeroStateSuggestionsManager> GetWeakPtr();

  // Owned by the glic_keyed_service.
  raw_ptr<GlicSharingManagerImpl> sharing_manager_;
  raw_ptr<GlicWindowController> window_controller_;
  raw_ptr<Host> host_;

  // This passed by the glic_keyed_service.
  raw_ptr<contextual_cueing::ContextualCueingService>
      contextual_cueing_service_;

  mojom::ZeroStateSuggestionsOptions current_zero_state_suggestions_options_;
  base::CallbackListSubscription
      current_zero_state_suggestions_focus_change_subscription_;

  base::CallbackListSubscription
      current_zero_state_suggestions_pinned_tab_change_subscription_;

  base::CallbackListSubscription
      current_zero_state_suggestions_pinned_tab_data_change_subscription_;

  bool pause_pinned_subscription_updates_ = false;

  base::WeakPtrFactory<GlicZeroStateSuggestionsManager> weak_ptr_factory_{this};
};

}  // namespace glic

#endif  // CHROME_BROWSER_GLIC_GLIC_ZERO_STATE_SUGGESTIONS_MANAGER_H_