author | Eugene Ostroukhov <eugeneo@symbian.org> |
Mon, 23 Aug 2010 10:30:05 -0700 | |
changeset 472 | bd9f2d7c64a6 |
parent 471 | 06589bf52fa7 |
child 484 | f5df819c1852 |
permissions | -rw-r--r-- |
471
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
1 |
/******************************************************************************* |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
2 |
* Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
3 |
* All rights reserved. |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
8 |
* |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
9 |
* Initial Contributors: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
10 |
* Symbian Foundation - initial contribution. |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
11 |
* Contributors: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
12 |
* Description: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
13 |
* Overview: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
14 |
* Details: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
15 |
* Platforms/Drives/Compatibility: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
16 |
* Assumptions/Requirement/Pre-requisites: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
17 |
* Failures and causes: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
18 |
*******************************************************************************/ |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
19 |
package org.symbian.tools.tmw.debug.internal.launch; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
20 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
21 |
import java.io.File; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
22 |
import java.io.FileFilter; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
23 |
import java.io.IOException; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
24 |
import java.text.MessageFormat; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
25 |
import java.util.Collections; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
26 |
import java.util.HashMap; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
27 |
import java.util.Map; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
28 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
29 |
import org.eclipse.core.resources.ResourcesPlugin; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
30 |
import org.eclipse.core.runtime.CoreException; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
31 |
import org.eclipse.core.runtime.IPath; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
32 |
import org.eclipse.core.runtime.IStatus; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
33 |
import org.eclipse.core.runtime.Path; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
34 |
import org.eclipse.core.runtime.Status; |
472
bd9f2d7c64a6
Debugger is now Symbian-independant
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
35 |
import org.symbian.tools.tmw.core.utilities.CoreUtil; |
471
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
36 |
import org.symbian.tools.tmw.debug.internal.Activator; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
37 |
import org.symbian.tools.tmw.debug.internal.ChromeDebugUtils; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
38 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
39 |
public class ChromeInstancesManager { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
40 |
private static final String[] CHROME_ARGS = { "%s", "--remote-shell-port=%d", // Here we will set port |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
41 |
"--user-data-dir=%s", // Here we will set profile folder so user settings have no effect |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
42 |
"--disk-cache-dir=%s", // We don't care |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
43 |
"--disable-web-security", // Widgets can use network now |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
44 |
"--disable-extenions", // Use standard UI, should also improve speed and stability |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
45 |
"--activate-on-launch", // Bring to front on Mac |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
46 |
"--disable-geolocation", // Use our own Geolocation (needed to emulate Geolocation in phonegap) |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
47 |
"--disable-local-storage", // Disable local storage (needed to emulate Geolocation in phonegap) |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
48 |
"--disable-session-storage", // Disable local storage (needed to emulate Geolocation in phonegap) |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
49 |
"--no-default-browser-check", // Our users don't need this nagging |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
50 |
"--disable-hang-monitor", // Fix for Bug 2682 - The debugger should disable "unresponsive" error message from chrome |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
51 |
"--no-first-run", // We don't care |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
52 |
"--app=%s" // Here we will have widget URI as --app argument |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
53 |
}; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
54 |
private final Map<Object, Process> chromes = Collections.synchronizedMap(new HashMap<Object, Process>()); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
55 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
56 |
private static final int EXECUTIBLE_INDEX = 0; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
57 |
private static final int PORT_INDEX = 1; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
58 |
private static final int USER_DATA_INDEX = 2; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
59 |
private static final int CACHE_INDEX = 3; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
60 |
private static final int URL_INDEX = CHROME_ARGS.length - 1; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
61 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
62 |
private int profileNum = 0; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
63 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
64 |
public void startChrome(final Object key, int port, final String url) throws CoreException { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
65 |
final String browserExecutable = ChromeDebugUtils.getChromeExecutible(); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
66 |
if (browserExecutable == null) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
67 |
throw createCoreException("No Chrome browser available", null); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
68 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
69 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
70 |
String[] commandline = new String[CHROME_ARGS.length]; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
71 |
System.arraycopy(CHROME_ARGS, 0, commandline, 0, CHROME_ARGS.length); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
72 |
commandline[EXECUTIBLE_INDEX] = String.format(CHROME_ARGS[EXECUTIBLE_INDEX], browserExecutable); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
73 |
commandline[PORT_INDEX] = String.format(CHROME_ARGS[PORT_INDEX], port); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
74 |
commandline[USER_DATA_INDEX] = String.format(CHROME_ARGS[USER_DATA_INDEX], getChromeProfilePath()); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
75 |
commandline[CACHE_INDEX] = String.format(CHROME_ARGS[CACHE_INDEX], getChromeCachePath()); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
76 |
commandline[URL_INDEX] = String.format(CHROME_ARGS[URL_INDEX], url); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
77 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
78 |
// 2. Start Chrome |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
79 |
try { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
80 |
Process process = Runtime.getRuntime().exec(commandline); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
81 |
chromes.put(key, process); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
82 |
} catch (IOException e) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
83 |
StringBuilder builder = new StringBuilder(); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
84 |
for (String string : commandline) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
85 |
builder.append(" ").append(string); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
86 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
87 |
throw createCoreException("Cannot execute: {0}", builder.toString().trim(), e); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
88 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
89 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
90 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
91 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
92 |
private String getChromeCachePath() { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
93 |
return getChromeSpecialDir(".chromecache"); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
94 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
95 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
96 |
/** |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
97 |
* Terminate Chrome instance associated with given key. |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
98 |
*/ |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
99 |
public synchronized void stopChrome(final Object key) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
100 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
101 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
102 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
103 |
public synchronized void forgetChrome(final Object key) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
104 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
105 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
106 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
107 |
public synchronized void shutdown() { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
108 |
String dir = getChromeSpecialDir(""); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
109 |
File directory = new File(dir); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
110 |
File[] files = directory.listFiles(new FileFilter() { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
111 |
public boolean accept(File pathname) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
112 |
return pathname.isDirectory() && pathname.getName().matches("\\.chr\\d{3}") |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
113 |
&& !isChromeRunning(pathname); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
114 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
115 |
}); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
116 |
boolean removedAll = true; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
117 |
for (File file : files) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
118 |
removedAll = delete(file) && removedAll; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
119 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
120 |
if (removedAll) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
121 |
String cachePath = getChromeCachePath(); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
122 |
delete(new File(cachePath)); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
123 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
124 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
125 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
126 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
127 |
private boolean delete(File file) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
128 |
if (!file.exists()) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
129 |
return true; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
130 |
} else if (file.isDirectory()) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
131 |
File[] files = file.listFiles(); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
132 |
for (File f : files) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
133 |
if (!delete(f)) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
134 |
return false; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
135 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
136 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
137 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
138 |
return file.delete(); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
139 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
140 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
141 |
private CoreException createCoreException(String pattern, String arg, Throwable exeption) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
142 |
return createCoreException(MessageFormat.format(pattern, arg), exeption); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
143 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
144 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
145 |
private CoreException createCoreException(String message, Throwable exeption) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
146 |
return new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, message, exeption)); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
147 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
148 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
149 |
private String getChromeProfilePath() { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
150 |
while (true) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
151 |
String dir = getChromeSpecialDir(String.format(".chr%03d", profileNum++)); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
152 |
if (!new File(dir).exists()) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
153 |
return dir; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
154 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
155 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
156 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
157 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
158 |
private boolean isChromeRunning(File pathname) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
159 |
File file = new File(pathname, "Default/Cookies"); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
160 |
try { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
161 |
// Note: it is ok to delete cookies file - if it can be deleted then Chrome is not running. |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
162 |
// If Chrome is running then we will not be able to delete the file. |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
163 |
// We do not need to preserve state between launches. So it is ok to delete coockies. |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
164 |
return file.exists() && !file.delete(); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
165 |
} catch (Exception e) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
166 |
Activator.log(e); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
167 |
return true; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
168 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
169 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
170 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
171 |
private String getChromeSpecialDir(String subdir) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
172 |
IPath location = ResourcesPlugin.getWorkspace().getRoot().getLocation(); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
173 |
if (CoreUtil.isLinux() && location.toString().length() > 50) { |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
174 |
location = new Path(System.getProperty("user.home")).append(".wrtdebug"); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
175 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
176 |
return location.append(subdir).toOSString(); |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
177 |
} |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
178 |
} |