Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / status_change_checker.h
blobb1611cc86b39881da881f2b63ecfe66235879ded
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.
5 #ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_STATUS_CHANGE_CHECKER_H_
6 #define CHROME_BROWSER_SYNC_TEST_INTEGRATION_STATUS_CHANGE_CHECKER_H_
8 #include <string>
10 #include "base/time/time.h"
12 class ProfileSyncServiceHarness;
14 // Interface for a helper class that can pump the message loop while waiting
15 // for a certain state transition to take place.
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.
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();
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;
31 // Returns true if the blocking wait was exited because of a timeout.
32 bool TimedOut() const;
34 virtual bool IsExitConditionSatisfied() = 0;
36 protected:
37 virtual ~StatusChangeChecker();
39 // Timeout length when blocking.
40 virtual base::TimeDelta GetTimeoutDuration();
42 // Helper function to start running the nested message loop.
44 // Will exit if IsExitConditionSatisfied() returns true when called from
45 // CheckExitCondition(), if a timeout occurs, or if StopWaiting() is called.
47 // The timeout length is specified with GetTimeoutDuration().
48 void StartBlockingWait();
50 // Stop the nested running of the message loop started in StartBlockingWait().
51 void StopWaiting();
53 // Checks IsExitConditionSatisfied() and calls StopWaiting() if it returns
54 // true.
55 void CheckExitCondition();
57 // Called when the blocking wait timeout is exceeded.
58 void OnTimeout();
60 bool timed_out_;
63 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_STATUS_CHANGE_CHECKER_H_