Title: [161020] trunk/Source/WebKit2
Revision
161020
Author
[email protected]
Date
2013-12-23 14:07:40 -0800 (Mon, 23 Dec 2013)

Log Message

[GTK][WK2] Simplify ProcessExecutablePathGtk
https://bugs.webkit.org/show_bug.cgi?id=126173

Reviewed by Martin Robinson.

Don't store process name strings in global variables -- each of the names is only used in the relevant
function, so the string can be directly passed into the findWebKitProcess function call.

Simplify the findWebKitProcess function. Make the execDirectory variable static so that g_getenv is only
called once, as it's not expected for the WEBKIT_EXEC_PATH environment variable to change during the runtime.

Introduce the getExecutablePath helper function that gets the current executable path and, if non-null, returns
the directory path of that executable. The helper function preserves the small performance improvement of querying
and processing the executable path only once.
The return value of getExecutablePath is stored in a static variable and is used to construct the process path
if the executable path was successfully retrieved.

* Shared/gtk/ProcessExecutablePathGtk.cpp:
(WebKit::getExecutablePath):
(WebKit::findWebKitProcess):
(WebKit::executablePathOfWebProcess):
(WebKit::executablePathOfPluginProcess):
(WebKit::executablePathOfNetworkProcess):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (161019 => 161020)


--- trunk/Source/WebKit2/ChangeLog	2013-12-23 22:05:48 UTC (rev 161019)
+++ trunk/Source/WebKit2/ChangeLog	2013-12-23 22:07:40 UTC (rev 161020)
@@ -1,5 +1,31 @@
 2013-12-23  Zan Dobersek  <[email protected]>
 
+        [GTK][WK2] Simplify ProcessExecutablePathGtk
+        https://bugs.webkit.org/show_bug.cgi?id=126173
+
+        Reviewed by Martin Robinson.
+
+        Don't store process name strings in global variables -- each of the names is only used in the relevant
+        function, so the string can be directly passed into the findWebKitProcess function call.
+
+        Simplify the findWebKitProcess function. Make the execDirectory variable static so that g_getenv is only
+        called once, as it's not expected for the WEBKIT_EXEC_PATH environment variable to change during the runtime.
+
+        Introduce the getExecutablePath helper function that gets the current executable path and, if non-null, returns
+        the directory path of that executable. The helper function preserves the small performance improvement of querying
+        and processing the executable path only once.
+        The return value of getExecutablePath is stored in a static variable and is used to construct the process path
+        if the executable path was successfully retrieved.
+
+        * Shared/gtk/ProcessExecutablePathGtk.cpp:
+        (WebKit::getExecutablePath):
+        (WebKit::findWebKitProcess):
+        (WebKit::executablePathOfWebProcess):
+        (WebKit::executablePathOfPluginProcess):
+        (WebKit::executablePathOfNetworkProcess):
+
+2013-12-23  Zan Dobersek  <[email protected]>
+
         Unreviewed build fix for GTK and EFL after r161007.
 
         * UIProcess/DrawingAreaProxyImpl.cpp:

Modified: trunk/Source/WebKit2/Shared/gtk/ProcessExecutablePathGtk.cpp (161019 => 161020)


--- trunk/Source/WebKit2/Shared/gtk/ProcessExecutablePathGtk.cpp	2013-12-23 22:05:48 UTC (rev 161019)
+++ trunk/Source/WebKit2/Shared/gtk/ProcessExecutablePathGtk.cpp	2013-12-23 22:07:40 UTC (rev 161020)
@@ -35,29 +35,24 @@
 
 namespace WebKit {
 
-const char* gWebKitWebProcessName = "WebKitWebProcess";
-const char* gWebKitPluginProcessName = "WebKitPluginProcess";
-const char* gWebKitNetworkProcessName = "WebKitNetworkProcess";
+static String getExecutablePath()
+{
+    CString executablePath = getCurrentExecutablePath();
+    if (!executablePath.isNull())
+        return directoryName(filenameToString(executablePath.data()));
+    return String();
+}
 
 static String findWebKitProcess(const char* processName)
 {
-    const char* execDirectory = g_getenv("WEBKIT_EXEC_PATH");
+    static const char* execDirectory = g_getenv("WEBKIT_EXEC_PATH");
     if (execDirectory) {
         String processPath = pathByAppendingComponent(filenameToString(execDirectory), processName);
         if (fileExists(processPath))
             return processPath;
     }
 
-    static bool gotExecutablePath = false;
-    static String executablePath;
-    if (!gotExecutablePath) {
-        gotExecutablePath = true;
-
-        CString executableFile = getCurrentExecutablePath();
-        if (!executableFile.isNull())
-            executablePath = directoryName(filenameToString(executableFile.data()));
-    }
-
+    static String executablePath = getExecutablePath();
     if (!executablePath.isNull()) {
         String processPath = pathByAppendingComponent(executablePath, processName);
         if (fileExists(processPath))
@@ -69,18 +64,18 @@
 
 String executablePathOfWebProcess()
 {
-    return findWebKitProcess(gWebKitWebProcessName);
+    return findWebKitProcess("WebKitWebProcess");
 }
 
 String executablePathOfPluginProcess()
 {
-    return findWebKitProcess(gWebKitPluginProcessName);
+    return findWebKitProcess("WebKitPluginProcess");
 }
 
 #if ENABLE(NETWORK_PROCESS)
 String executablePathOfNetworkProcess()
 {
-    return findWebKitProcess(gWebKitNetworkProcessName);
+    return findWebKitProcess("WebKitNetworkProcess");
 }
 #endif
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to