Changes for start_with_ext Telemetry test to work on Windows.
[chromium-blink-merge.git] / chrome / browser / profiles / profile_destroyer.h
blob59b705bbd99e5f97345ed6bcf6202d41c6d8e170
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_PROFILES_PROFILE_DESTROYER_H_
6 #define CHROME_BROWSER_PROFILES_PROFILE_DESTROYER_H_
8 #include <set>
10 #include "base/memory/ref_counted.h"
11 #include "base/timer/timer.h"
12 #include "content/public/browser/render_process_host_observer.h"
14 class Profile;
16 namespace content {
17 class RenderProcessHost;
20 // We use this class to destroy the off the record profile so that we can make
21 // sure it gets done asynchronously after all render process hosts are gone.
22 class ProfileDestroyer : public content::RenderProcessHostObserver {
23 public:
24 static void DestroyProfileWhenAppropriate(Profile* const profile);
25 static void DestroyOffTheRecordProfileNow(Profile* const profile);
27 private:
28 typedef std::set<content::RenderProcessHost*> HostSet;
29 typedef std::set<ProfileDestroyer*> DestroyerSet;
31 friend class base::RefCounted<ProfileDestroyer>;
33 ProfileDestroyer(Profile* const profile, HostSet* hosts);
34 ~ProfileDestroyer() override;
36 // content::RenderProcessHostObserver override.
37 void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;
39 // Called by the timer to cancel the pending destruction and do it now.
40 void DestroyProfile();
42 // Fetch the list of render process hosts that still refer to the profile.
43 // Return true if we found at least one, false otherwise.
44 static bool GetHostsForProfile(Profile* const profile, HostSet* hosts);
46 // We need access to all pending destroyers so we can cancel them.
47 static DestroyerSet* pending_destroyers_;
49 // We don't want to wait forever, so we have a cancellation timer.
50 base::Timer timer_;
52 // Used to count down the number of render process host left.
53 uint32 num_hosts_;
55 // The profile being destroyed. If it is set to NULL, it is a signal from
56 // another instance of ProfileDestroyer that this instance is canceled.
57 Profile* profile_;
59 base::WeakPtrFactory<ProfileDestroyer> weak_ptr_factory_;
61 DISALLOW_COPY_AND_ASSIGN(ProfileDestroyer);
64 #endif // CHROME_BROWSER_PROFILES_PROFILE_DESTROYER_H_