Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1021)

Side by Side Diff: chrome/browser/sync/test/integration/status_change_checker.h

Issue 2379433002: [Sync] Refactoring of sync integration test checkers to remove boilerplate await methods. (Closed)
Patch Set: Updates for Max. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 whether the state the checker is currently in is its desired
32 // configuration.
33 virtual bool IsExitConditionSatisfied() = 0;
34
35 // Block if IsExitConditionSatisfied() is currently false until TimedOut()
36 // becomes true. Checkers should call CheckExitCondition upon changes, which
37 // can cause Wait() to immediately return true if IsExitConditionSatisfied(),
38 // and continue to block if not. Returns true if and only if timeout occurs.
maxbogue 2016/09/30 19:03:53 This is wrong now: "Returns true if and only if ti
skym 2016/09/30 19:06:52 Done.
39 virtual bool Wait();
40
31 // Returns true if the blocking wait was exited because of a timeout. 41 // Returns true if the blocking wait was exited because of a timeout.
32 bool TimedOut() const; 42 bool TimedOut() const;
33 43
34 virtual bool IsExitConditionSatisfied() = 0;
35
36 protected: 44 protected:
37 virtual ~StatusChangeChecker(); 45 virtual ~StatusChangeChecker();
38 46
39 // Timeout length when blocking. 47 // Timeout length when blocking.
40 virtual base::TimeDelta GetTimeoutDuration(); 48 virtual base::TimeDelta GetTimeoutDuration();
41 49
42 // Helper function to start running the nested message loop. 50 // Helper function to start running the nested message loop.
43 // 51 //
44 // Will exit if IsExitConditionSatisfied() returns true when called from 52 // Will exit if IsExitConditionSatisfied() returns true when called from
45 // CheckExitCondition(), if a timeout occurs, or if StopWaiting() is called. 53 // CheckExitCondition(), if a timeout occurs, or if StopWaiting() is called.
46 // 54 //
47 // The timeout length is specified with GetTimeoutDuration(). 55 // The timeout length is specified with GetTimeoutDuration().
48 void StartBlockingWait(); 56 void StartBlockingWait();
49 57
50 // Stop the nested running of the message loop started in StartBlockingWait(). 58 // Stop the nested running of the message loop started in StartBlockingWait().
51 void StopWaiting(); 59 void StopWaiting();
52 60
53 // Checks IsExitConditionSatisfied() and calls StopWaiting() if it returns 61 // Checks IsExitConditionSatisfied() and calls StopWaiting() if it returns
54 // true. 62 // true.
55 void CheckExitCondition(); 63 void CheckExitCondition();
56 64
57 // Called when the blocking wait timeout is exceeded. 65 // Called when the blocking wait timeout is exceeded.
58 void OnTimeout(); 66 void OnTimeout();
59 67
60 bool timed_out_; 68 bool timed_out_;
61 }; 69 };
62 70
63 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_STATUS_CHANGE_CHECKER_H_ 71 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_STATUS_CHANGE_CHECKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698