| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_main.h" | 5 #include "chrome/browser/diagnostics/diagnostics_main.h" |
| 6 | 6 |
| 7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 #endif | 10 #endif |
| 11 | 11 |
| 12 #include <iostream> | 12 #include <iostream> |
| 13 | 13 |
| 14 #include "app/app_paths.h" | 14 #include "app/app_paths.h" |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/i18n/icu_util.h" | 17 #include "base/i18n/icu_util.h" |
| 18 #include "base/string_util.h" | 18 #include "base/logging.h" |
| 19 #include "base/stringprintf.h" |
| 19 #include "base/sys_string_conversions.h" | 20 #include "base/sys_string_conversions.h" |
| 20 #include "base/time.h" | 21 #include "base/time.h" |
| 21 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
| 22 #include "chrome/browser/diagnostics/diagnostics_model.h" | 23 #include "chrome/browser/diagnostics/diagnostics_model.h" |
| 23 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
| 24 #include "ui/base/ui_base_paths.h" | 25 #include "ui/base/ui_base_paths.h" |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 // This is a minimalistic interface to wrap the platform console. This will be | 28 // This is a minimalistic interface to wrap the platform console. This will be |
| 28 // eventually replaced by a view that can be subclassed for each platform and | 29 // eventually replaced by a view that can be subclassed for each platform and |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 245 |
| 245 // Keeps track of how many tests reported failure. | 246 // Keeps track of how many tests reported failure. |
| 246 int failures_; | 247 int failures_; |
| 247 | 248 |
| 248 DISALLOW_COPY_AND_ASSIGN(TestWriter); | 249 DISALLOW_COPY_AND_ASSIGN(TestWriter); |
| 249 }; | 250 }; |
| 250 | 251 |
| 251 std::wstring PrintableUSCurrentTime() { | 252 std::wstring PrintableUSCurrentTime() { |
| 252 base::Time::Exploded exploded = {0}; | 253 base::Time::Exploded exploded = {0}; |
| 253 base::Time::Now().UTCExplode(&exploded); | 254 base::Time::Now().UTCExplode(&exploded); |
| 254 return StringPrintf(L"%d:%d:%d.%d:%d:%d", | 255 return base::StringPrintf(L"%d:%d:%d.%d:%d:%d", |
| 255 exploded.year, exploded.month, exploded.day_of_month, | 256 exploded.year, |
| 256 exploded.hour, exploded.minute, exploded.second); | 257 exploded.month, |
| 258 exploded.day_of_month, |
| 259 exploded.hour, |
| 260 exploded.minute, |
| 261 exploded.second); |
| 257 } | 262 } |
| 258 | 263 |
| 259 // This class is a basic test controller. In this design the view (TestWriter) | 264 // This class is a basic test controller. In this design the view (TestWriter) |
| 260 // and the model (DiagnosticsModel) do not talk to each other directly but they | 265 // and the model (DiagnosticsModel) do not talk to each other directly but they |
| 261 // are mediated by the controller. This has a name: 'passive view'. | 266 // are mediated by the controller. This has a name: 'passive view'. |
| 262 // More info at http://martinfowler.com/eaaDev/PassiveScreen.html | 267 // More info at http://martinfowler.com/eaaDev/PassiveScreen.html |
| 263 class TestController : public DiagnosticsModel::Observer { | 268 class TestController : public DiagnosticsModel::Observer { |
| 264 public: | 269 public: |
| 265 explicit TestController(TestWriter* writer) | 270 explicit TestController(TestWriter* writer) |
| 266 : model_(NULL), | 271 : model_(NULL), |
| 267 writer_(writer) { | 272 writer_(writer) { |
| 268 } | 273 } |
| 269 | 274 |
| 270 // Run all the diagnostics of |model| and invoke the view as the model | 275 // Run all the diagnostics of |model| and invoke the view as the model |
| 271 // callbacks arrive. | 276 // callbacks arrive. |
| 272 void Run(DiagnosticsModel* model) { | 277 void Run(DiagnosticsModel* model) { |
| 273 std::wstring title(L"Chrome Diagnostics Mode ("); | 278 std::wstring title(L"Chrome Diagnostics Mode ("); |
| 274 writer_->WriteInfoText(title.append(PrintableUSCurrentTime()) + L")\n"); | 279 writer_->WriteInfoText(title.append(PrintableUSCurrentTime()) + L")\n"); |
| 275 if (!model) { | 280 if (!model) { |
| 276 writer_->WriteResult(false, L"Diagnostics start", L"model is null"); | 281 writer_->WriteResult(false, L"Diagnostics start", L"model is null"); |
| 277 return; | 282 return; |
| 278 } | 283 } |
| 279 bool icu_result = icu_util::Initialize(); | 284 bool icu_result = icu_util::Initialize(); |
| 280 if (!icu_result) { | 285 if (!icu_result) { |
| 281 writer_->WriteResult(false, L"Diagnostics start", L"ICU failure"); | 286 writer_->WriteResult(false, L"Diagnostics start", L"ICU failure"); |
| 282 return; | 287 return; |
| 283 } | 288 } |
| 284 int count = model->GetTestAvailableCount(); | 289 int count = model->GetTestAvailableCount(); |
| 285 writer_->WriteInfoText(StringPrintf(L"%d available test(s)\n\n", count)); | 290 writer_->WriteInfoText(base::StringPrintf( |
| 291 L"%d available test(s)\n\n", count)); |
| 286 model->RunAll(this); | 292 model->RunAll(this); |
| 287 } | 293 } |
| 288 | 294 |
| 289 // Next four are overridden from DiagnosticsModel::Observer. | 295 // Next four are overridden from DiagnosticsModel::Observer. |
| 290 virtual void OnProgress(int id, int percent, DiagnosticsModel* model) { | 296 virtual void OnProgress(int id, int percent, DiagnosticsModel* model) { |
| 291 } | 297 } |
| 292 | 298 |
| 293 virtual void OnSkipped(int id, DiagnosticsModel* model) { | 299 virtual void OnSkipped(int id, DiagnosticsModel* model) { |
| 294 // TODO(cpu): display skipped tests. | 300 // TODO(cpu): display skipped tests. |
| 295 } | 301 } |
| 296 | 302 |
| 297 virtual void OnFinished(int id, DiagnosticsModel* model) { | 303 virtual void OnFinished(int id, DiagnosticsModel* model) { |
| 298 // As each test completes we output the results. | 304 // As each test completes we output the results. |
| 299 ShowResult(model->GetTest(id)); | 305 ShowResult(model->GetTest(id)); |
| 300 } | 306 } |
| 301 | 307 |
| 302 virtual void OnDoneAll(DiagnosticsModel* model) { | 308 virtual void OnDoneAll(DiagnosticsModel* model) { |
| 303 if (writer_->failures() > 0) { | 309 if (writer_->failures() > 0) { |
| 304 writer_->WriteInfoText(StringPrintf(L"DONE. %d failure(s)\n\n", | 310 writer_->WriteInfoText(base::StringPrintf( |
| 305 writer_->failures())); | 311 L"DONE. %d failure(s)\n\n", writer_->failures())); |
| 306 } else { | 312 } else { |
| 307 writer_->WriteInfoText(L"DONE\n\n"); | 313 writer_->WriteInfoText(L"DONE\n\n"); |
| 308 } | 314 } |
| 309 } | 315 } |
| 310 | 316 |
| 311 private: | 317 private: |
| 312 void ShowResult(DiagnosticsModel::TestInfo& test_info) { | 318 void ShowResult(DiagnosticsModel::TestInfo& test_info) { |
| 313 bool success = (DiagnosticsModel::TEST_OK == test_info.GetResult()); | 319 bool success = (DiagnosticsModel::TEST_OK == test_info.GetResult()); |
| 314 writer_->WriteResult(success, UTF16ToWide(test_info.GetTitle()), | 320 writer_->WriteResult(success, UTF16ToWide(test_info.GetTitle()), |
| 315 UTF16ToWide(test_info.GetAdditionalInfo())); | 321 UTF16ToWide(test_info.GetAdditionalInfo())); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 // Windows. | 365 // Windows. |
| 360 #if defined(OS_WIN) | 366 #if defined(OS_WIN) |
| 361 // Block here so the user can see the results. | 367 // Block here so the user can see the results. |
| 362 writer.WriteInfoText(L"Press [enter] to continue\n"); | 368 writer.WriteInfoText(L"Press [enter] to continue\n"); |
| 363 std::wstring txt; | 369 std::wstring txt; |
| 364 console->Read(&txt); | 370 console->Read(&txt); |
| 365 #endif | 371 #endif |
| 366 delete console; | 372 delete console; |
| 367 return 0; | 373 return 0; |
| 368 } | 374 } |
| OLD | NEW |