Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: ios/web/active_state_manager_impl.mm

Issue 2251023003: Remove single active state restriction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ios/web/active_state_manager_impl.h" 5 #include "ios/web/active_state_manager_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ios/web/public/browser_state.h" 8 #include "ios/web/public/browser_state.h"
9 #include "ios/web/public/web_thread.h" 9 #include "ios/web/public/web_thread.h"
10 10
11 namespace web { 11 namespace web {
12 12
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
18
19 ActiveStateManagerImpl::ActiveStateManagerImpl(BrowserState* browser_state) 13 ActiveStateManagerImpl::ActiveStateManagerImpl(BrowserState* browser_state)
20 : browser_state_(browser_state), active_(false) { 14 : browser_state_(browser_state), active_(false) {
21 DCHECK_CURRENTLY_ON(WebThread::UI); 15 DCHECK_CURRENTLY_ON(WebThread::UI);
22 DCHECK(browser_state_); 16 DCHECK(browser_state_);
23 } 17 }
24 18
25 ActiveStateManagerImpl::~ActiveStateManagerImpl() { 19 ActiveStateManagerImpl::~ActiveStateManagerImpl() {
26 FOR_EACH_OBSERVER(Observer, observer_list_, WillBeDestroyed()); 20 FOR_EACH_OBSERVER(Observer, observer_list_, WillBeDestroyed());
27 DCHECK(!IsActive()); 21 DCHECK(!IsActive());
28 } 22 }
29 23
30 void ActiveStateManagerImpl::SetActive(bool active) { 24 void ActiveStateManagerImpl::SetActive(bool active) {
31 DCHECK_CURRENTLY_ON(WebThread::UI); 25 DCHECK_CURRENTLY_ON(WebThread::UI);
32 26
33 if (active == active_) { 27 if (active == active_) {
34 return; 28 return;
35 } 29 }
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; 30 active_ = active;
43 31
44 if (active) { 32 if (active) {
45 FOR_EACH_OBSERVER(Observer, observer_list_, OnActive()); 33 FOR_EACH_OBSERVER(Observer, observer_list_, OnActive());
46 } else { 34 } else {
47 FOR_EACH_OBSERVER(Observer, observer_list_, OnInactive()); 35 FOR_EACH_OBSERVER(Observer, observer_list_, OnInactive());
48 } 36 }
49 } 37 }
50 38
51 bool ActiveStateManagerImpl::IsActive() { 39 bool ActiveStateManagerImpl::IsActive() {
52 DCHECK_CURRENTLY_ON(WebThread::UI); 40 DCHECK_CURRENTLY_ON(WebThread::UI);
53 return active_; 41 return active_;
54 } 42 }
55 43
56 void ActiveStateManagerImpl::AddObserver(ActiveStateManager::Observer* obs) { 44 void ActiveStateManagerImpl::AddObserver(ActiveStateManager::Observer* obs) {
57 DCHECK_CURRENTLY_ON(WebThread::UI); 45 DCHECK_CURRENTLY_ON(WebThread::UI);
58 observer_list_.AddObserver(obs); 46 observer_list_.AddObserver(obs);
59 } 47 }
60 48
61 void ActiveStateManagerImpl::RemoveObserver(ActiveStateManager::Observer* obs) { 49 void ActiveStateManagerImpl::RemoveObserver(ActiveStateManager::Observer* obs) {
62 DCHECK_CURRENTLY_ON(WebThread::UI); 50 DCHECK_CURRENTLY_ON(WebThread::UI);
63 observer_list_.RemoveObserver(obs); 51 observer_list_.RemoveObserver(obs);
64 } 52 }
65 53
66 } // namespace web 54 } // namespace web
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698