Home | History | Annotate | Download | only in diagnostics
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/diagnostics/diagnostics_test.h"
      6 
      7 #include "base/files/file_path.h"
      8 #include "base/path_service.h"
      9 #include "chrome/common/chrome_constants.h"
     10 #include "chrome/common/chrome_paths.h"
     11 
     12 namespace diagnostics {
     13 
     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) {}
     20 
     21 DiagnosticsTest::~DiagnosticsTest() {}
     22 
     23 bool DiagnosticsTest::Execute(DiagnosticsModel::Observer* observer,
     24                               DiagnosticsModel* model,
     25                               size_t index) {
     26   start_time_ = base::Time::Now();
     27   result_ = DiagnosticsModel::TEST_RUNNING;
     28   bool keep_going = ExecuteImpl(observer);
     29   if (observer)
     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);
     43   return keep_going;
     44 }
     45 
     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;
     51   additional_info_ = additional_info;
     52   result_ = result;
     53 }
     54 
     55 // static
     56 base::FilePath DiagnosticsTest::GetUserDefaultProfileDir() {
     57   base::FilePath path;
     58   if (!PathService::Get(chrome::DIR_USER_DATA, &path))
     59     return base::FilePath();
     60   return path.AppendASCII(chrome::kInitialProfile);
     61 }
     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 
     81 bool DiagnosticsTest::RecoveryImpl(DiagnosticsModel::Observer* observer) {
     82   return true;
     83 };
     84 
     85 
     86 }  // namespace diagnostics
     87