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

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

Issue 728133002: Update mojo sdk to rev e01f9a49449381a5eb430c1fd88bf2cae73ec35a (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: android + ios gyp fixes 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, 26 if (!WriteFile(handle.handle, buffer, static_cast<DWORD>(bytes_to_write),
27 buffer, 27 &bytes_written_dword, &overlapped)) {
28 static_cast<DWORD>(bytes_to_write),
29 &bytes_written_dword,
30 &overlapped)) {
31 if (GetLastError() != ERROR_IO_PENDING || 28 if (GetLastError() != ERROR_IO_PENDING ||
32 !GetOverlappedResult( 29 !GetOverlappedResult(handle.handle, &overlapped, &bytes_written_dword,
33 handle.handle, &overlapped, &bytes_written_dword, TRUE)) { 30 TRUE)) {
34 return false; 31 return false;
35 } 32 }
36 } 33 }
37 34
38 *bytes_written = bytes_written_dword; 35 *bytes_written = bytes_written_dword;
39 return true; 36 return true;
40 } 37 }
41 38
42 bool BlockingRead(const embedder::PlatformHandle& handle, 39 bool BlockingRead(const embedder::PlatformHandle& handle,
43 void* buffer, 40 void* buffer,
44 size_t buffer_size, 41 size_t buffer_size,
45 size_t* bytes_read) { 42 size_t* bytes_read) {
46 OVERLAPPED overlapped = {0}; 43 OVERLAPPED overlapped = {0};
47 DWORD bytes_read_dword = 0; 44 DWORD bytes_read_dword = 0;
48 45
49 if (!ReadFile(handle.handle, 46 if (!ReadFile(handle.handle, buffer, static_cast<DWORD>(buffer_size),
50 buffer, 47 &bytes_read_dword, &overlapped)) {
51 static_cast<DWORD>(buffer_size),
52 &bytes_read_dword,
53 &overlapped)) {
54 if (GetLastError() != ERROR_IO_PENDING || 48 if (GetLastError() != ERROR_IO_PENDING ||
55 !GetOverlappedResult( 49 !GetOverlappedResult(handle.handle, &overlapped, &bytes_read_dword,
56 handle.handle, &overlapped, &bytes_read_dword, TRUE)) { 50 TRUE)) {
57 return false; 51 return false;
58 } 52 }
59 } 53 }
60 54
61 *bytes_read = bytes_read_dword; 55 *bytes_read = bytes_read_dword;
62 return true; 56 return true;
63 } 57 }
64 58
65 bool NonBlockingRead(const embedder::PlatformHandle& handle, 59 bool NonBlockingRead(const embedder::PlatformHandle& handle,
66 void* buffer, 60 void* buffer,
67 size_t buffer_size, 61 size_t buffer_size,
68 size_t* bytes_read) { 62 size_t* bytes_read) {
69 OVERLAPPED overlapped = {0}; 63 OVERLAPPED overlapped = {0};
70 DWORD bytes_read_dword = 0; 64 DWORD bytes_read_dword = 0;
71 65
72 if (!ReadFile(handle.handle, 66 if (!ReadFile(handle.handle, buffer, static_cast<DWORD>(buffer_size),
73 buffer, 67 &bytes_read_dword, &overlapped)) {
74 static_cast<DWORD>(buffer_size),
75 &bytes_read_dword,
76 &overlapped)) {
77 if (GetLastError() != ERROR_IO_PENDING) 68 if (GetLastError() != ERROR_IO_PENDING)
78 return false; 69 return false;
79 70
80 CancelIo(handle.handle); 71 CancelIo(handle.handle);
81 72
82 if (!GetOverlappedResult( 73 if (!GetOverlappedResult(handle.handle, &overlapped, &bytes_read_dword,
83 handle.handle, &overlapped, &bytes_read_dword, TRUE)) { 74 TRUE)) {
84 *bytes_read = 0; 75 *bytes_read = 0;
85 return true; 76 return true;
86 } 77 }
87 } 78 }
88 79
89 *bytes_read = bytes_read_dword; 80 *bytes_read = bytes_read_dword;
90 return true; 81 return true;
91 } 82 }
92 83
93 embedder::ScopedPlatformHandle PlatformHandleFromFILE(base::ScopedFILE fp) { 84 embedder::ScopedPlatformHandle PlatformHandleFromFILE(base::ScopedFILE fp) {
94 CHECK(fp); 85 CHECK(fp);
95 86
96 HANDLE rv = INVALID_HANDLE_VALUE; 87 HANDLE rv = INVALID_HANDLE_VALUE;
97 PCHECK(DuplicateHandle( 88 PCHECK(DuplicateHandle(
98 GetCurrentProcess(), 89 GetCurrentProcess(),
99 reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(fp.get()))), 90 reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(fp.get()))),
100 GetCurrentProcess(), 91 GetCurrentProcess(), &rv, 0, TRUE, DUPLICATE_SAME_ACCESS))
101 &rv,
102 0,
103 TRUE,
104 DUPLICATE_SAME_ACCESS))
105 << "DuplicateHandle"; 92 << "DuplicateHandle";
106 return embedder::ScopedPlatformHandle(embedder::PlatformHandle(rv)); 93 return embedder::ScopedPlatformHandle(embedder::PlatformHandle(rv));
107 } 94 }
108 95
109 base::ScopedFILE FILEFromPlatformHandle(embedder::ScopedPlatformHandle h, 96 base::ScopedFILE FILEFromPlatformHandle(embedder::ScopedPlatformHandle h,
110 const char* mode) { 97 const char* mode) {
111 CHECK(h.is_valid()); 98 CHECK(h.is_valid());
112 // Microsoft's documentation for |_open_osfhandle()| only discusses these 99 // Microsoft's documentation for |_open_osfhandle()| only discusses these
113 // flags (and |_O_WTEXT|). Hmmm. 100 // flags (and |_O_WTEXT|). Hmmm.
114 int flags = 0; 101 int flags = 0;
(...skipping 13 matching lines...) Expand all
128 base::FilePath GetFilePathForJSResource(const std::string& path) { 115 base::FilePath GetFilePathForJSResource(const std::string& path) {
129 std::string binding_path = "gen/" + path + ".js"; 116 std::string binding_path = "gen/" + path + ".js";
130 base::ReplaceChars(binding_path, "//", "\\", &binding_path); 117 base::ReplaceChars(binding_path, "//", "\\", &binding_path);
131 base::FilePath exe_dir; 118 base::FilePath exe_dir;
132 PathService::Get(base::DIR_EXE, &exe_dir); 119 PathService::Get(base::DIR_EXE, &exe_dir);
133 return exe_dir.AppendASCII(binding_path); 120 return exe_dir.AppendASCII(binding_path);
134 } 121 }
135 122
136 } // namespace test 123 } // namespace test
137 } // namespace mojo 124 } // 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