Rebecca Silberstein | f4365a6 | 2014-09-16 11:40:32 -0700 | [diff] [blame] | 1 | // Copyright (c) 2014 The Chromium OS 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 | #ifndef SHILL_CONNECTION_TESTER_H_ |
| 6 | #define SHILL_CONNECTION_TESTER_H_ |
| 7 | |
Ben Chan | 22f1fbc | 2014-10-17 14:18:07 -0700 | [diff] [blame] | 8 | #include <memory> |
Rebecca Silberstein | f4365a6 | 2014-09-16 11:40:32 -0700 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
| 12 | #include <base/callback.h> |
| 13 | #include <base/cancelable_callback.h> |
| 14 | #include <base/memory/ref_counted.h> |
Rebecca Silberstein | f4365a6 | 2014-09-16 11:40:32 -0700 | [diff] [blame] | 15 | #include <base/memory/weak_ptr.h> |
| 16 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 17 | |
| 18 | #include "shill/connectivity_trial.h" |
| 19 | #include "shill/refptr_types.h" |
| 20 | |
| 21 | namespace shill { |
| 22 | |
| 23 | // The ConnectionTester class implements a single trial connectivity test |
| 24 | // to evaluate a connection in shill. This will evaluate if a connection has |
| 25 | // "general internet connectivity." |
| 26 | // |
| 27 | // This test will be triggered through a D-Bus call on demand by a user to |
| 28 | // capture state of an existing connection and create detailed logging |
| 29 | // information to be used for debugging connectivity issues. |
| 30 | // |
| 31 | // This functionality will be implemented by testing the connection with a |
| 32 | // single ConnectivityTrial attempt. |
| 33 | class ConnectionTester { |
| 34 | public: |
| 35 | ConnectionTester(ConnectionRefPtr connection, |
Paul Stewart | a794cd6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 36 | EventDispatcher* dispatcher, |
| 37 | const base::Closure& callback); |
Rebecca Silberstein | f4365a6 | 2014-09-16 11:40:32 -0700 | [diff] [blame] | 38 | virtual ~ConnectionTester(); |
| 39 | |
| 40 | // Start a connectivity test. The Start method creates a ConnectivityTrial |
| 41 | // instance and performs a single ConnectivityTrial. The results are logged |
| 42 | // and when the trial completes, the supplied callback is notified. |
| 43 | virtual void Start(); |
| 44 | |
| 45 | // End the current ConnectivityTester by calling Stop on underlying |
| 46 | // ConnectivityTrial. The callback will not be called. |
| 47 | virtual void Stop(); |
| 48 | |
| 49 | private: |
| 50 | friend class ConnectionTesterTest; |
| 51 | FRIEND_TEST(ConnectionTesterTest, CompleteTest); |
| 52 | |
| 53 | // Time to wait for the attempt to complete. |
| 54 | static const int kTrialTimeoutSeconds; |
| 55 | // Callback used by ConnectivityTrial to report results. |
| 56 | void CompleteTest(ConnectivityTrial::Result result); |
| 57 | |
| 58 | ConnectionRefPtr connection_; |
Paul Stewart | a794cd6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 59 | EventDispatcher* dispatcher_; |
Rebecca Silberstein | f4365a6 | 2014-09-16 11:40:32 -0700 | [diff] [blame] | 60 | base::WeakPtrFactory<ConnectionTester> weak_ptr_factory_; |
| 61 | base::Callback<void()> tester_callback_; |
Ben Chan | 22f1fbc | 2014-10-17 14:18:07 -0700 | [diff] [blame] | 62 | std::unique_ptr<ConnectivityTrial> connectivity_trial_; |
Rebecca Silberstein | f4365a6 | 2014-09-16 11:40:32 -0700 | [diff] [blame] | 63 | |
| 64 | DISALLOW_COPY_AND_ASSIGN(ConnectionTester); |
| 65 | }; |
| 66 | |
| 67 | } // namespace shill |
| 68 | |
| 69 | #endif // SHILL_CONNECTION_TESTER_H_ |