| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 966 AdblockEngine.generateAppInfo(this.getContext(), debugMode), | 966 AdblockEngine.generateAppInfo(this.getContext(), debugMode), |
| 967 this.getContext().getDir(AdblockEngine.BASE_PATH_DIRECTORY, Context.MODE _PRIVATE).getAbsolutePath()) | 967 this.getContext().getDir(AdblockEngine.BASE_PATH_DIRECTORY, Context.MODE _PRIVATE).getAbsolutePath()) |
| 968 .enableElementHiding(true) | 968 .enableElementHiding(true) |
| 969 .build(); | 969 .build(); |
| 970 } | 970 } |
| 971 | 971 |
| 972 private class ElemHideThread extends Thread | 972 private class ElemHideThread extends Thread |
| 973 { | 973 { |
| 974 private String selectorsString; | 974 private String selectorsString; |
| 975 private CountDownLatch finishedLatch; | 975 private CountDownLatch finishedLatch; |
| 976 private AtomicBoolean isFinished; | |
| 976 private AtomicBoolean isCancelled; | 977 private AtomicBoolean isCancelled; |
| 977 | 978 |
| 978 public ElemHideThread(CountDownLatch finishedLatch) | 979 public ElemHideThread(CountDownLatch finishedLatch) |
| 979 { | 980 { |
| 980 this.finishedLatch = finishedLatch; | 981 this.finishedLatch = finishedLatch; |
| 982 isFinished = new AtomicBoolean(false); | |
| 981 isCancelled = new AtomicBoolean(false); | 983 isCancelled = new AtomicBoolean(false); |
| 982 } | 984 } |
| 983 | 985 |
| 984 @Override | 986 @Override |
| 985 public void run() | 987 public void run() |
| 986 { | 988 { |
| 987 try | 989 try |
| 988 { | 990 { |
| 989 if (adblockEngine == null) | 991 if (adblockEngine == null) |
| 990 { | 992 { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1046 { | 1048 { |
| 1047 if (finishedRunnable != null) | 1049 if (finishedRunnable != null) |
| 1048 { | 1050 { |
| 1049 finishedRunnable.run(); | 1051 finishedRunnable.run(); |
| 1050 } | 1052 } |
| 1051 } | 1053 } |
| 1052 } | 1054 } |
| 1053 | 1055 |
| 1054 private void finish(String result) | 1056 private void finish(String result) |
| 1055 { | 1057 { |
| 1058 isFinished.set(true); | |
| 1056 d("Setting elemhide string " + result.length() + " bytes"); | 1059 d("Setting elemhide string " + result.length() + " bytes"); |
| 1057 elemHideSelectorsString = result; | 1060 elemHideSelectorsString = result; |
| 1058 onFinished(); | 1061 onFinished(); |
| 1059 } | 1062 } |
| 1060 | 1063 |
| 1061 private final Object finishedRunnableLockObject = new Object(); | 1064 private final Object finishedRunnableLockObject = new Object(); |
| 1062 private Runnable finishedRunnable; | 1065 private Runnable finishedRunnable; |
| 1063 | 1066 |
| 1064 public void setFinishedRunnable(Runnable runnable) | 1067 public void setFinishedRunnable(Runnable runnable) |
| 1065 { | 1068 { |
| 1066 synchronized (finishedRunnableLockObject) | 1069 synchronized (finishedRunnableLockObject) |
| 1067 { | 1070 { |
| 1068 this.finishedRunnable = runnable; | 1071 this.finishedRunnable = runnable; |
| 1069 } | 1072 } |
| 1070 } | 1073 } |
| 1071 | 1074 |
| 1072 public void cancel() | 1075 public void cancel() |
| 1073 { | 1076 { |
| 1074 w("Cancelling elemhide thread " + this); | 1077 w("Cancelling elemhide thread " + this); |
| 1075 isCancelled.set(true); | 1078 if (!isFinished.get()) |
|
jens
2018/01/17 08:28:43
To make the if statement more readable, I would pr
anton
2018/01/17 08:33:55
Done. See patch set #2
| |
| 1076 | 1079 { |
| 1077 finish(EMPTY_ELEMHIDE_ARRAY_STRING); | 1080 isCancelled.set(true); |
| 1081 finish(EMPTY_ELEMHIDE_ARRAY_STRING); | |
| 1082 } | |
| 1083 else | |
| 1084 { | |
| 1085 w("This thread is finished, exiting silently " + this); | |
| 1086 } | |
| 1078 } | 1087 } |
| 1079 } | 1088 } |
| 1080 | 1089 |
| 1081 private Runnable elemHideThreadFinishedRunnable = new Runnable() | 1090 private Runnable elemHideThreadFinishedRunnable = new Runnable() |
| 1082 { | 1091 { |
| 1083 @Override | 1092 @Override |
| 1084 public void run() | 1093 public void run() |
| 1085 { | 1094 { |
| 1086 synchronized (elemHideThreadLockObject) | 1095 synchronized (elemHideThreadLockObject) |
| 1087 { | 1096 { |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1436 w("Busy with elemhide selectors, delayed disposing scheduled"); | 1445 w("Busy with elemhide selectors, delayed disposing scheduled"); |
| 1437 elemHideThread.setFinishedRunnable(disposeRunnable); | 1446 elemHideThread.setFinishedRunnable(disposeRunnable); |
| 1438 } | 1447 } |
| 1439 else | 1448 else |
| 1440 { | 1449 { |
| 1441 disposeRunnable.run(); | 1450 disposeRunnable.run(); |
| 1442 } | 1451 } |
| 1443 } | 1452 } |
| 1444 } | 1453 } |
| 1445 } | 1454 } |
| OLD | NEW |