File: frame_token_message_queue.cc

package info (click to toggle)
chromium-browser 70.0.3538.110-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,619,476 kB
  • sloc: cpp: 13,024,755; ansic: 1,349,823; python: 916,672; xml: 314,489; java: 280,047; asm: 276,936; perl: 75,771; objc: 66,634; sh: 45,860; cs: 28,354; php: 11,064; makefile: 10,911; yacc: 9,109; tcl: 8,403; ruby: 4,065; lex: 1,779; pascal: 1,411; lisp: 1,055; awk: 41; jsp: 39; sed: 17; sql: 3
file content (76 lines) | stat: -rw-r--r-- 2,305 bytes parent folder | download | duplicates (2)
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
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/renderer_host/frame_token_message_queue.h"

#include "ipc/ipc_message.h"

namespace content {

FrameTokenMessageQueue::FrameTokenMessageQueue(Client* client)
    : client_(client) {}

FrameTokenMessageQueue::~FrameTokenMessageQueue() {}

void FrameTokenMessageQueue::DidProcessFrame(uint32_t frame_token) {
  // Frame tokens always increase.
  if (frame_token <= last_received_frame_token_) {
    client_->OnInvalidFrameToken(frame_token);
    return;
  }

  last_received_frame_token_ = frame_token;

  // Gets the first callback associated with a token after |frame_token| or
  // callback_map_.end().
  auto upper_bound = callback_map_.upper_bound(frame_token);

  // std::multimap already sorts on keys, so this will process all enqueued
  // messages up to the current frame token.
  for (auto it = callback_map_.begin(); it != upper_bound; ++it)
    std::move(it->second).Run();

  // Clear all callbacks up to the current frame token.
  callback_map_.erase(callback_map_.begin(), upper_bound);
}

void FrameTokenMessageQueue::EnqueueOrRunFrameTokenCallback(
    uint32_t frame_token,
    base::OnceClosure callback) {
  // Zero token is invalid.
  if (!frame_token) {
    client_->OnInvalidFrameToken(frame_token);
    return;
  }

  if (frame_token <= last_received_frame_token_) {
    std::move(callback).Run();
    return;
  }
  callback_map_.insert(std::make_pair(frame_token, std::move(callback)));
}

void FrameTokenMessageQueue::OnFrameSwapMessagesReceived(
    uint32_t frame_token,
    std::vector<IPC::Message> messages) {
  EnqueueOrRunFrameTokenCallback(
      frame_token, base::BindOnce(&FrameTokenMessageQueue::ProcessSwapMessages,
                                  base::Unretained(this), std::move(messages)));
}

void FrameTokenMessageQueue::Reset() {
  last_received_frame_token_ = 0;
  callback_map_.clear();
}

void FrameTokenMessageQueue::ProcessSwapMessages(
    std::vector<IPC::Message> messages) {
  for (const IPC::Message& i : messages) {
    client_->OnProcessSwapMessage(i);
    if (i.dispatch_error())
      client_->OnMessageDispatchError(i);
  }
}

}  // namespace content