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

Side by Side Diff: mojo/dart/embedder/builtin_natives.cc

Issue 1239583004: Cut the spam in the dart handler log printouts. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | 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 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 <stdio.h> 5 #include <stdio.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/files/file_enumerator.h" 9 #include "base/files/file_enumerator.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "crypto/random.h" 15 #include "crypto/random.h"
16 #include "dart/runtime/include/dart_api.h" 16 #include "dart/runtime/include/dart_api.h"
17 #include "mojo/dart/embedder/builtin.h" 17 #include "mojo/dart/embedder/builtin.h"
18 #include "mojo/dart/embedder/mojo_natives.h" 18 #include "mojo/dart/embedder/mojo_natives.h"
19 19
20 #if defined(OS_ANDROID)
21 #include <android/log.h>
22 #endif
23
20 namespace mojo { 24 namespace mojo {
21 namespace dart { 25 namespace dart {
22 26
23 // Lists the native functions implementing basic functionality in 27 // Lists the native functions implementing basic functionality in
24 // the Mojo embedder dart, such as printing, and file I/O. 28 // the Mojo embedder dart, such as printing, and file I/O.
25 #define BUILTIN_NATIVE_LIST(V) \ 29 #define BUILTIN_NATIVE_LIST(V) \
26 V(Crypto_GetRandomBytes, 1) \ 30 V(Crypto_GetRandomBytes, 1) \
27 V(Logger_PrintString, 1) \ 31 V(Logger_PrintString, 1) \
28 V(Builtin_ReadSync, 1) \ 32 V(Builtin_ReadSync, 1) \
29 V(Builtin_EnumerateFiles, 1) \ 33 V(Builtin_EnumerateFiles, 1) \
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // Implementation of native functions which are used for some 77 // Implementation of native functions which are used for some
74 // test/debug functionality in standalone dart mode. 78 // test/debug functionality in standalone dart mode.
75 void Logger_PrintString(Dart_NativeArguments args) { 79 void Logger_PrintString(Dart_NativeArguments args) {
76 intptr_t length = 0; 80 intptr_t length = 0;
77 uint8_t* chars = nullptr; 81 uint8_t* chars = nullptr;
78 Dart_Handle str = Dart_GetNativeArgument(args, 0); 82 Dart_Handle str = Dart_GetNativeArgument(args, 0);
79 Dart_Handle result = Dart_StringToUTF8(str, &chars, &length); 83 Dart_Handle result = Dart_StringToUTF8(str, &chars, &length);
80 if (Dart_IsError(result)) { 84 if (Dart_IsError(result)) {
81 Dart_PropagateError(result); 85 Dart_PropagateError(result);
82 } else { 86 } else {
83 // TODO(dart): Hook up to developer console (if/when that's a thing). 87 // TODO(dart): Hook up to developer console (if/when that's a thing).
84 #if defined(OS_ANDROID)
85 std::string message(reinterpret_cast<char*>(chars), length);
86 LOG(INFO) << "CONSOLE: " << message;
87 #else
88 // Uses fwrite to support printing NUL bytes. 88 // Uses fwrite to support printing NUL bytes.
89 fwrite(chars, 1, length, stdout); 89 fwrite(chars, 1, length, stdout);
90 fputs("\n", stdout); 90 fputs("\n", stdout);
91 #if defined(OS_ANDROID)
92 // In addition to writing to the stdout, write to the logcat so that the
93 // message is discoverable when running on an unrooted device. Use the
94 // "chromium" tag to match native printouts produced by base LOG macros, so
95 // that the same rule will pick them up in scripts that stream relevant
96 // logcat output to host terminal.
97 std::string str_newline = std::string(reinterpret_cast<const char*>(chars),
98 length) + "\n";
99 __android_log_print(ANDROID_LOG_INFO, "chromium", str_newline.c_str());
qsr 2015/07/16 08:31:39 Do android_log_print needs a carriage return? From
ppi 2015/07/16 09:41:27 Yes indeed, done.
91 #endif 100 #endif
92 } 101 }
93 fflush(stdout); 102 fflush(stdout);
94 } 103 }
95 104
96 void Builtin_ReadSync(Dart_NativeArguments args) { 105 void Builtin_ReadSync(Dart_NativeArguments args) {
97 intptr_t chars_length = 0; 106 intptr_t chars_length = 0;
98 uint8_t* chars = nullptr; 107 uint8_t* chars = nullptr;
99 Dart_Handle file_uri = Dart_GetNativeArgument(args, 0); 108 Dart_Handle file_uri = Dart_GetNativeArgument(args, 0);
100 if (!Dart_IsString(file_uri)) { 109 if (!Dart_IsString(file_uri)) {
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 Dart_Handle error = Dart_NewStringFromCString( 333 Dart_Handle error = Dart_NewStringFromCString(
325 "Failed to allocate storage."); 334 "Failed to allocate storage.");
326 Dart_ThrowException(error); 335 Dart_ThrowException(error);
327 } 336 }
328 Dart_ListSetAsBytes(result, 0, buffer.get(), count); 337 Dart_ListSetAsBytes(result, 0, buffer.get(), count);
329 Dart_SetReturnValue(args, result); 338 Dart_SetReturnValue(args, result);
330 } 339 }
331 340
332 } // namespace bin 341 } // namespace bin
333 } // namespace dart 342 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698