Ensure favicon images are correctly used and downloaded when syncing bookmark apps.
[chromium-blink-merge.git] / ios / web / active_state_manager_impl.mm
blob258244747be5a718fe435f75cc4273901406fb6d
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(ActiveStateManager::Observer* obs) {
57   DCHECK_CURRENTLY_ON_WEB_THREAD(WebThread::UI);
58   observer_list_.AddObserver(obs);
61 void ActiveStateManagerImpl::RemoveObserver(ActiveStateManager::Observer* obs) {
62   DCHECK_CURRENTLY_ON_WEB_THREAD(WebThread::UI);
63   observer_list_.RemoveObserver(obs);
66 }  // namespace web