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

content / public / test / commit_message_delayer.h [blame]

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_PUBLIC_TEST_COMMIT_MESSAGE_DELAYER_H_
#define CONTENT_PUBLIC_TEST_COMMIT_MESSAGE_DELAYER_H_

#include <memory>

#include "base/functional/callback.h"
#include "url/gurl.h"

namespace content {

class RenderFrameHost;
class WebContents;

// A helper class to run a predefined callback just before processing the
// DidCommitProvisionalLoad IPC for |deferred_url|.
class CommitMessageDelayer {
 public:
  using DidCommitCallback = base::OnceCallback<void(RenderFrameHost*)>;

  // Starts monitoring |web_contents| for DidCommit IPC and executes
  // |deferred_action| for each DidCommit IPC that matches |deferred_url|.
  explicit CommitMessageDelayer(WebContents* web_contents,
                                const GURL& deferred_url,
                                DidCommitCallback deferred_action);
  ~CommitMessageDelayer();

  CommitMessageDelayer(const CommitMessageDelayer&) = delete;
  CommitMessageDelayer& operator=(const CommitMessageDelayer&) = delete;

  // Waits until DidCommit IPC arrives for |deferred_url|, then calls
  // |deferred_action|, then handles the IPC, then returns.
  void Wait();

 private:
  class Impl;
  std::unique_ptr<Impl> impl_;
};

}  // namespace content

#endif  // CONTENT_PUBLIC_TEST_COMMIT_MESSAGE_DELAYER_H_