Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_STATUS_CHANGE_CHECKER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_STATUS_CHANGE_CHECKER_H_ |
| 6 #define CHROME_BROWSER_SYNC_TEST_INTEGRATION_STATUS_CHANGE_CHECKER_H_ | 6 #define CHROME_BROWSER_SYNC_TEST_INTEGRATION_STATUS_CHANGE_CHECKER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 | 11 |
| 12 class ProfileSyncServiceHarness; | 12 class ProfileSyncServiceHarness; |
| 13 | 13 |
| 14 // Interface for a helper class that can pump the message loop while waiting | 14 // Interface for a helper class that can pump the message loop while waiting |
| 15 // for a certain state transition to take place. | 15 // for a certain state transition to take place. |
| 16 // | 16 // |
| 17 // This is a template that should be filled in by child classes so they can | 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. | 18 // observe specific kinds of changes and await specific conditions. |
| 19 // | 19 // |
| 20 // The instances of this class are intended to be single-use. It doesn't make | 20 // The instances of this class are intended to be single-use. It doesn't make |
| 21 // sense to call StartBlockingWait() more than once. | 21 // sense to call StartBlockingWait() more than once. |
| 22 class StatusChangeChecker { | 22 class StatusChangeChecker { |
| 23 public: | 23 public: |
| 24 explicit StatusChangeChecker(); | 24 StatusChangeChecker(); |
| 25 | 25 |
| 26 // Returns a string representing this current StatusChangeChecker, and | 26 // Returns a string representing this current StatusChangeChecker, and |
| 27 // possibly some small part of its state. For example: "AwaitPassphraseError" | 27 // possibly some small part of its state. For example: "AwaitPassphraseError" |
| 28 // or "AwaitMigrationDone(BOOKMARKS)". | 28 // or "AwaitMigrationDone(BOOKMARKS)". |
| 29 virtual std::string GetDebugMessage() const = 0; | 29 virtual std::string GetDebugMessage() const = 0; |
| 30 | 30 |
| 31 // Returns a bool representing if the state the checker is currently in its | |
|
maxbogue
2016/09/30 16:27:56
"Returns whether the state the checker is currentl
skym
2016/09/30 17:43:21
Right? I was trying really hard to not just repeat
| |
| 32 // desired configuration. | |
| 33 virtual bool IsExitConditionSatisfied() = 0; | |
| 34 | |
| 35 // Block if IsExitConditionSatisfied() is currently false until TimeOut() | |
|
maxbogue
2016/09/30 16:27:56
"TimedOut()"
Also this makes it sound like you ch
skym
2016/09/30 17:43:22
Done.
| |
| 36 // becomes true. Checkers should call CheckExitCondition upon changes. Returns | |
| 37 // true if IsExitConditionSatisfied() is ultimately true, otherwise false. | |
| 38 bool Wait(); | |
| 39 | |
| 31 // Returns true if the blocking wait was exited because of a timeout. | 40 // Returns true if the blocking wait was exited because of a timeout. |
| 32 bool TimedOut() const; | 41 bool TimedOut() const; |
| 33 | 42 |
| 34 virtual bool IsExitConditionSatisfied() = 0; | |
| 35 | |
| 36 protected: | 43 protected: |
| 37 virtual ~StatusChangeChecker(); | 44 virtual ~StatusChangeChecker(); |
| 38 | 45 |
| 39 // Timeout length when blocking. | 46 // Timeout length when blocking. |
| 40 virtual base::TimeDelta GetTimeoutDuration(); | 47 virtual base::TimeDelta GetTimeoutDuration(); |
| 41 | 48 |
| 42 // Helper function to start running the nested message loop. | 49 // Helper function to start running the nested message loop. |
| 43 // | 50 // |
| 44 // Will exit if IsExitConditionSatisfied() returns true when called from | 51 // Will exit if IsExitConditionSatisfied() returns true when called from |
| 45 // CheckExitCondition(), if a timeout occurs, or if StopWaiting() is called. | 52 // CheckExitCondition(), if a timeout occurs, or if StopWaiting() is called. |
| 46 // | 53 // |
| 47 // The timeout length is specified with GetTimeoutDuration(). | 54 // The timeout length is specified with GetTimeoutDuration(). |
| 48 void StartBlockingWait(); | 55 void StartBlockingWait(); |
| 49 | 56 |
| 50 // Stop the nested running of the message loop started in StartBlockingWait(). | 57 // Stop the nested running of the message loop started in StartBlockingWait(). |
| 51 void StopWaiting(); | 58 void StopWaiting(); |
| 52 | 59 |
| 53 // Checks IsExitConditionSatisfied() and calls StopWaiting() if it returns | 60 // Checks IsExitConditionSatisfied() and calls StopWaiting() if it returns |
| 54 // true. | 61 // true. |
| 55 void CheckExitCondition(); | 62 void CheckExitCondition(); |
| 56 | 63 |
| 57 // Called when the blocking wait timeout is exceeded. | 64 // Called when the blocking wait timeout is exceeded. |
| 58 void OnTimeout(); | 65 void OnTimeout(); |
| 59 | 66 |
| 60 bool timed_out_; | 67 bool timed_out_; |
| 61 }; | 68 }; |
| 62 | 69 |
| 63 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_STATUS_CHANGE_CHECKER_H_ | 70 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_STATUS_CHANGE_CHECKER_H_ |
| OLD | NEW |