Home | History | Annotate | Download | only in shill
      1 //
      2 // Copyright (C) 2014 The Android Open Source Project
      3 //
      4 // Licensed under the Apache License, Version 2.0 (the "License");
      5 // you may not use this file except in compliance with the License.
      6 // You may obtain a copy of the License at
      7 //
      8 //      http://www.apache.org/licenses/LICENSE-2.0
      9 //
     10 // Unless required by applicable law or agreed to in writing, software
     11 // distributed under the License is distributed on an "AS IS" BASIS,
     12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 // See the License for the specific language governing permissions and
     14 // limitations under the License.
     15 //
     16 
     17 #ifndef SHILL_CONNECTION_TESTER_H_
     18 #define SHILL_CONNECTION_TESTER_H_
     19 
     20 #include <memory>
     21 #include <string>
     22 #include <vector>
     23 
     24 #include <base/callback.h>
     25 #include <base/cancelable_callback.h>
     26 #include <base/memory/ref_counted.h>
     27 #include <base/memory/weak_ptr.h>
     28 #include <gtest/gtest_prod.h>  // for FRIEND_TEST
     29 
     30 #include "shill/connectivity_trial.h"
     31 #include "shill/refptr_types.h"
     32 
     33 namespace shill {
     34 
     35 // The ConnectionTester class implements a single trial connectivity test
     36 // to evaluate a connection in shill.  This will evaluate if a connection has
     37 // "general internet connectivity."
     38 //
     39 // This test will be triggered through a D-Bus call on demand by a user to
     40 // capture state of an existing connection and create detailed logging
     41 // information to be used for debugging connectivity issues.
     42 //
     43 // This functionality will be implemented by testing the connection with a
     44 // single ConnectivityTrial attempt.
     45 class ConnectionTester {
     46  public:
     47   ConnectionTester(ConnectionRefPtr connection,
     48                    EventDispatcher* dispatcher,
     49                    const base::Closure& callback);
     50   virtual ~ConnectionTester();
     51 
     52   // Start a connectivity test.  The Start method creates a ConnectivityTrial
     53   // instance and performs a single ConnectivityTrial.  The results are logged
     54   // and when the trial completes, the supplied callback is notified.
     55   virtual void Start();
     56 
     57   // End the current ConnectivityTester by calling Stop on underlying
     58   // ConnectivityTrial.  The callback will not be called.
     59   virtual void Stop();
     60 
     61  private:
     62   friend class ConnectionTesterTest;
     63   FRIEND_TEST(ConnectionTesterTest, CompleteTest);
     64 
     65   // Time to wait for the attempt to complete.
     66   static const int kTrialTimeoutSeconds;
     67   // Callback used by ConnectivityTrial to report results.
     68   void CompleteTest(ConnectivityTrial::Result result);
     69 
     70   ConnectionRefPtr connection_;
     71   EventDispatcher* dispatcher_;
     72   base::WeakPtrFactory<ConnectionTester> weak_ptr_factory_;
     73   base::Callback<void()> tester_callback_;
     74   std::unique_ptr<ConnectivityTrial> connectivity_trial_;
     75 
     76   DISALLOW_COPY_AND_ASSIGN(ConnectionTester);
     77 };
     78 
     79 }  // namespace shill
     80 
     81 #endif  // SHILL_CONNECTION_TESTER_H_
     82