summaryrefslogtreecommitdiffstats
path: root/ios/web/active_state_manager_impl.h
blob: 3a383384706dc58487512e3d889fbe1e9642f201 (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
// 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 IOS_WEB_ACTIVE_STATE_MANAGER_IMPL_H_
#define IOS_WEB_ACTIVE_STATE_MANAGER_IMPL_H_

#include "base/macros.h"
#include "base/observer_list.h"
#include "base/supports_user_data.h"
#include "ios/web/public/active_state_manager.h"

namespace web {

class BrowserState;

// Concrete subclass of web::ActiveStateManager. Informs observers when an
// ActiveStateManager becomes active/inactive.
class ActiveStateManagerImpl : public ActiveStateManager,
                               public base::SupportsUserData::Data {
 public:
  explicit ActiveStateManagerImpl(BrowserState* browser_state);
  ~ActiveStateManagerImpl() override;

  // ActiveStateManager methods.
  void SetActive(bool active) override;
  bool IsActive() override;
  void AddObserver(ActiveStateManager::Observer* observer) override;
  void RemoveObserver(ActiveStateManager::Observer* observer) override;

 private:
  BrowserState* browser_state_;  // weak, owns this object.
  // true if the ActiveStateManager is active.
  bool active_;
  // The list of observers.
  base::ObserverList<Observer> observer_list_;

  DISALLOW_COPY_AND_ASSIGN(ActiveStateManagerImpl);
};

}  // namespace web

#endif  // IOS_WEB_ACTIVE_STATE_MANAGER_IMPL_H_