summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sessions/session_restore_test_helper.h
blob: 63b60a46297256dce5ef0dd08d77bea911d12a49 (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
// Copyright 2015 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.

#ifndef CHROME_BROWSER_SESSIONS_SESSION_RESTORE_TEST_HELPER_H_
#define CHROME_BROWSER_SESSIONS_SESSION_RESTORE_TEST_HELPER_H_

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/sessions/session_restore.h"

namespace content {
class MessageLoopRunner;
}

// This class waits on the SessionRestore notification. It is a replacement for
// content::WindowedNotificationObserver, which uses notification service. This
// class uses the callback-based notification instead.
class SessionRestoreTestHelper {
 public:
  SessionRestoreTestHelper();
  ~SessionRestoreTestHelper();

  // Blocks until OnSessionRestore() is called.
  void Wait();

 private:
  // Callback for session restore notifications.
  void OnSessionRestoreDone(int /* num_tabs_restored */);

  // Indicates whether a session restore notification has been received.
  bool restore_notification_seen_;

  // Indicates whether |message_loop_runner_| is running.
  bool loop_is_running_;

  // Loop that runs while waiting for notification callback.
  scoped_refptr<content::MessageLoopRunner> message_loop_runner_;

  // For automatically unsubscribing from callback-based notifications.
  SessionRestore::CallbackSubscription callback_subscription_;

  // For safely binding pointers to callbacks.
  base::WeakPtrFactory<SessionRestoreTestHelper> weak_ptr_factory;

  DISALLOW_COPY_AND_ASSIGN(SessionRestoreTestHelper);
};

#endif  // CHROME_BROWSER_SESSIONS_SESSION_RESTORE_TEST_HELPER_H_