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

Side by Side Diff: mojo/edk/test/test_utils_win.cc

Issue 728043002: Revert of Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « mojo/edk/test/test_support_impl.cc ('k') | mojo/mojo.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/edk/test/test_utils.h" 5 #include "mojo/edk/test/test_utils.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <io.h> 9 #include <io.h>
10 #include <string.h> 10 #include <string.h>
11 11
12 #include "base/base_paths.h" 12 #include "base/base_paths.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 15
16 namespace mojo { 16 namespace mojo {
17 namespace test { 17 namespace test {
18 18
19 bool BlockingWrite(const embedder::PlatformHandle& handle, 19 bool BlockingWrite(const embedder::PlatformHandle& handle,
20 const void* buffer, 20 const void* buffer,
21 size_t bytes_to_write, 21 size_t bytes_to_write,
22 size_t* bytes_written) { 22 size_t* bytes_written) {
23 OVERLAPPED overlapped = {0}; 23 OVERLAPPED overlapped = {0};
24 DWORD bytes_written_dword = 0; 24 DWORD bytes_written_dword = 0;
25 25
26 if (!WriteFile(handle.handle, buffer, static_cast<DWORD>(bytes_to_write), 26 if (!WriteFile(handle.handle,
27 &bytes_written_dword, &overlapped)) { 27 buffer,
28 static_cast<DWORD>(bytes_to_write),
29 &bytes_written_dword,
30 &overlapped)) {
28 if (GetLastError() != ERROR_IO_PENDING || 31 if (GetLastError() != ERROR_IO_PENDING ||
29 !GetOverlappedResult(handle.handle, &overlapped, &bytes_written_dword, 32 !GetOverlappedResult(
30 TRUE)) { 33 handle.handle, &overlapped, &bytes_written_dword, TRUE)) {
31 return false; 34 return false;
32 } 35 }
33 } 36 }
34 37
35 *bytes_written = bytes_written_dword; 38 *bytes_written = bytes_written_dword;
36 return true; 39 return true;
37 } 40 }
38 41
39 bool BlockingRead(const embedder::PlatformHandle& handle, 42 bool BlockingRead(const embedder::PlatformHandle& handle,
40 void* buffer, 43 void* buffer,
41 size_t buffer_size, 44 size_t buffer_size,
42 size_t* bytes_read) { 45 size_t* bytes_read) {
43 OVERLAPPED overlapped = {0}; 46 OVERLAPPED overlapped = {0};
44 DWORD bytes_read_dword = 0; 47 DWORD bytes_read_dword = 0;
45 48
46 if (!ReadFile(handle.handle, buffer, static_cast<DWORD>(buffer_size), 49 if (!ReadFile(handle.handle,
47 &bytes_read_dword, &overlapped)) { 50 buffer,
51 static_cast<DWORD>(buffer_size),
52 &bytes_read_dword,
53 &overlapped)) {
48 if (GetLastError() != ERROR_IO_PENDING || 54 if (GetLastError() != ERROR_IO_PENDING ||
49 !GetOverlappedResult(handle.handle, &overlapped, &bytes_read_dword, 55 !GetOverlappedResult(
50 TRUE)) { 56 handle.handle, &overlapped, &bytes_read_dword, TRUE)) {
51 return false; 57 return false;
52 } 58 }
53 } 59 }
54 60
55 *bytes_read = bytes_read_dword; 61 *bytes_read = bytes_read_dword;
56 return true; 62 return true;
57 } 63 }
58 64
59 bool NonBlockingRead(const embedder::PlatformHandle& handle, 65 bool NonBlockingRead(const embedder::PlatformHandle& handle,
60 void* buffer, 66 void* buffer,
61 size_t buffer_size, 67 size_t buffer_size,
62 size_t* bytes_read) { 68 size_t* bytes_read) {
63 OVERLAPPED overlapped = {0}; 69 OVERLAPPED overlapped = {0};
64 DWORD bytes_read_dword = 0; 70 DWORD bytes_read_dword = 0;
65 71
66 if (!ReadFile(handle.handle, buffer, static_cast<DWORD>(buffer_size), 72 if (!ReadFile(handle.handle,
67 &bytes_read_dword, &overlapped)) { 73 buffer,
74 static_cast<DWORD>(buffer_size),
75 &bytes_read_dword,
76 &overlapped)) {
68 if (GetLastError() != ERROR_IO_PENDING) 77 if (GetLastError() != ERROR_IO_PENDING)
69 return false; 78 return false;
70 79
71 CancelIo(handle.handle); 80 CancelIo(handle.handle);
72 81
73 if (!GetOverlappedResult(handle.handle, &overlapped, &bytes_read_dword, 82 if (!GetOverlappedResult(
74 TRUE)) { 83 handle.handle, &overlapped, &bytes_read_dword, TRUE)) {
75 *bytes_read = 0; 84 *bytes_read = 0;
76 return true; 85 return true;
77 } 86 }
78 } 87 }
79 88
80 *bytes_read = bytes_read_dword; 89 *bytes_read = bytes_read_dword;
81 return true; 90 return true;
82 } 91 }
83 92
84 embedder::ScopedPlatformHandle PlatformHandleFromFILE(base::ScopedFILE fp) { 93 embedder::ScopedPlatformHandle PlatformHandleFromFILE(base::ScopedFILE fp) {
85 CHECK(fp); 94 CHECK(fp);
86 95
87 HANDLE rv = INVALID_HANDLE_VALUE; 96 HANDLE rv = INVALID_HANDLE_VALUE;
88 PCHECK(DuplicateHandle( 97 PCHECK(DuplicateHandle(
89 GetCurrentProcess(), 98 GetCurrentProcess(),
90 reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(fp.get()))), 99 reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(fp.get()))),
91 GetCurrentProcess(), &rv, 0, TRUE, DUPLICATE_SAME_ACCESS)) 100 GetCurrentProcess(),
101 &rv,
102 0,
103 TRUE,
104 DUPLICATE_SAME_ACCESS))
92 << "DuplicateHandle"; 105 << "DuplicateHandle";
93 return embedder::ScopedPlatformHandle(embedder::PlatformHandle(rv)); 106 return embedder::ScopedPlatformHandle(embedder::PlatformHandle(rv));
94 } 107 }
95 108
96 base::ScopedFILE FILEFromPlatformHandle(embedder::ScopedPlatformHandle h, 109 base::ScopedFILE FILEFromPlatformHandle(embedder::ScopedPlatformHandle h,
97 const char* mode) { 110 const char* mode) {
98 CHECK(h.is_valid()); 111 CHECK(h.is_valid());
99 // Microsoft's documentation for |_open_osfhandle()| only discusses these 112 // Microsoft's documentation for |_open_osfhandle()| only discusses these
100 // flags (and |_O_WTEXT|). Hmmm. 113 // flags (and |_O_WTEXT|). Hmmm.
101 int flags = 0; 114 int flags = 0;
(...skipping 13 matching lines...) Expand all
115 base::FilePath GetFilePathForJSResource(const std::string& path) { 128 base::FilePath GetFilePathForJSResource(const std::string& path) {
116 std::string binding_path = "gen/" + path + ".js"; 129 std::string binding_path = "gen/" + path + ".js";
117 base::ReplaceChars(binding_path, "//", "\\", &binding_path); 130 base::ReplaceChars(binding_path, "//", "\\", &binding_path);
118 base::FilePath exe_dir; 131 base::FilePath exe_dir;
119 PathService::Get(base::DIR_EXE, &exe_dir); 132 PathService::Get(base::DIR_EXE, &exe_dir);
120 return exe_dir.AppendASCII(binding_path); 133 return exe_dir.AppendASCII(binding_path);
121 } 134 }
122 135
123 } // namespace test 136 } // namespace test
124 } // namespace mojo 137 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/test/test_support_impl.cc ('k') | mojo/mojo.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698