Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / ios / web / public / active_state_manager.h
blob325e936d8749f19e1d02de94de8bb311ccdbc077
1 // Copyright 2015 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.
5 #ifndef IOS_WEB_PUBLIC_ACTIVE_STATE_MANAGER_H_
6 #define IOS_WEB_PUBLIC_ACTIVE_STATE_MANAGER_H_
8 #include "base/macros.h"
10 namespace web {
12 class BrowserState;
14 // Manages the active state associated with a particular BrowserState. Not
15 // thread safe. Must be used only on the main thread.
16 class ActiveStateManager {
17 public:
18 // Sets the active state of the ActiveStateManager. At most one
19 // ActiveStateManager can be active at any given time in the app. A
20 // ActiveStateManager must be made inactive before it is destroyed. It is
21 // valid to call |SetActive(true)| on an already active ActiveStateManager.
22 virtual void SetActive(bool active) = 0;
23 // Returns true if the BrowserState is active.
24 virtual bool IsActive() = 0;
26 // Observer that is notified when a ActiveStateManager becomes active,
27 // inactive or destroyed.
28 class Observer {
29 public:
30 // Called when the ActiveStateManager becomes active.
31 virtual void OnActive() {}
32 // Called when the ActiveStateManager becomes inactive.
33 virtual void OnInactive() {}
34 // Called just before the ActiveStateManager is destroyed.
35 virtual void WillBeDestroyed() {}
37 // Adds an observer for this class. An observer should not be added more
38 // than once. The caller retains the ownership of the observer object.
39 virtual void AddObserver(Observer* observer) = 0;
40 // Removes an observer.
41 virtual void RemoveObserver(Observer* observer) = 0;
43 protected:
44 virtual ~ActiveStateManager(){};
47 } // namespace web
49 #endif // IOS_WEB_PUBLIC_ACTIVE_STATE_MANAGER_H_