Files
cdesouza-chromium 5cf18451d5 [CodeHealth] Use base::DictValue/base::ListValue - Part VI (#33697)
These classes were hoisted and renamed. This has been replaced in
Chromium as well. This is a mechanical change for Brave, done with the
following script.

```
git grep -lw 'Value::List' | xargs sed -i 's/\bValue::List\b/ListValue/g'
git grep -lw 'Value::Dict' | xargs sed -i 's/\bValue::Dict\b/DictValue/g'
git cl format
```

Chromium changes:
https://chromium.googlesource.com/chromium/src/+/6bc468d481835992696083e99e556516fb7f5f80

```
commit 6bc468d481835992696083e99e556516fb7f5f80
Author: Avi Drissman <avi@chromium.org>
Date:   Thu Jan 29 22:14:50 2026 -0800

    Remove aliases for base::DictValue and base::ListValue

    This removes a few last stragglers as well.

    Fixed: 478100525
    Cq-Include-Trybots: luci.chromium.try:win-official,mac-official,linux-official,android-official,android-desktop-x64-official
    Change-Id: If92142b8ab0562a82c609b71c6b2a7665cea6ec6
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7513889
    Auto-Submit: Avi Drissman <avi@chromium.org>
    Commit-Queue: Daniel Cheng <dcheng@chromium.org>
    Owners-Override: Daniel Cheng <dcheng@chromium.org>
    Reviewed-by: Daniel Cheng <dcheng@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#1577038}
```

Issue: https://github.com/brave/brave-browser/issues/52435
2026-02-05 17:09:26 -03:00

69 lines
2.3 KiB
C++

/* Copyright (c) 2024 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */
#ifndef BRAVE_COMPONENTS_WEB_DISCOVERY_BROWSER_REQUEST_QUEUE_H_
#define BRAVE_COMPONENTS_WEB_DISCOVERY_BROWSER_REQUEST_QUEUE_H_
#include <string_view>
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/timer/timer.h"
#include "base/values.h"
#include "brave/components/web_discovery/browser/pref_names.h"
#include "net/base/backoff_entry.h"
class PrefService;
namespace web_discovery {
// Persists and schedules requests on randomized intervals within
// an interval range. If request failures exceed the threshold defined in
// `max_retries`, the request will be dropped from the list. If a persisted
// request age exceeds `request_max_age`, the request will be dropped.
class RequestQueue {
public:
RequestQueue(
PrefService* profile_prefs,
RequestQueuePrefName list_pref_name,
base::TimeDelta request_max_age,
base::TimeDelta min_request_interval,
base::TimeDelta max_request_interval,
size_t max_retries,
base::RepeatingCallback<void(const base::Value&)> start_request_callback);
~RequestQueue();
RequestQueue(const RequestQueue&) = delete;
RequestQueue& operator=(const RequestQueue&) = delete;
// Persist and schedule a request. The arbitrary data will be passed
// to `start_request_callback` on the scheduled interval.
void ScheduleRequest(base::DictValue request_data);
// Returns data value if request is deleted from queue, due to the retry limit
// or success
std::optional<base::Value> NotifyRequestComplete(bool success);
private:
void OnFetchTimer();
void StartFetchTimer(bool use_backoff_delta);
raw_ptr<PrefService> profile_prefs_;
RequestQueuePrefName list_pref_name_;
net::BackoffEntry backoff_entry_;
base::TimeDelta request_max_age_;
base::TimeDelta min_request_interval_;
base::TimeDelta max_request_interval_;
size_t max_retries_;
base::RepeatingCallback<void(const base::Value&)> start_request_callback_;
base::OneShotTimer fetch_timer_;
};
} // namespace web_discovery
#endif // BRAVE_COMPONENTS_WEB_DISCOVERY_BROWSER_REQUEST_QUEUE_H_