[Android WebViewShell] Add inclusion test for webview exposed stable interfaces.
[chromium-blink-merge.git] / ios / web / active_state_manager_impl.h
blob564f55bbcfd4a1122009b8f4118758c4c47a202e
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_ACTIVE_STATE_MANAGER_IMPL_H_
6 #define IOS_WEB_ACTIVE_STATE_MANAGER_IMPL_H_
8 #include "base/macros.h"
9 #include "base/observer_list.h"
10 #include "base/supports_user_data.h"
11 #include "ios/web/public/active_state_manager.h"
13 namespace web {
15 class BrowserState;
17 // Concrete subclass of web::ActiveStateManager. Informs observers when an
18 // ActiveStateManager becomes active/inactive.
19 class ActiveStateManagerImpl : public ActiveStateManager,
20 public base::SupportsUserData::Data {
21 public:
22 explicit ActiveStateManagerImpl(BrowserState* browser_state);
23 ~ActiveStateManagerImpl() override;
25 // ActiveStateManager methods.
26 void SetActive(bool active) override;
27 bool IsActive() override;
29 // Observer that is notified when a ActiveStateManager becomes active,
30 // inactive or destroyed.
31 class Observer {
32 public:
33 // Called when the ActiveStateManager becomes active.
34 virtual void OnActive() = 0;
35 // Called when the ActiveStateManager becomes inactive.
36 virtual void OnInactive() = 0;
37 // Called just before the ActiveStateManager is destroyed.
38 virtual void WillBeDestroyed() = 0;
40 // Adds an observer for this class. An observer should not be added more
41 // than once. The caller retains the ownership of the observer object.
42 void AddObserver(Observer* obs);
43 // Removes an observer.
44 void RemoveObserver(Observer* obs);
46 private:
47 BrowserState* browser_state_; // weak, owns this object.
48 // true if the ActiveStateManager is active.
49 bool active_;
50 // The list of observers.
51 base::ObserverList<Observer> observer_list_;
53 DISALLOW_COPY_AND_ASSIGN(ActiveStateManagerImpl);
56 } // namespace web
58 #endif // IOS_WEB_ACTIVE_STATE_MANAGER_IMPL_H_