Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/dom/DocumentLifecycle.h" | 32 #include "core/dom/DocumentLifecycle.h" |
| 33 | 33 |
| 34 #include "platform/RuntimeEnabledFeatures.h" | 34 #include "platform/RuntimeEnabledFeatures.h" |
| 35 #include "wtf/Assertions.h" | 35 #include "wtf/Assertions.h" |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 static DocumentLifecycle::DeprecatedTransition* s_deprecatedTransitionStack = 0; | 39 static DocumentLifecycle::DeprecatedTransition* s_deprecatedTransitionStack = 0; |
| 40 | 40 |
| 41 // TODO(skyostil): Come up with a better way to store cross-frame lifecycle | |
| 42 // related data to avoid this being a global setting. | |
| 43 static unsigned s_preventThrottlingCount = 0; | |
| 44 | |
| 41 DocumentLifecycle::Scope::Scope(DocumentLifecycle& lifecycle, State finalState) | 45 DocumentLifecycle::Scope::Scope(DocumentLifecycle& lifecycle, State finalState) |
| 42 : m_lifecycle(lifecycle) | 46 : m_lifecycle(lifecycle) |
| 43 , m_finalState(finalState) | 47 , m_finalState(finalState) |
| 44 { | 48 { |
| 45 } | 49 } |
| 46 | 50 |
| 47 DocumentLifecycle::Scope::~Scope() | 51 DocumentLifecycle::Scope::~Scope() |
| 48 { | 52 { |
| 49 m_lifecycle.advanceTo(m_finalState); | 53 m_lifecycle.advanceTo(m_finalState); |
| 50 } | 54 } |
| 51 | 55 |
| 52 DocumentLifecycle::DeprecatedTransition::DeprecatedTransition(State from, State to) | 56 DocumentLifecycle::DeprecatedTransition::DeprecatedTransition(State from, State to) |
| 53 : m_previous(s_deprecatedTransitionStack) | 57 : m_previous(s_deprecatedTransitionStack) |
| 54 , m_from(from) | 58 , m_from(from) |
| 55 , m_to(to) | 59 , m_to(to) |
| 56 { | 60 { |
| 57 s_deprecatedTransitionStack = this; | 61 s_deprecatedTransitionStack = this; |
| 58 } | 62 } |
| 59 | 63 |
| 60 DocumentLifecycle::DeprecatedTransition::~DeprecatedTransition() | 64 DocumentLifecycle::DeprecatedTransition::~DeprecatedTransition() |
| 61 { | 65 { |
| 62 s_deprecatedTransitionStack = m_previous; | 66 s_deprecatedTransitionStack = m_previous; |
| 63 } | 67 } |
| 64 | 68 |
| 69 DocumentLifecycle::PreventThrottlingScope::PreventThrottlingScope(DocumentLifecy cle& lifecycle) | |
| 70 : m_lifecycle(lifecycle) | |
| 71 { | |
| 72 m_lifecycle.incrementPreventThrottlingCount(); | |
|
esprehn
2015/10/16 21:40:45
if you're going to put these out of line you don't
Sami
2015/10/19 10:51:06
Ah, of course. Done.
| |
| 73 } | |
| 74 | |
| 75 DocumentLifecycle::PreventThrottlingScope::~PreventThrottlingScope() | |
| 76 { | |
| 77 m_lifecycle.decrementPreventThrottlingCount(); | |
| 78 } | |
| 79 | |
| 65 DocumentLifecycle::DocumentLifecycle() | 80 DocumentLifecycle::DocumentLifecycle() |
| 66 : m_state(Uninitialized) | 81 : m_state(Uninitialized) |
| 67 , m_detachCount(0) | 82 , m_detachCount(0) |
| 68 { | 83 { |
| 69 } | 84 } |
| 70 | 85 |
| 71 DocumentLifecycle::~DocumentLifecycle() | 86 DocumentLifecycle::~DocumentLifecycle() |
| 72 { | 87 { |
| 73 } | 88 } |
| 74 | 89 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 void DocumentLifecycle::ensureStateAtMost(State state) | 299 void DocumentLifecycle::ensureStateAtMost(State state) |
| 285 { | 300 { |
| 286 ASSERT(state == VisualUpdatePending || state == StyleClean || state == Layou tClean); | 301 ASSERT(state == VisualUpdatePending || state == StyleClean || state == Layou tClean); |
| 287 if (m_state <= state) | 302 if (m_state <= state) |
| 288 return; | 303 return; |
| 289 ASSERT_WITH_MESSAGE(canRewindTo(state), | 304 ASSERT_WITH_MESSAGE(canRewindTo(state), |
| 290 "Cannot rewind document lifecycle from %s to %s.", stateAsDebugString(m_ state), stateAsDebugString(state)); | 305 "Cannot rewind document lifecycle from %s to %s.", stateAsDebugString(m_ state), stateAsDebugString(state)); |
| 291 m_state = state; | 306 m_state = state; |
| 292 } | 307 } |
| 293 | 308 |
| 309 void DocumentLifecycle::incrementPreventThrottlingCount() | |
| 310 { | |
| 311 s_preventThrottlingCount++; | |
| 312 } | |
| 313 | |
| 314 void DocumentLifecycle::decrementPreventThrottlingCount() | |
| 315 { | |
| 316 ASSERT(s_preventThrottlingCount > 0); | |
| 317 s_preventThrottlingCount--; | |
| 318 } | |
| 319 | |
| 320 bool DocumentLifecycle::throttlingAllowed() const | |
| 321 { | |
| 322 return !s_preventThrottlingCount; | |
| 323 } | |
| 324 | |
| 294 #if ENABLE(ASSERT) | 325 #if ENABLE(ASSERT) |
| 295 #define DEBUG_STRING_CASE(StateName) \ | 326 #define DEBUG_STRING_CASE(StateName) \ |
| 296 case StateName: return #StateName | 327 case StateName: return #StateName |
| 297 | 328 |
| 298 const char* DocumentLifecycle::stateAsDebugString(const State state) | 329 const char* DocumentLifecycle::stateAsDebugString(const State state) |
| 299 { | 330 { |
| 300 switch (state) { | 331 switch (state) { |
| 301 DEBUG_STRING_CASE(Uninitialized); | 332 DEBUG_STRING_CASE(Uninitialized); |
| 302 DEBUG_STRING_CASE(Inactive); | 333 DEBUG_STRING_CASE(Inactive); |
| 303 DEBUG_STRING_CASE(VisualUpdatePending); | 334 DEBUG_STRING_CASE(VisualUpdatePending); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 323 DEBUG_STRING_CASE(Stopped); | 354 DEBUG_STRING_CASE(Stopped); |
| 324 DEBUG_STRING_CASE(Disposed); | 355 DEBUG_STRING_CASE(Disposed); |
| 325 } | 356 } |
| 326 | 357 |
| 327 ASSERT_NOT_REACHED(); | 358 ASSERT_NOT_REACHED(); |
| 328 return "Unknown"; | 359 return "Unknown"; |
| 329 } | 360 } |
| 330 #endif | 361 #endif |
| 331 | 362 |
| 332 } | 363 } |
| OLD | NEW |