blob: 8f0f20b9a3a7b90436de2bbfd0001da04fb3de49 [file] [log] [blame]
// 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_CONTEXTUAL_SEARCH_CONTEXTUAL_SEARCH_WEB_CONTENTS_HELPER_H_
#define CHROME_BROWSER_CONTEXTUAL_SEARCH_CONTEXTUAL_SEARCH_WEB_CONTENTS_HELPER_H_
#include <memory>
#include "components/contextual_search/contextual_search_session_handle.h"
#include "content/public/browser/web_contents_user_data.h"
namespace content {
class WebContents;
}
// Helper class that scopes the `ContextualSearchSessionHandle`'s
// lifetime to a `content::WebContents`.
class ContextualSearchWebContentsHelper
: public content::WebContentsUserData<ContextualSearchWebContentsHelper> {
public:
ContextualSearchWebContentsHelper(const ContextualSearchWebContentsHelper&) =
delete;
ContextualSearchWebContentsHelper& operator=(
const ContextualSearchWebContentsHelper&) = delete;
~ContextualSearchWebContentsHelper() override;
// Takes ownership of a contextual session handle.
void set_session_handle(
std::unique_ptr<contextual_search::ContextualSearchSessionHandle>
handle) {
session_handle_ = std::move(handle);
}
// Returns the owned contextual session handle. May return nullptr.
contextual_search::ContextualSearchSessionHandle* session_handle() const {
return session_handle_.get();
}
private:
explicit ContextualSearchWebContentsHelper(
content::WebContents* web_contents);
friend class content::WebContentsUserData<ContextualSearchWebContentsHelper>;
std::unique_ptr<contextual_search::ContextualSearchSessionHandle>
session_handle_;
WEB_CONTENTS_USER_DATA_KEY_DECL();
};
#endif // CHROME_BROWSER_CONTEXTUAL_SEARCH_CONTEXTUAL_SEARCH_WEB_CONTENTS_HELPER_H_