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
|
// 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_UI_AUTOFILL_BUBBLE_MANAGER_IMPL_H_
#define CHROME_BROWSER_UI_AUTOFILL_BUBBLE_MANAGER_IMPL_H_
#include <memory>
#include <set>
#include "base/time/time.h"
#include "chrome/browser/ui/autofill/bubble_controller_base.h"
#include "chrome/browser/ui/autofill/bubble_manager.h"
namespace autofill {
class BubbleManagerImpl : public BubbleManager {
public:
BubbleManagerImpl();
~BubbleManagerImpl() override;
BubbleManagerImpl(const BubbleManagerImpl&) = delete;
BubbleManagerImpl& operator=(const BubbleManagerImpl&) = delete;
// BubbleManager:
void RequestShowController(BubbleControllerBase& controller_to_show) override;
void OnBubbleHiddenByController(
BubbleControllerBase& controller_to_hide) override;
bool HasPendingBubble(const BubbleControllerBase& controller) override;
private:
struct PendingRequest {
PendingRequest(base::WeakPtr<BubbleControllerBase> controller,
base::TimeTicks time_added,
int priority);
~PendingRequest();
PendingRequest(const PendingRequest& other);
PendingRequest& operator=(const PendingRequest& other);
// Sorts by priority (descending), then by time (ascending) as a
// tie-breaker.
bool operator<(const PendingRequest& other) const;
base::WeakPtr<BubbleControllerBase> controller;
base::TimeTicks time_added;
int priority;
};
// Checks the pending bubbles queue and shows the highest-priority one if no
// bubble is currently active.
void ProcessPendingBubbles();
// Shows the given controller, sets it as the active one, and ensures
// it's removed from the pending queue.
void ShowAndSetCurrentActive(
base::WeakPtr<BubbleControllerBase> controller_to_show);
// Adds a controller to the pending queue based on (uniqueness by type,
// timeout, and password exception).
void AddToPendingQueue(base::WeakPtr<BubbleControllerBase> controller);
// Hides the currently active bubble to show a higher-priority one.
void HideActiveBubbleForPreemption(
base::WeakPtr<BubbleControllerBase> preempting_controller);
// Currently active controller that is shown.
base::WeakPtr<BubbleControllerBase> active_bubble_controller_ = nullptr;
// A queue of controllers that have requested to be shown. The container is
// kept sorted by priority and creation time.
std::set<PendingRequest> pending_bubbles_queue_;
// A boolean indicating that the manager is in the process of showing a
// bubble. This could mean another bubble is in the process of preemption.
bool handling_show_request_ = false;
};
} // namespace autofill
#endif // CHROME_BROWSER_UI_AUTOFILL_BUBBLE_MANAGER_IMPL_H_
|