Commit 13e4c0c7 authored by barraclough@apple.com's avatar barraclough@apple.com

Source/WebCore: Refactor NSActivity handling code from ChildProcess to UserActivity

https://bugs.webkit.org/show_bug.cgi?id=126330

Reviewed by Sam Weinig.

UserActivity is a mechanism to express to the operating system (where appropriate)
that a user initiated activity is taking place, and as such that resources should be
made available to the process accordingly.

Currently we hold a single NSActivity, at the WebKit layer. This refactoring allows us
to hold different activity tokens for different user actions (which simplifies the
handling, and aides debugging since the token can more accurately express the activity
taking place), and also will allow us to avoid the layering difficulty of calling back
up the stack to WebKit to register that an activity is taking place.

* WebCore.xcodeproj/project.pbxproj:
    - added new files.
* platform/UserActivity.cpp: Added.
(WebCore::UserActivity::UserActivity):
    - nop implementation - ignore description.
(WebCore::UserActivity::beginActivity):
(WebCore::UserActivity::endActivity):
    - nop implementation - just inc/dec m_count.
* platform/UserActivity.h: Added.
(WebCore::UserActivity::isActive):
    - returns true if one or more instance of this activity is in progress.
* platform/mac/UserActivityMac.mm: Added.
(WebCore::UserActivity::UserActivity):
    - constructor accepts one argument, a description string.
(WebCore::UserActivity::isValid):
    - used by assertions.
(WebCore::UserActivity::beginActivity):
(WebCore::UserActivity::endActivity):
    - track start/end of an activity - calls to these methods should be balanced.
(WebCore::UserActivity::hysteresisTimerFired):
      - used to implement hysteresis in releasing  NSActivity.

Source/WebKit2: VibrationPattern should allocate an single vector instance for single integer input
https://bugs.webkit.org/show_bug.cgi?id=126417

Patch by Jinwoo Song <jinwoo7.song@samsung.com> on 2014-01-03
Reviewed by Gyuyoung Kim.

Fix a vibration unit test regression after r161139. Also remove unnecessary test cases. 

* UIProcess/API/efl/tests/test_ewk2_view.cpp:
(EWK2ViewTest::loadVibrationHTMLString):
(TEST_F):

Source/WTF: Refactor NSActivity handling code from ChildProcess to UserActivity
https://bugs.webkit.org/show_bug.cgi?id=126330

Reviewed by Sam Weinig.

UserActivity is a mechanism to express to the operating system (where appropriate)
that a user initiated activity is taking place, and as such that resources should be
made available to the process accordingly.

Currently we hold a single NSActivity, at the WebKit layer. This refactoring allows us
to hold different activity tokens for different user actions (which simplifies the
handling, and aides debugging since the token can more accurately express the activity
taking place), and also will allow us to avoid the layering difficulty of calling back
up the stack to WebKit to register that an activity is taking place.

* wtf/Platform.h:
    - added HAVE_NS_ACTIVITY.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@161271 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2f9d9b63
2014-01-02 Gavin Barraclough <barraclough@apple.com>
Refactor NSActivity handling code from ChildProcess to UserActivity
https://bugs.webkit.org/show_bug.cgi?id=126330
Reviewed by Sam Weinig.
UserActivity is a mechanism to express to the operating system (where appropriate)
that a user initiated activity is taking place, and as such that resources should be
made available to the process accordingly.
Currently we hold a single NSActivity, at the WebKit layer. This refactoring allows us
to hold different activity tokens for different user actions (which simplifies the
handling, and aides debugging since the token can more accurately express the activity
taking place), and also will allow us to avoid the layering difficulty of calling back
up the stack to WebKit to register that an activity is taking place.
* wtf/Platform.h:
- added HAVE_NS_ACTIVITY.
2013-12-30 Commit Queue <commit-queue@webkit.org>
Unreviewed, rolling out r161157, r161158, r161160, r161161,
......
......@@ -1078,4 +1078,8 @@
#define _HAS_EXCEPTIONS 1
#endif
#if PLATFORM(MAC) && !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
#define HAVE_NS_ACTIVITY 1
#endif
#endif /* WTF_Platform_h */
......@@ -1841,6 +1841,7 @@ set(WebCore_SOURCES
platform/ThreadGlobalData.cpp
platform/ThreadTimers.cpp
platform/Timer.cpp
platform/UserActivity.cpp
platform/UUID.cpp
platform/Widget.cpp
......
2014-01-02 Gavin Barraclough <barraclough@apple.com>
Refactor NSActivity handling code from ChildProcess to UserActivity
https://bugs.webkit.org/show_bug.cgi?id=126330
Reviewed by Sam Weinig.
UserActivity is a mechanism to express to the operating system (where appropriate)
that a user initiated activity is taking place, and as such that resources should be
made available to the process accordingly.
Currently we hold a single NSActivity, at the WebKit layer. This refactoring allows us
to hold different activity tokens for different user actions (which simplifies the
handling, and aides debugging since the token can more accurately express the activity
taking place), and also will allow us to avoid the layering difficulty of calling back
up the stack to WebKit to register that an activity is taking place.
* WebCore.xcodeproj/project.pbxproj:
- added new files.
* platform/UserActivity.cpp: Added.
(WebCore::UserActivity::UserActivity):
- nop implementation - ignore description.
(WebCore::UserActivity::beginActivity):
(WebCore::UserActivity::endActivity):
- nop implementation - just inc/dec m_count.
* platform/UserActivity.h: Added.
(WebCore::UserActivity::isActive):
- returns true if one or more instance of this activity is in progress.
* platform/mac/UserActivityMac.mm: Added.
(WebCore::UserActivity::UserActivity):
- constructor accepts one argument, a description string.
(WebCore::UserActivity::isValid):
- used by assertions.
(WebCore::UserActivity::beginActivity):
(WebCore::UserActivity::endActivity):
- track start/end of an activity - calls to these methods should be balanced.
(WebCore::UserActivity::hysteresisTimerFired):
- used to implement hysteresis in releasing NSActivity.
2014-01-03 Alexey Proskuryakov <ap@apple.com>
Line ending conversion should be able to handle strings with null chars
......@@ -5531,7 +5531,9 @@ webcore_platform_sources += \
Source/WebCore/platform/ScrollAnimatorNone.cpp \
Source/WebCore/platform/ScrollAnimatorNone.h \
Source/WebCore/platform/ThreadGlobalData.cpp \
Source/WebCore/platform/ThreadGlobalData.h
Source/WebCore/platform/ThreadGlobalData.h \
Source/WebCore/platform/UserActivity.cpp \
Source/WebCore/platform/UserActivity.h
platform_sources += \
Source/WebCore/platform/animation/AnimationUtilities.h \
......
......@@ -245,6 +245,9 @@ __ZN7WebCore12TextIterator7advanceEv
__ZN7WebCore12TextIterator8subrangeEPNS_5RangeEii
__ZN7WebCore12TextIteratorC1EPKNS_5RangeENS_20TextIteratorBehaviorE
__ZN7WebCore12TextIteratorD1Ev
__ZN7WebCore12UserActivity11endActivityEv
__ZN7WebCore12UserActivity13beginActivityEv
__ZN7WebCore12UserActivityC1EPKc
__ZN7WebCore12UTF8EncodingEv
__ZN7WebCore12WorkerThread17workerThreadCountEv
__ZN7WebCore12cacheStorageEv
......
......@@ -2860,6 +2860,9 @@
861C2EA613FB4FFF00062ABB /* ResourceLoadTiming.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 861C2EA513FB4FFF00062ABB /* ResourceLoadTiming.cpp */; };
86512EDE154A2AEF00A90426 /* PerformanceResourceTiming.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 86512EDB154A2AEE00A90426 /* PerformanceResourceTiming.cpp */; };
86512EDF154A2AEF00A90426 /* PerformanceResourceTiming.h in Headers */ = {isa = PBXBuildFile; fileRef = 86512EDC154A2AEF00A90426 /* PerformanceResourceTiming.h */; };
868160D418766A0A0021E79D /* UserActivity.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 868160D1187669C40021E79D /* UserActivity.cpp */; };
868160D518766A0E0021E79D /* UserActivityMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 868160D3187669E70021E79D /* UserActivityMac.mm */; };
868160D618766A130021E79D /* UserActivity.h in Headers */ = {isa = PBXBuildFile; fileRef = 868160D2187669C40021E79D /* UserActivity.h */; settings = {ATTRIBUTES = (Private, ); }; };
86BA766E166427A8005BE5D1 /* FrameLoadRequest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 86BA766D166427A8005BE5D1 /* FrameLoadRequest.cpp */; };
86BE340115058CB200CE0FD8 /* PerformanceEntry.h in Headers */ = {isa = PBXBuildFile; fileRef = 86BE33FB15058CB200CE0FD8 /* PerformanceEntry.h */; };
86BE340315058CB200CE0FD8 /* PerformanceEntryList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 86BE33FD15058CB200CE0FD8 /* PerformanceEntryList.cpp */; };
......@@ -9648,6 +9651,9 @@
86512EDB154A2AEE00A90426 /* PerformanceResourceTiming.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PerformanceResourceTiming.cpp; sourceTree = "<group>"; };
86512EDC154A2AEF00A90426 /* PerformanceResourceTiming.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PerformanceResourceTiming.h; sourceTree = "<group>"; };
86512EDD154A2AEF00A90426 /* PerformanceResourceTiming.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = PerformanceResourceTiming.idl; sourceTree = "<group>"; };
868160D1187669C40021E79D /* UserActivity.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = UserActivity.cpp; sourceTree = "<group>"; };
868160D2187669C40021E79D /* UserActivity.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UserActivity.h; sourceTree = "<group>"; };
868160D3187669E70021E79D /* UserActivityMac.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = UserActivityMac.mm; sourceTree = "<group>"; };
86BA766D166427A8005BE5D1 /* FrameLoadRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FrameLoadRequest.cpp; sourceTree = "<group>"; };
86BE33FB15058CB200CE0FD8 /* PerformanceEntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PerformanceEntry.h; sourceTree = "<group>"; };
86BE33FC15058CB200CE0FD8 /* PerformanceEntry.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = PerformanceEntry.idl; sourceTree = "<group>"; };
......@@ -15721,6 +15727,7 @@
BCE659E50EA92FB2007E4533 /* ThemeMac.h */,
BCE659E80EA92FFA007E4533 /* ThemeMac.mm */,
51DF6D7F0B92A18E00C2DC85 /* ThreadCheck.mm */,
868160D3187669E70021E79D /* UserActivityMac.mm */,
CDC69DD816371FD3007C38DF /* WebCoreFullScreenPlaceholderView.h */,
CDC69DD916371FD3007C38DF /* WebCoreFullScreenPlaceholderView.mm */,
CDC69DD41632026C007C38DF /* WebCoreFullScreenWarningView.h */,
......@@ -20437,6 +20444,8 @@
6593923509AE4346002C531F /* URL.cpp */,
6593923609AE4346002C531F /* URL.h */,
BCBD21AA0E417AD400A070F2 /* URLHash.h */,
868160D1187669C40021E79D /* UserActivity.cpp */,
868160D2187669C40021E79D /* UserActivity.h */,
2E3BBF051162DA1100B9409A /* UUID.cpp */,
2E3BBF061162DA1100B9409A /* UUID.h */,
9A1142031832D134000BB8AD /* ValueToString.h */,
......@@ -22593,6 +22602,7 @@
E49BD9FA131FD2ED003C56F0 /* CSSValuePool.h in Headers */,
93F1992F08245E59001E9ABC /* Cursor.h in Headers */,
BC2272A20E82E87C00E7F975 /* CursorData.h in Headers */,
868160D618766A130021E79D /* UserActivity.h in Headers */,
BC2272AD0E82E8F300E7F975 /* CursorList.h in Headers */,
62CD325A1157E57C0063B0A7 /* CustomEvent.h in Headers */,
15B3FC1915FB217800A81BCB /* CustomFilterArrayParameter.h in Headers */,
......@@ -26333,6 +26343,7 @@
859A9C500AA5E3BD00B694B2 /* DOMHTMLStyleElement.mm in Sources */,
85DF821E0AA7849E00486AD7 /* DOMHTMLTableCaptionElement.mm in Sources */,
85DF82200AA7849E00486AD7 /* DOMHTMLTableCellElement.mm in Sources */,
868160D418766A0A0021E79D /* UserActivity.cpp in Sources */,
85DF82220AA7849E00486AD7 /* DOMHTMLTableColElement.mm in Sources */,
85DF82710AA78B8B00486AD7 /* DOMHTMLTableElement.mm in Sources */,
85DF82240AA7849E00486AD7 /* DOMHTMLTableRowElement.mm in Sources */,
......@@ -26401,6 +26412,7 @@
498391510F1E76B400C23782 /* DOMWebKitCSSMatrix.mm in Sources */,
8AD0A59714C88358000D83C5 /* DOMWebKitCSSRegionRule.mm in Sources */,
31611E620E1C4E1400F6A579 /* DOMWebKitCSSTransformValue.mm in Sources */,
868160D518766A0E0021E79D /* UserActivityMac.mm in Sources */,
3F2B33EC165AF15600E3987C /* DOMWebKitCSSViewportRule.mm in Sources */,
8A195933147EA16E00D1EA61 /* DOMWebKitNamedFlow.mm in Sources */,
31C0FF4D0E4CEFDD007D6FE5 /* DOMWebKitTransitionEvent.mm in Sources */,
/*
* Copyright (C) 2014 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "UserActivity.h"
namespace WebCore {
#if !HAVE(NS_ACTIVITY)
UserActivity::UserActivity(const char*)
: m_count(0)
{
}
void UserActivity::beginActivity()
{
++m_count;
}
void UserActivity::endActivity()
{
ASSERT(m_count);
--m_count;
}
#endif
} // namespace WebCore
/*
* Copyright (C) 2014 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UserActivity_h
#define UserActivity_h
#if HAVE(NS_ACTIVITY)
#include <wtf/RetainPtr.h>
#include <wtf/Runloop.h>
OBJC_CLASS NSString;
#endif
namespace WebCore {
// The UserActivity type is used to indicate to the operating system that
// a user initiated or visible action is taking place, and as such that
// resources should be allocated to the process accordingly.
class UserActivity {
public:
UserActivity(const char* description);
void beginActivity();
void endActivity();
bool isActive() const { return m_count; }
private:
size_t m_count;
#if HAVE(NS_ACTIVITY)
void hysteresisTimerFired();
bool isValid();
RetainPtr<NSString> m_description;
RunLoop::Timer<UserActivity> m_timer;
RetainPtr<id> m_activity;
#endif
};
} // namespace WebCore
using WebCore::UserActivity;
#endif // UserActivity_h
/*
* Copyright (C) 2014 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "config.h"
#import "UserActivity.h"
namespace WebCore {
#if HAVE(NS_ACTIVITY)
static const double kHysteresisSeconds = 5.0;
UserActivity::UserActivity(const char* description)
: m_count(0)
, m_description([NSString stringWithUTF8String:description])
, m_timer(RunLoop::main(), this, &UserActivity::hysteresisTimerFired)
{
ASSERT(isValid());
}
bool UserActivity::isValid()
{
// If count is non-zero then we should be holding an activity, and the hysteresis timer should not be running.
// Else if count is zero then:
// (a) if we're holding an activity there should be an active timer to clear this,
// (b) if we're not holding an activity there should be no active timer.
return m_count ? m_activity && !m_timer.isActive() : !!m_activity == m_timer.isActive();
}
void UserActivity::beginActivity()
{
ASSERT(isValid());
++m_count;
if (m_timer.isActive())
m_timer.stop();
if (!m_activity) {
NSActivityOptions options = (NSActivityUserInitiatedAllowingIdleSystemSleep | NSActivityLatencyCritical) & ~(NSActivitySuddenTerminationDisabled | NSActivityAutomaticTerminationDisabled);
m_activity = [[NSProcessInfo processInfo] beginActivityWithOptions:options reason:m_description.get()];
}
ASSERT(isValid());
}
void UserActivity::endActivity()
{
ASSERT(m_count);
ASSERT(isValid());
if (!--m_count)
m_timer.startOneShot(kHysteresisSeconds);
ASSERT(isValid());
}
void UserActivity::hysteresisTimerFired()
{
ASSERT(isValid());
[[NSProcessInfo processInfo] endActivity:m_activity.get()];
m_activity.clear();
m_timer.stop();
ASSERT(isValid());
}
#endif
} // namespace WebCore
......@@ -79,6 +79,39 @@
(WebProcessTest::add):
* UIProcess/API/gtk/tests/WebProcessTest.h:
2014-01-02 Gavin Barraclough <barraclough@apple.com>
Refactor NSActivity handling code from ChildProcess to UserActivity
https://bugs.webkit.org/show_bug.cgi?id=126330
Reviewed by Sam Weinig.
UserActivity is a mechanism to express to the operating system (where appropriate)
that a user initiated activity is taking place, and as such that resources should be
made available to the process accordingly.
Currently we hold a single NSActivity, at the WebKit layer. This refactoring allows us
to hold different activity tokens for different user actions (which simplifies the
handling, and aides debugging since the token can more accurately express the activity
taking place), and also will allow us to avoid the layering difficulty of calling back
up the stack to WebKit to register that an activity is taking place.
* Shared/ChildProcess.cpp:
(WebKit::ChildProcess::ChildProcess):
- removed fields to directly manage NSActivity, use UserActivity objects instead.
* Shared/ChildProcess.h:
(WebKit::ChildProcess::processSuppressionEnabled):
- changed to initialize new fields.
* Shared/mac/ChildProcessMac.mm:
(WebKit::ChildProcess::setProcessSuppressionEnabled):
- implemented in terms of UserActivity m_processSuppressionDisabled.
(WebKit::ChildProcess::incrementActiveTaskCount):
- implemented in terms of UserActivity m_activeTasks.
(WebKit::ChildProcess::decrementActiveTaskCount):
- implemented in terms of UserActivity m_activeTasks.
(WebKit::ChildProcess::platformInitialize):
- implemented in terms of UserActivity m_processSuppressionDisabled.
2014-01-02 Gavin Barraclough <barraclough@apple.com>
Propagate WindowServer modifications state to WebProcess
......
......@@ -35,11 +35,8 @@ ChildProcess::ChildProcess()
: m_terminationTimeout(0)
, m_terminationCounter(0)
, m_terminationTimer(RunLoop::main(), this, &ChildProcess::terminationTimerFired)
#if PLATFORM(MAC)
, m_activeTaskCount(0)
, m_shouldSuspend(false)
, m_suspensionHysteresisTimer(RunLoop::main(), this, &ChildProcess::suspensionHysteresisTimerFired)
#endif
, m_processSuppressionDisabled("Process Suppression Disabled by UIProcess")
, m_activeTasks("Process Suppression Disabled by WebProcess")
{
}
......@@ -80,6 +77,27 @@ void ChildProcess::initialize(const ChildProcessInitializationParameters& parame
m_connection->open();
}
void ChildProcess::setProcessSuppressionEnabled(bool enabled)
{
if (processSuppressionEnabled() == enabled)
return;
if (enabled)
m_processSuppressionDisabled.endActivity();
else
m_processSuppressionDisabled.beginActivity();
}
void ChildProcess::incrementActiveTaskCount()
{
m_activeTasks.beginActivity();
}
void ChildProcess::decrementActiveTaskCount()
{
m_activeTasks.endActivity();
}
void ChildProcess::initializeProcess(const ChildProcessInitializationParameters&)
{
}
......
......@@ -29,6 +29,7 @@
#include "Connection.h"
#include "MessageReceiverMap.h"
#include "MessageSender.h"
#include <WebCore/UserActivity.h>
#include <wtf/HashMap.h>
#include <wtf/RetainPtr.h>
#include <wtf/RunLoop.h>
......@@ -61,16 +62,13 @@ public:
void addMessageReceiver(IPC::StringReference messageReceiverName, uint64_t destinationID, IPC::MessageReceiver&);
void removeMessageReceiver(IPC::StringReference messageReceiverName, uint64_t destinationID);
#if PLATFORM(MAC)
void setProcessSuppressionEnabled(bool);
bool processSuppressionEnabled() const { return !m_processSuppressionAssertion; }
bool processSuppressionEnabled() const { return !m_processSuppressionDisabled.isActive(); }
void incrementActiveTaskCount();
void decrementActiveTaskCount();
#if PLATFORM(MAC)
void setApplicationIsDaemon();
#else
void incrementActiveTaskCount() { }
void decrementActiveTaskCount() { }
#endif
IPC::Connection* parentProcessConnection() const { return m_connection.get(); }
......@@ -119,14 +117,8 @@ private:
RefPtr<IPC::Connection> m_connection;
IPC::MessageReceiverMap m_messageReceiverMap;
#if PLATFORM(MAC)
void suspensionHysteresisTimerFired();
void setProcessSuppressionEnabledInternal(bool);
size_t m_activeTaskCount;
bool m_shouldSuspend;
RunLoop::Timer<ChildProcess> m_suspensionHysteresisTimer;
RetainPtr<id> m_processSuppressionAssertion;
#endif
UserActivity m_processSuppressionDisabled;
UserActivity m_activeTasks;
};
} // namespace WebKit
......
......@@ -60,68 +60,6 @@ using namespace WebCore;
namespace WebKit {
static const double kSuspensionHysteresisSeconds = 5.0;
void ChildProcess::setProcessSuppressionEnabledInternal(bool processSuppressionEnabled)
{
#if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
if (this->processSuppressionEnabled() == processSuppressionEnabled)
return;
if (processSuppressionEnabled) {
ASSERT(!m_activeTaskCount);
[[NSProcessInfo processInfo] endActivity:m_processSuppressionAssertion.get()];
m_processSuppressionAssertion.clear();
} else {
NSActivityOptions options = (NSActivityUserInitiatedAllowingIdleSystemSleep | NSActivityLatencyCritical) & ~(NSActivitySuddenTerminationDisabled | NSActivityAutomaticTerminationDisabled);
m_processSuppressionAssertion = [[NSProcessInfo processInfo] beginActivityWithOptions:options reason:@"Process Suppression Disabled"];
}
#else
UNUSED_PARAM(processSuppressionEnabled);
#endif
}
void ChildProcess::setProcessSuppressionEnabled(bool processSuppressionEnabled)
{
if (this->processSuppressionEnabled() == processSuppressionEnabled)
return;
if (m_shouldSuspend == processSuppressionEnabled)
return;
m_shouldSuspend = processSuppressionEnabled;
if (m_shouldSuspend) {
if (!m_activeTaskCount)
m_suspensionHysteresisTimer.startOneShot(kSuspensionHysteresisSeconds);
return;
}
setProcessSuppressionEnabledInternal(false);
}
void ChildProcess::incrementActiveTaskCount()
{
m_activeTaskCount++;
if (m_suspensionHysteresisTimer.isActive())
m_suspensionHysteresisTimer.stop();
if (m_activeTaskCount)
setProcessSuppressionEnabledInternal(false);
}
void ChildProcess::decrementActiveTaskCount()
{
ASSERT(m_activeTaskCount);
m_activeTaskCount--;
if (m_activeTaskCount)
return;
if (m_shouldSuspend)
m_suspensionHysteresisTimer.startOneShot(kSuspensionHysteresisSeconds);
}
void ChildProcess::suspensionHysteresisTimerFired()
{
ASSERT(!m_activeTaskCount);
ASSERT(m_shouldSuspend);
setProcessSuppressionEnabledInternal(true);
}
#if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
static void initializeTimerCoalescingPolicy()
{
......@@ -150,11 +88,8 @@ void ChildProcess::platformInitialize()
#if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
initializeTimerCoalescingPolicy();
#endif
// Starting with process suppression disabled. The proxy for this process will
// enable if appropriate from didFinishLaunching().
// We use setProcessSuppressionEnabledInternal to avoid any short circuit logic
// that would prevent us from taking the suppression assertion.
setProcessSuppressionEnabledInternal(false);
// Start with process suppression disabled.
m_processSuppressionDisabled.beginActivity();
[[NSFileManager defaultManager] changeCurrentDirectoryPath:[[NSBundle mainBundle] bundlePath]];
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment