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

Side by Side Diff: chrome/browser/browsing_data/browsing_data_remover_test_util.h

Issue 2802013002: Move BrowsingDataRemoverImpl:: CompletionInhibitor to the public interface (Closed)
Patch Set: Finishing after shutdown is still OK. Created 3 years, 8 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 2014 The Chromium Authors. All rights reserved. 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 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_BROWSING_DATA_BROWSING_DATA_REMOVER_TEST_UTIL_H_ 5 #ifndef CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_TEST_UTIL_H_
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_TEST_UTIL_H_ 6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_TEST_UTIL_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/scoped_observer.h" 10 #include "base/scoped_observer.h"
11 #include "chrome/browser/browsing_data/browsing_data_remover.h" 11 #include "chrome/browser/browsing_data/browsing_data_remover.h"
12 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h"
13 #include "content/public/test/test_utils.h" 12 #include "content/public/test/test_utils.h"
14 13
15 // This class can be used to wait for a BrowsingDataRemover to complete 14 // This class can be used to wait for a BrowsingDataRemover to complete
16 // operation. It is not suitable for repeated use. 15 // operation. It is not suitable for repeated use.
17 class BrowsingDataRemoverCompletionObserver 16 class BrowsingDataRemoverCompletionObserver
18 : public BrowsingDataRemover::Observer { 17 : public BrowsingDataRemover::Observer {
19 public: 18 public:
20 explicit BrowsingDataRemoverCompletionObserver(BrowsingDataRemover* remover); 19 explicit BrowsingDataRemoverCompletionObserver(BrowsingDataRemover* remover);
21 ~BrowsingDataRemoverCompletionObserver() override; 20 ~BrowsingDataRemoverCompletionObserver() override;
22 21
23 void BlockUntilCompletion(); 22 void BlockUntilCompletion();
24 23
25 protected: 24 protected:
26 // BrowsingDataRemover::Observer: 25 // BrowsingDataRemover::Observer:
27 void OnBrowsingDataRemoverDone() override; 26 void OnBrowsingDataRemoverDone() override;
28 27
29 private: 28 private:
30 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 29 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
31 ScopedObserver<BrowsingDataRemover, BrowsingDataRemover::Observer> observer_; 30 ScopedObserver<BrowsingDataRemover, BrowsingDataRemover::Observer> observer_;
32 31
33 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverCompletionObserver); 32 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverCompletionObserver);
34 }; 33 };
35 34
36 class BrowsingDataRemoverCompletionInhibitor 35 // The completion inhibitor can artificially delay completion of the browsing
37 : public BrowsingDataRemoverImpl::CompletionInhibitor { 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 {
38 public: 43 public:
39 BrowsingDataRemoverCompletionInhibitor(); 44 explicit BrowsingDataRemoverCompletionInhibitor(BrowsingDataRemover* remover);
40 ~BrowsingDataRemoverCompletionInhibitor() override; 45 virtual ~BrowsingDataRemoverCompletionInhibitor();
46
47 void Reset();
41 48
42 void BlockUntilNearCompletion(); 49 void BlockUntilNearCompletion();
43 void ContinueToCompletion(); 50 void ContinueToCompletion();
44 51
45 protected: 52 protected:
46 // BrowsingDataRemoverImpl::CompletionInhibitor: 53 virtual void OnBrowsingDataRemoverWouldComplete(
47 void OnBrowsingDataRemoverWouldComplete( 54 const base::Closure& continue_to_completion);
48 BrowsingDataRemoverImpl* remover,
49 const base::Closure& continue_to_completion) override;
50 55
51 private: 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
52 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 61 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
53 base::Closure continue_to_completion_callback_; 62 base::Closure continue_to_completion_callback_;
54 63
55 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverCompletionInhibitor); 64 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverCompletionInhibitor);
56 }; 65 };
57 66
58 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_TEST_UTIL_H_ 67 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698