File: browsing_history_handler.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; 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 (136 lines) | stat: -rw-r--r-- 4,769 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright 2015 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_UI_WEBUI_HISTORY_BROWSING_HISTORY_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_HISTORY_BROWSING_HISTORY_HANDLER_H_

#include <stdint.h>

#include <memory>
#include <queue>
#include <string>
#include <utility>
#include <vector>

#include "base/functional/callback.h"
#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/clock.h"
#include "base/values.h"
#include "chrome/browser/history/profile_based_browsing_history_driver.h"
#include "chrome/browser/ui/webui/top_chrome/top_chrome_web_ui_controller.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "ui/webui/resources/cr_components/history/history.mojom.h"

namespace content {
class WebContents;
}  // namespace content

// The handler for Javascript messages related to the "history" view.
class BrowsingHistoryHandler : public history::mojom::PageHandler,
                               public ProfileBasedBrowsingHistoryDriver {
 public:
  BrowsingHistoryHandler(
      mojo::PendingReceiver<history::mojom::PageHandler> pending_page_handler,
      Profile* profile,
      content::WebContents* web_contents);

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

  ~BrowsingHistoryHandler() override;

  void SetSidePanelUIEmbedder(
      base::WeakPtr<TopChromeWebUIController::Embedder> side_panel_embedder);

  void StartQueryHistory();

  void SetPage(mojo::PendingRemote<history::mojom::Page> pending_page) override;

  void ShowSidePanelUI() override;

  void QueryHistory(const std::string& query,
                    int max_count,
                    std::optional<double> begin_timestamp,
                    QueryHistoryCallback callback) override;

  void QueryHistoryContinuation(
      QueryHistoryContinuationCallback callback) override;

  void RemoveVisits(const std::vector<history::mojom::RemovalItemPtr> items,
                    RemoveVisitsCallback callback) override;

  void OpenClearBrowsingDataDialog() override;

  void RemoveBookmark(const std::string& url) override;

  void SetLastSelectedTab(const int last_tab) override;

  // BrowsingHistoryDriver implementation.
  void OnQueryComplete(
      const std::vector<history::BrowsingHistoryService::HistoryEntry>& results,
      const history::BrowsingHistoryService::QueryResultsInfo&
          query_results_info,
      base::OnceClosure continuation_closure) override;
  void OnRemoveVisitsComplete() override;
  void OnRemoveVisitsFailed() override;
  void HistoryDeleted() override;
  void HasOtherFormsOfBrowsingHistory(bool has_other_forms,
                                      bool has_synced_results) override;

  // ProfileBasedBrowsingHistoryDriver implementation.
  Profile* GetProfile() override;

  // For tests. This does not take the ownership of the clock. |clock| must
  // outlive the BrowsingHistoryHandler instance.
  void set_clock(base::Clock* clock) { clock_ = clock; }

  void set_browsing_history_service_for_testing(
      std::unique_ptr<history::BrowsingHistoryService> service) {
    browsing_history_service_ = std::move(service);
  }

  history::BrowsingHistoryService* get_browsing_history_service_for_testing() {
    return browsing_history_service_.get();
  }

 protected:
  virtual void SendHistoryQuery(int count,
                                const std::string& query,
                                std::optional<double> begin_timestamp);

 private:
  FRIEND_TEST_ALL_PREFIXES(BrowsingHistoryHandlerTest,
                           ObservingWebHistoryDeletions);
  FRIEND_TEST_ALL_PREFIXES(BrowsingHistoryHandlerTest, MdTruncatesTitles);

  base::WeakPtr<TopChromeWebUIController::Embedder> side_panel_embedder_;

  raw_ptr<Profile> profile_;
  raw_ptr<content::WebContents> web_contents_;

  mojo::Remote<history::mojom::Page> page_;
  mojo::Receiver<history::mojom::PageHandler> page_handler_;

  // The clock used to vend times.
  raw_ptr<base::Clock> clock_;

  std::unique_ptr<history::BrowsingHistoryService> browsing_history_service_;

  std::vector<base::OnceClosure> deferred_callbacks_;

  QueryHistoryCallback query_history_callback_;

  base::OnceClosure query_history_continuation_;

  std::queue<RemoveVisitsCallback> remove_visits_callbacks_;

  base::WeakPtrFactory<BrowsingHistoryHandler> weak_factory_{this};
};

#endif  // CHROME_BROWSER_UI_WEBUI_HISTORY_BROWSING_HISTORY_HANDLER_H_