1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SYNC_TEST_SESSIONS_TEST_SCOPED_SESSION_EVENT_LISTENER_H_
6#define SYNC_TEST_SESSIONS_TEST_SCOPED_SESSION_EVENT_LISTENER_H_
7
8#include "sync/sessions/sync_session_context.h"
9
10namespace syncer {
11namespace sessions {
12
13// Installs a SyncEventListener to a given session context for the lifetime of
14// the TestScopedSessionEventListener.
15class TestScopedSessionEventListener {
16 public:
17  TestScopedSessionEventListener(
18      SyncSessionContext* context,
19      SyncEngineEventListener* listener)
20    : context_(context), listener_(listener) {
21      context->listeners_.AddObserver(listener);
22  }
23  ~TestScopedSessionEventListener() {
24    context_->listeners_.RemoveObserver(listener_);
25  }
26 private:
27  SyncSessionContext* context_;
28  SyncEngineEventListener* listener_;
29  DISALLOW_COPY_AND_ASSIGN(TestScopedSessionEventListener);
30};
31
32}  // namespace sessions
33}  // namespace syncer
34
35#endif  // SYNC_TEST_SESSIONS_TEST_SCOPED_SESSION_EVENT_LISTENER_H_
36