Update V8 to version 4.5.34.
[chromium-blink-merge.git] / ios / web / active_state_manager_impl.mm
blob0553038c54d75843dc20fa1d8276dbc78e54b4ca
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 #include "ios/web/active_state_manager_impl.h"
7 #include "base/logging.h"
8 #include "ios/web/public/browser_state.h"
9 #include "ios/web/public/web_thread.h"
11 namespace web {
13 namespace {
14 // The number of ActiveStateManagers that are currently in active state.
15 // At most one ActiveStateManager can be active at any given time.
16 int g_active_state_manager_active_count = 0;
17 }  // namespace
19 ActiveStateManagerImpl::ActiveStateManagerImpl(BrowserState* browser_state)
20     : browser_state_(browser_state), active_(false) {
21   DCHECK_CURRENTLY_ON_WEB_THREAD(WebThread::UI);
22   DCHECK(browser_state_);
25 ActiveStateManagerImpl::~ActiveStateManagerImpl() {
26   FOR_EACH_OBSERVER(Observer, observer_list_, WillBeDestroyed());
27   DCHECK(!IsActive());
30 void ActiveStateManagerImpl::SetActive(bool active) {
31   DCHECK_CURRENTLY_ON_WEB_THREAD(WebThread::UI);
33   if (active == active_) {
34     return;
35   }
36   if (active) {
37     ++g_active_state_manager_active_count;
38   } else {
39     --g_active_state_manager_active_count;
40   }
41   DCHECK_GE(1, g_active_state_manager_active_count);
42   active_ = active;
44   if (active) {
45     FOR_EACH_OBSERVER(Observer, observer_list_, OnActive());
46   } else {
47     FOR_EACH_OBSERVER(Observer, observer_list_, OnInactive());
48   }
51 bool ActiveStateManagerImpl::IsActive() {
52   DCHECK_CURRENTLY_ON_WEB_THREAD(WebThread::UI);
53   return active_;
56 void ActiveStateManagerImpl::AddObserver(Observer* obs) {
57   DCHECK_CURRENTLY_ON_WEB_THREAD(WebThread::UI);
58   observer_list_.AddObserver(obs);
61 void ActiveStateManagerImpl::RemoveObserver(Observer* obs) {
62   DCHECK_CURRENTLY_ON_WEB_THREAD(WebThread::UI);
63   observer_list_.RemoveObserver(obs);
66 }  // namespace web