1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file.
4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_QUIESCE_STATUS_CHANGE_CHECKER_H_
6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#define CHROME_BROWSER_SYNC_TEST_INTEGRATION_QUIESCE_STATUS_CHANGE_CHECKER_H_
7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include <vector>
9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/basictypes.h"
11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/compiler_specific.h"
12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/memory/scoped_vector.h"
13effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "base/time/time.h"
14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/sync/test/integration/status_change_checker.h"
15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class ProfileSyncService;
17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class ProgressMarkerWatcher;
18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Waits until all provided clients have finished committing any unsynced items
20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// and downloading each others' udpates.
21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)//
22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// This requires that "self-notifications" be enabled.  Otherwise the clients
23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// will not fetch the latest progress markers on their own, and the latest
24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// progress markers are needed to confirm that clients are in sync.
25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)//
26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// There is a race condition here.  If we manage to perform the check at
27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// precisely the wrong time, we could end up seeing stale snapshot state
28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// (crbug.com/95742), which would make us think that the client has finished
29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// syncing when it hasn't.  In practice, this race is rare enough that it
30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// doesn't cause test failures.
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class QuiesceStatusChangeChecker : public StatusChangeChecker {
32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public:
33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  explicit QuiesceStatusChangeChecker(
34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      std::vector<ProfileSyncService*> services);
35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual ~QuiesceStatusChangeChecker();
36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
37effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // Blocks until all clients have quiesced or we time out.
38e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  void Wait();
39effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
40effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // A callback function for some helper objects.
41effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  void OnServiceStateChanged(ProfileSyncService* service);
42effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
43cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Implementation of StatusChangeChecker.
44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual bool IsExitConditionSatisfied() OVERRIDE;
45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual std::string GetDebugMessage() const OVERRIDE;
46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) private:
48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  std::vector<ProfileSyncService*> services_;
49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ScopedVector<ProgressMarkerWatcher> observers_;
50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
51a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(QuiesceStatusChangeChecker);
52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
53a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
54a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif  // CHROME_BROWSER_SYNC_TEST_INTEGRATION_QUIESCE_STATUS_CHANGE_CHECKER_H_
55