[email protected] | d778d6e | 2011-08-12 09:47:05 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | e4be2dd | 2010-12-14 00:44:39 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/diagnostics/diagnostics_test.h" |
| 6 | |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 7 | #include "base/files/file_path.h" |
[email protected] | e4be2dd | 2010-12-14 00:44:39 | [diff] [blame] | 8 | #include "base/path_service.h" |
| 9 | #include "chrome/common/chrome_constants.h" |
| 10 | #include "chrome/common/chrome_paths.h" |
| 11 | |
[email protected] | f22fae4 | 2013-07-09 21:11:11 | [diff] [blame] | 12 | namespace diagnostics { |
[email protected] | e4be2dd | 2010-12-14 00:44:39 | [diff] [blame] | 13 | |
[email protected] | f22fae4 | 2013-07-09 21:11:11 | [diff] [blame] | 14 | DiagnosticsTest::DiagnosticsTest(const std::string& id, |
| 15 | const std::string& title) |
| 16 | : id_(id), |
| 17 | title_(title), |
| 18 | outcome_code_(-1), |
| 19 | result_(DiagnosticsModel::TEST_NOT_RUN) {} |
[email protected] | e4be2dd | 2010-12-14 00:44:39 | [diff] [blame] | 20 | |
[email protected] | f22fae4 | 2013-07-09 21:11:11 | [diff] [blame] | 21 | DiagnosticsTest::~DiagnosticsTest() {} |
| 22 | |
| 23 | bool DiagnosticsTest::Execute(DiagnosticsModel::Observer* observer, |
| 24 | DiagnosticsModel* model, |
| 25 | size_t index) { |
| 26 | start_time_ = base::Time::Now(); |
[email protected] | e4be2dd | 2010-12-14 00:44:39 | [diff] [blame] | 27 | result_ = DiagnosticsModel::TEST_RUNNING; |
[email protected] | e4be2dd | 2010-12-14 00:44:39 | [diff] [blame] | 28 | bool keep_going = ExecuteImpl(observer); |
[email protected] | f22fae4 | 2013-07-09 21:11:11 | [diff] [blame] | 29 | if (observer) |
[email protected] | 60756be | 2013-08-07 05:20:26 | [diff] [blame] | 30 | observer->OnTestFinished(index, model); |
| 31 | return keep_going; |
| 32 | } |
| 33 | |
| 34 | bool DiagnosticsTest::Recover(DiagnosticsModel::Observer* observer, |
| 35 | DiagnosticsModel* model, |
| 36 | size_t index) { |
| 37 | result_ = DiagnosticsModel::RECOVERY_RUNNING; |
| 38 | bool keep_going = RecoveryImpl(observer); |
| 39 | result_ = keep_going ? DiagnosticsModel::RECOVERY_OK |
| 40 | : DiagnosticsModel::RECOVERY_FAIL_STOP; |
| 41 | if (observer) |
| 42 | observer->OnRecoveryFinished(index, model); |
[email protected] | e4be2dd | 2010-12-14 00:44:39 | [diff] [blame] | 43 | return keep_going; |
| 44 | } |
| 45 | |
[email protected] | f22fae4 | 2013-07-09 21:11:11 | [diff] [blame] | 46 | void DiagnosticsTest::RecordOutcome(int outcome_code, |
| 47 | const std::string& additional_info, |
| 48 | DiagnosticsModel::TestResult result) { |
| 49 | end_time_ = base::Time::Now(); |
| 50 | outcome_code_ = outcome_code; |
[email protected] | e4be2dd | 2010-12-14 00:44:39 | [diff] [blame] | 51 | additional_info_ = additional_info; |
| 52 | result_ = result; |
| 53 | } |
| 54 | |
| 55 | // static |
[email protected] | f22fae4 | 2013-07-09 21:11:11 | [diff] [blame] | 56 | base::FilePath DiagnosticsTest::GetUserDefaultProfileDir() { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 57 | base::FilePath path; |
[email protected] | e4be2dd | 2010-12-14 00:44:39 | [diff] [blame] | 58 | if (!PathService::Get(chrome::DIR_USER_DATA, &path)) |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 59 | return base::FilePath(); |
[email protected] | d778d6e | 2011-08-12 09:47:05 | [diff] [blame] | 60 | return path.AppendASCII(chrome::kInitialProfile); |
[email protected] | e4be2dd | 2010-12-14 00:44:39 | [diff] [blame] | 61 | } |
[email protected] | f22fae4 | 2013-07-09 21:11:11 | [diff] [blame] | 62 | |
| 63 | std::string DiagnosticsTest::GetId() const { return id_; } |
| 64 | |
| 65 | std::string DiagnosticsTest::GetTitle() const { return title_; } |
| 66 | |
| 67 | DiagnosticsModel::TestResult DiagnosticsTest::GetResult() const { |
| 68 | return result_; |
| 69 | } |
| 70 | |
| 71 | int DiagnosticsTest::GetOutcomeCode() const { return outcome_code_; } |
| 72 | |
| 73 | std::string DiagnosticsTest::GetAdditionalInfo() const { |
| 74 | return additional_info_; |
| 75 | } |
| 76 | |
| 77 | base::Time DiagnosticsTest::GetStartTime() const { return start_time_; } |
| 78 | |
| 79 | base::Time DiagnosticsTest::GetEndTime() const { return end_time_; } |
| 80 | |
[email protected] | 60756be | 2013-08-07 05:20:26 | [diff] [blame] | 81 | bool DiagnosticsTest::RecoveryImpl(DiagnosticsModel::Observer* observer) { |
| 82 | return true; |
| 83 | }; |
| 84 | |
| 85 | |
[email protected] | f22fae4 | 2013-07-09 21:11:11 | [diff] [blame] | 86 | } // namespace diagnostics |