OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/diagnostics/diagnostics_writer.h" | 5 #include "chrome/browser/diagnostics/diagnostics_writer.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 24 matching lines...) Expand all Loading... |
35 GREEN, | 35 GREEN, |
36 }; | 36 }; |
37 | 37 |
38 virtual ~SimpleConsole() {} | 38 virtual ~SimpleConsole() {} |
39 | 39 |
40 // Init must be called before using any other method. If it returns | 40 // Init must be called before using any other method. If it returns |
41 // false there will be no console output. | 41 // false there will be no console output. |
42 virtual bool Init() = 0; | 42 virtual bool Init() = 0; |
43 | 43 |
44 // Writes a string to the console with the current color. | 44 // Writes a string to the console with the current color. |
45 virtual bool Write(const string16& text) = 0; | 45 virtual bool Write(const base::string16& text) = 0; |
46 | 46 |
47 // Called when the program is about to exit. | 47 // Called when the program is about to exit. |
48 virtual void OnQuit() = 0; | 48 virtual void OnQuit() = 0; |
49 | 49 |
50 // Sets the foreground text color. | 50 // Sets the foreground text color. |
51 virtual bool SetColor(Color color) = 0; | 51 virtual bool SetColor(Color color) = 0; |
52 | 52 |
53 // Create an appropriate SimpleConsole instance. May return NULL if there is | 53 // Create an appropriate SimpleConsole instance. May return NULL if there is |
54 // no implementation for the current platform. | 54 // no implementation for the current platform. |
55 static SimpleConsole* Create(); | 55 static SimpleConsole* Create(); |
(...skipping 14 matching lines...) Expand all Loading... |
70 } | 70 } |
71 | 71 |
72 virtual ~WinConsole() { | 72 virtual ~WinConsole() { |
73 ::FreeConsole(); | 73 ::FreeConsole(); |
74 } | 74 } |
75 | 75 |
76 virtual bool Init() { | 76 virtual bool Init() { |
77 return SetIOHandles(); | 77 return SetIOHandles(); |
78 } | 78 } |
79 | 79 |
80 virtual bool Write(const string16& txt) { | 80 virtual bool Write(const base::string16& txt) { |
81 DWORD sz = txt.size(); | 81 DWORD sz = txt.size(); |
82 return (TRUE == ::WriteConsoleW(std_out_, txt.c_str(), sz, &sz, NULL)); | 82 return (TRUE == ::WriteConsoleW(std_out_, txt.c_str(), sz, &sz, NULL)); |
83 } | 83 } |
84 | 84 |
85 // Reads a string from the console. Internally it is limited to 256 | 85 // Reads a string from the console. Internally it is limited to 256 |
86 // characters. | 86 // characters. |
87 virtual void OnQuit() { | 87 virtual void OnQuit() { |
88 // Block here so the user can see the results. | 88 // Block here so the user can see the results. |
89 SetColor(SimpleConsole::DEFAULT); | 89 SetColor(SimpleConsole::DEFAULT); |
90 Write(L"Press [enter] to continue\n"); | 90 Write(L"Press [enter] to continue\n"); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 public: | 139 public: |
140 PosixConsole() : use_color_(false) {} | 140 PosixConsole() : use_color_(false) {} |
141 | 141 |
142 virtual bool Init() OVERRIDE { | 142 virtual bool Init() OVERRIDE { |
143 // Technically, we should also check the terminal capabilities before using | 143 // Technically, we should also check the terminal capabilities before using |
144 // color, but in practice this is unlikely to be an issue. | 144 // color, but in practice this is unlikely to be an issue. |
145 use_color_ = isatty(STDOUT_FILENO); | 145 use_color_ = isatty(STDOUT_FILENO); |
146 return true; | 146 return true; |
147 } | 147 } |
148 | 148 |
149 virtual bool Write(const string16& text) OVERRIDE { | 149 virtual bool Write(const base::string16& text) OVERRIDE { |
150 // We're assuming that the terminal is using UTF-8 encoding. | 150 // We're assuming that the terminal is using UTF-8 encoding. |
151 printf("%s", UTF16ToUTF8(text).c_str()); | 151 printf("%s", UTF16ToUTF8(text).c_str()); |
152 return true; | 152 return true; |
153 } | 153 } |
154 | 154 |
155 virtual void OnQuit() OVERRIDE { | 155 virtual void OnQuit() OVERRIDE { |
156 // The "press enter to continue" prompt isn't very unixy, so only do that on | 156 // The "press enter to continue" prompt isn't very unixy, so only do that on |
157 // Windows. | 157 // Windows. |
158 } | 158 } |
159 | 159 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 result.c_str(), | 281 result.c_str(), |
282 outcome_code, | 282 outcome_code, |
283 id.c_str(), | 283 id.c_str(), |
284 extra.c_str())); | 284 extra.c_str())); |
285 } | 285 } |
286 } | 286 } |
287 return true; | 287 return true; |
288 } | 288 } |
289 | 289 |
290 } // namespace diagnostics | 290 } // namespace diagnostics |
OLD | NEW |