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

Side by Side Diff: chrome/test/chromedriver/chromedriver_shared_library.cc

Issue 18419003: [chromedriver] Remove dll build target. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 7 years, 5 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <cstring>
6 #include <string>
7
8 #include "base/at_exit.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "build/build_config.h"
12 #include "chrome/test/chromedriver/chrome/log.h"
13 #include "chrome/test/chromedriver/chromedriver.h"
14 #include "chrome/test/chromedriver/command_executor.h"
15 #include "chrome/test/chromedriver/command_executor_impl.h"
16
17 #if defined(OS_WIN)
18 #include <windows.h>
19 #endif
20
21 #if defined(OS_WIN)
22 #define EXPORT __declspec(dllexport)
23 #else
24 #define EXPORT __attribute__((visibility("default")))
25 #endif
26
27 namespace {
28
29 base::AtExitManager* g_at_exit = NULL;
30 Log* g_log = NULL;
31
32 } // namespace
33
34 extern "C" {
35
36 // Synchronously executes the given command. Thread safe.
37 // Every call dynamically allocates a |response| string, which must be
38 // deallocated by calling |Free|. This |response| string is not guaranteed
39 // to be null terminated, and may contain null characters within. You
40 // should use the given response size to construct the string.
41 void EXPORT ExecuteCommand(
42 const char* command,
43 unsigned int command_size,
44 char** response,
45 unsigned int* response_size) {
46 std::string command_str(command, command_size);
47 std::string json;
48 ExecuteCommand(command_str, &json);
49 *response = new char[json.length()];
50 std::memcpy(*response, json.c_str(), json.length());
51 *response_size = json.length();
52 }
53
54 void EXPORT Free(char* p) {
55 delete [] p;
56 }
57
58 } // extern "C"
59
60 #if defined(OS_WIN)
61 BOOL APIENTRY DllMain(HMODULE module, DWORD reason, void* reserved) {
62 if (reason == DLL_PROCESS_ATTACH) {
63 g_at_exit = new base::AtExitManager();
64 g_log = new Logger();
65 Init(scoped_ptr<CommandExecutor>(new CommandExecutorImpl(g_log)));
66 }
67 if (reason == DLL_PROCESS_DETACH) {
68 // If |reserved| is not null, the process is terminating and
69 // ChromeDriver's threads have already been signaled to exit.
70 // Just leak and let the OS clean it up.
71 if (reserved)
72 return TRUE;
73 Shutdown();
74 delete g_log;
75 delete g_at_exit;
76 }
77 return TRUE;
78 }
79 #else
80 void __attribute__((constructor)) OnLoad(void) {
81 g_at_exit = new base::AtExitManager();
82 g_log = new Logger();
83 Init(scoped_ptr<CommandExecutor>(new CommandExecutorImpl(g_log)));
84 }
85 void __attribute__((destructor)) OnUnload(void) {
86 Shutdown();
87 delete g_log;
88 delete g_at_exit;
89 }
90 #endif
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/chromedriver.cc ('k') | chrome/test/chromedriver/chromedriver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698