Home | History | Annotate | Download | only in base
      1 // Copyright (c) 2006-2008 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 #ifndef NET_BASE_TEST_COMPLETION_CALLBACK_H_
      6 #define NET_BASE_TEST_COMPLETION_CALLBACK_H_
      7 #pragma once
      8 
      9 #include "base/callback.h"
     10 
     11 //-----------------------------------------------------------------------------
     12 // completion callback helper
     13 
     14 // A helper class for completion callbacks, designed to make it easy to run
     15 // tests involving asynchronous operations.  Just call WaitForResult to wait
     16 // for the asynchronous operation to complete.
     17 //
     18 // NOTE: Since this runs a message loop to wait for the completion callback,
     19 // there could be other side-effects resulting from WaitForResult.  For this
     20 // reason, this class is probably not ideal for a general application.
     21 //
     22 class TestCompletionCallback : public CallbackRunner< Tuple1<int> > {
     23  public:
     24   TestCompletionCallback();
     25   virtual ~TestCompletionCallback();
     26 
     27   int WaitForResult();
     28 
     29   int GetResult(int result);
     30 
     31   bool have_result() const { return have_result_; }
     32 
     33   virtual void RunWithParams(const Tuple1<int>& params);
     34 
     35  private:
     36   int result_;
     37   bool have_result_;
     38   bool waiting_for_result_;
     39 };
     40 
     41 #endif  // NET_BASE_TEST_COMPLETION_CALLBACK_H_
     42