blob: c46d7781af6f868a4881a489a57f5ddf72e0034c (
plain)
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
|
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_QUEUE_H_
#define COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_QUEUE_H_
#include <cstddef>
#include "base/containers/circular_deque.h"
#include "components/permissions/permission_request.h"
namespace permissions {
// Provides a container for holding pending PermissionRequest objects and
// provides access methods respecting the currently applicable feature flag
// configuration.
class PermissionRequestQueue {
public:
using const_iterator =
base::circular_deque<PermissionRequest*>::const_iterator;
using const_reverse_iterator =
base::circular_deque<PermissionRequest*>::const_reverse_iterator;
// Not copyable or movable
PermissionRequestQueue(const PermissionRequestQueue&) = delete;
PermissionRequestQueue& operator=(const PermissionRequestQueue&) = delete;
PermissionRequestQueue();
~PermissionRequestQueue();
bool IsEmpty() const;
size_t Count() const;
size_t Count(PermissionRequest* request) const;
// Push a new request into queue. When |reorder_based_on_priority| is set, the
// request might be inserted to correct position based on its priority,
// instead of be pushed to the front of queue.
void Push(permissions::PermissionRequest* request,
bool reorder_based_on_priority = false);
PermissionRequest* Pop();
PermissionRequest* Peek() const;
// Searches queued_requests_ and returns the first matching request, or
// nullptr if there is no match.
PermissionRequest* FindDuplicate(PermissionRequest* request) const;
// Used for iterating over the queued requests.
const_iterator begin() const;
const_iterator end() const;
private:
void PushInternal(permissions::PermissionRequest* request);
base::circular_deque<PermissionRequest*> queued_requests_;
};
} // namespace permissions
#endif // COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_QUEUE_H_
|