Fix the problem that the temp worker directory is not deleted if the http server process is still holding it.

BUG=none
TEST=none

Review URL: http://codereview.chromium.org/155177

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20168 0039d316-1c4b-4281-b951-d872f2087c98
Esse commit está contido em:
jianli@chromium.org
2009-07-08 18:13:26 +00:00
commit 3fd5e8685f
+22 -2
Ver Arquivo
@@ -5,6 +5,7 @@
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/platform_thread.h"
#include "base/string_util.h"
#include "chrome/browser/worker_host/worker_service.h"
#include "chrome/common/chrome_paths.h"
@@ -63,8 +64,27 @@ WorkerTest::WorkerTest()
}
WorkerTest::~WorkerTest() {
if (!temp_test_dir_.empty())
file_util::Delete(temp_test_dir_, true);
// The deletion might fail because HTTP server process might not been
// completely shut down yet and is still holding certain handle to it.
// To work around this problem, we try to repeat the deletion several
// times.
if (!temp_test_dir_.empty()) {
static const int kRetryNum = 10;
static const int kRetryDelayTimeMs = 500;
int retry_time = 0;
for (int i = 0; i < kRetryNum; ++i) {
file_util::Delete(temp_test_dir_, true);
if (!file_util::DirectoryExists(temp_test_dir_))
break;
PlatformThread::Sleep(kRetryDelayTimeMs);
retry_time += kRetryDelayTimeMs;
}
if (retry_time)
printf("Retrying %d ms to delete temp worker directory.\n", retry_time);
}
}
void WorkerTest::RunTest(const std::wstring& test_case) {