| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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_BROWSING_DATA_BROWSING_DATA_REMOVER_TEST_UTIL_H_ | |
| 6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_TEST_UTIL_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/scoped_observer.h" | |
| 11 #include "chrome/browser/browsing_data/browsing_data_remover.h" | |
| 12 #include "content/public/test/test_utils.h" | |
| 13 | |
| 14 // This class can be used to wait for a BrowsingDataRemover to complete | |
| 15 // operation. It is not suitable for repeated use. | |
| 16 class BrowsingDataRemoverCompletionObserver | |
| 17 : public BrowsingDataRemover::Observer { | |
| 18 public: | |
| 19 explicit BrowsingDataRemoverCompletionObserver(BrowsingDataRemover* remover); | |
| 20 ~BrowsingDataRemoverCompletionObserver() override; | |
| 21 | |
| 22 void BlockUntilCompletion(); | |
| 23 | |
| 24 protected: | |
| 25 // BrowsingDataRemover::Observer: | |
| 26 void OnBrowsingDataRemoverDone() override; | |
| 27 | |
| 28 private: | |
| 29 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
| 30 ScopedObserver<BrowsingDataRemover, BrowsingDataRemover::Observer> observer_; | |
| 31 | |
| 32 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverCompletionObserver); | |
| 33 }; | |
| 34 | |
| 35 // The completion inhibitor can artificially delay completion of the browsing | |
| 36 // data removal process. It is used during testing to simulate scenarios in | |
| 37 // which the deletion stalls or takes a very long time. | |
| 38 // | |
| 39 // This class will detach itself from |remover| upon its destruction. | |
| 40 // If |remover| is destroyed during a test (e.g. in profile shutdown tests), | |
| 41 // users must call Reset() to detach it in advance. | |
| 42 class BrowsingDataRemoverCompletionInhibitor { | |
| 43 public: | |
| 44 explicit BrowsingDataRemoverCompletionInhibitor(BrowsingDataRemover* remover); | |
| 45 virtual ~BrowsingDataRemoverCompletionInhibitor(); | |
| 46 | |
| 47 void Reset(); | |
| 48 | |
| 49 void BlockUntilNearCompletion(); | |
| 50 void ContinueToCompletion(); | |
| 51 | |
| 52 protected: | |
| 53 virtual void OnBrowsingDataRemoverWouldComplete( | |
| 54 const base::Closure& continue_to_completion); | |
| 55 | |
| 56 private: | |
| 57 // Not owned by this class. If the pointer becomes invalid, the owner of | |
| 58 // this class is responsible for calling Reset(). | |
| 59 BrowsingDataRemover* remover_; | |
| 60 | |
| 61 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
| 62 base::Closure continue_to_completion_callback_; | |
| 63 | |
| 64 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverCompletionInhibitor); | |
| 65 }; | |
| 66 | |
| 67 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_TEST_UTIL_H_ | |
| OLD | NEW |