Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1277)

Side by Side Diff: webkit/tools/test_shell/test_webworker_helper.cc

Issue 66043: Make OSX TestShell able to run workers, using a new test_worker.dylib which i... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/tools/test_shell/test_webworker_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include <wtf/MainThread.h> 6 #include <wtf/MainThread.h>
7 #include <wtf/Threading.h> 7 #include <wtf/Threading.h>
8 #undef LOG 8 #undef LOG
9 9
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 11
12 #include "webkit/tools/test_shell/test_webworker_helper.h" 12 #include "webkit/tools/test_shell/test_webworker_helper.h"
13 13
14 #if defined(OS_MACOSX)
15 #include <dlfcn.h>
16 #endif
17
14 #include "base/logging.h" 18 #include "base/logging.h"
15 #include "base/file_util.h" 19 #include "base/file_util.h"
16 #include "base/path_service.h" 20 #include "base/path_service.h"
17 #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" 21 #include "third_party/WebKit/WebKit/chromium/public/WebKit.h"
18 #include "webkit/glue/webworkerclient.h" 22 #include "webkit/glue/webworkerclient.h"
19 23
20
21 WebWorker* TestWebWorkerHelper::CreateWebWorker(WebWorkerClient* client) { 24 WebWorker* TestWebWorkerHelper::CreateWebWorker(WebWorkerClient* client) {
22 TestWebWorkerHelper* loader = new TestWebWorkerHelper(); 25 TestWebWorkerHelper* loader = new TestWebWorkerHelper();
23 return loader->CreateWebWorker_(client, loader); 26 return loader->CreateWebWorker_(client, loader);
24 } 27 }
25 28
26 TestWebWorkerHelper::TestWebWorkerHelper() : 29 TestWebWorkerHelper::TestWebWorkerHelper() :
27 #if defined(OS_WIN) 30 #if defined(OS_WIN)
28 module_(NULL), 31 module_(NULL),
29 #endif 32 #endif
30 CreateWebWorker_(NULL) { 33 CreateWebWorker_(NULL) {
31 Load(); 34 Load();
32 } 35 }
33 36
34 TestWebWorkerHelper::~TestWebWorkerHelper() { 37 TestWebWorkerHelper::~TestWebWorkerHelper() {
35 } 38 }
36 39
37 bool TestWebWorkerHelper::IsMainThread() const { 40 bool TestWebWorkerHelper::IsMainThread() const {
38 return WTF::isMainThread(); 41 return WTF::isMainThread();
39 } 42 }
40 43
41 void TestWebWorkerHelper::DispatchToMainThread(WTF::MainThreadFunction* func, 44 void TestWebWorkerHelper::DispatchToMainThread(WTF::MainThreadFunction* func,
42 void* context) { 45 void* context) {
43 return WTF::callOnMainThread(func, context); 46 return WTF::callOnMainThread(func, context);
44 } 47 }
45 48
46 bool TestWebWorkerHelper::Load() { 49 void TestWebWorkerHelper::Load() {
47 #if defined(OS_WIN)
48 FilePath path; 50 FilePath path;
49 PathService::Get(base::DIR_EXE, &path); 51 PathService::Get(base::DIR_EXE, &path);
52
53 #if defined(OS_WIN)
50 path = path.AppendASCII("test_worker.dll"); 54 path = path.AppendASCII("test_worker.dll");
51 55
52 module_ = LoadLibrary(path.value().c_str()); 56 module_ = LoadLibrary(path.value().c_str());
53 if (module_ == 0) 57 if (module_ == 0)
54 return false; 58 return;
55 59
56 CreateWebWorker_ = reinterpret_cast<CreateWebWorkerFunc> 60 CreateWebWorker_ = reinterpret_cast<CreateWebWorkerFunc>
57 (GetProcAddress(module_, "CreateWebWorker")); 61 (GetProcAddress(module_, "CreateWebWorker"));
58 if (!CreateWebWorker_) { 62 if (!CreateWebWorker_) {
59 FreeLibrary(module_); 63 FreeLibrary(module_);
60 module_ = 0; 64 module_ = 0;
61 return false;
62 } 65 }
66 #elif defined(OS_MACOSX)
67 path = path.AppendASCII("test_worker.dylib");
63 68
64 return true; 69 module_ = dlopen(path.value().c_str(), RTLD_NOW | RTLD_LOCAL);
70 if (!module_)
71 return;
72
73 CreateWebWorker_ = reinterpret_cast<CreateWebWorkerFunc>
74 (dlsym(module_, "CreateWebWorker"));
75 if (!CreateWebWorker_) {
76 dlclose(module_);
77 module_ = 0;
78 }
65 #else 79 #else
66 NOTIMPLEMENTED(); 80 NOTIMPLEMENTED();
67 return false;
68 #endif 81 #endif
69 } 82 }
70 83
71 void TestWebWorkerHelper::Unload() { 84 void TestWebWorkerHelper::Unload() {
72 // Since this is called from DLL, delay the unloading until it can be 85 // Since this is called from DLL, delay the unloading until it can be
73 // invoked from EXE. 86 // invoked from EXE.
74 return WTF::callOnMainThread(UnloadHelper, this); 87 return WTF::callOnMainThread(UnloadHelper, this);
75 } 88 }
76 89
77 void TestWebWorkerHelper::UnloadHelper(void* param) { 90 void TestWebWorkerHelper::UnloadHelper(void* param) {
78 TestWebWorkerHelper* this_ptr = static_cast<TestWebWorkerHelper*>(param); 91 TestWebWorkerHelper* this_ptr = static_cast<TestWebWorkerHelper*>(param);
79 92
80 #if defined(OS_WIN) 93 #if defined(OS_WIN)
81 if (this_ptr->module_) { 94 if (this_ptr->module_) {
82 FreeLibrary(this_ptr->module_); 95 FreeLibrary(this_ptr->module_);
83 this_ptr->module_ = 0; 96 this_ptr->module_ = 0;
84 } 97 }
85 #else 98 #else
86 NOTIMPLEMENTED(); 99 NOTIMPLEMENTED();
87 #endif 100 #endif
88 101
89 delete this_ptr; 102 delete this_ptr;
90 } 103 }
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/test_webworker_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698