• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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 CHROME_BROWSER_SYNC_TEST_INTEGRATION_STATUS_CHANGE_CHECKER_H_
6 #define CHROME_BROWSER_SYNC_TEST_INTEGRATION_STATUS_CHANGE_CHECKER_H_
7 
8 #include <string>
9 
10 #include "base/time/time.h"
11 
12 class ProfileSyncServiceHarness;
13 
14 // Interface for a helper class that can pump the message loop while waiting
15 // for a certain state transition to take place.
16 //
17 // This is a template that should be filled in by child classes so they can
18 // observe specific kinds of changes and await specific conditions.
19 //
20 // The instances of this class are intended to be single-use.  It doesn't make
21 // sense to call StartBlockingWait() more than once.
22 class StatusChangeChecker {
23  public:
24   explicit StatusChangeChecker();
25 
26   // Returns a string representing this current StatusChangeChecker, and
27   // possibly some small part of its state.  For example: "AwaitPassphraseError"
28   // or "AwaitMigrationDone(BOOKMARKS)".
29   virtual std::string GetDebugMessage() const = 0;
30 
31   // Returns true if the blocking wait was exited because of a timeout.
32   bool TimedOut() const;
33 
34   virtual bool IsExitConditionSatisfied() = 0;
35 
36  protected:
37   virtual ~StatusChangeChecker();
38 
39   // Timeout length when blocking.
40   virtual base::TimeDelta GetTimeoutDuration();
41 
42   // Helper function to start running the nested message loop.
43   //
44   // Will exit if IsExitConditionSatisfied() returns true when called from
45   // CheckExitCondition(), if a timeout occurs, or if StopWaiting() is called.
46   //
47   // The timeout length is specified with GetTimeoutDuration().
48   void StartBlockingWait();
49 
50   // Stop the nested running of the message loop started in StartBlockingWait().
51   void StopWaiting();
52 
53   // Checks IsExitConditionSatisfied() and calls StopWaiting() if it returns
54   // true.
55   void CheckExitCondition();
56 
57   // Called when the blocking wait timeout is exceeded.
58   void OnTimeout();
59 
60   bool timed_out_;
61 };
62 
63 #endif  // CHROME_BROWSER_SYNC_TEST_INTEGRATION_STATUS_CHANGE_CHECKER_H_
64