Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / chrome / browser / profiles / profile_destroyer.h
blob62aa7c1348bc28552763d373b719dd035eae740e
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 <vector>
10 #include "base/memory/ref_counted.h"
11 #include "base/timer.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
15 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
23 : public content::NotificationObserver,
24 public base::RefCounted<ProfileDestroyer> {
25 public:
26 static void DestroyProfileWhenAppropriate(Profile* const profile);
27 static void DestroyOffTheRecordProfileNow(Profile* const profile);
29 private:
30 friend class base::RefCounted<ProfileDestroyer>;
32 ProfileDestroyer(
33 Profile* const profile,
34 const std::vector<content::RenderProcessHost*>& hosts);
35 virtual ~ProfileDestroyer();
37 // content::NotificationObserver override.
38 virtual void Observe(int type,
39 const content::NotificationSource& source,
40 const content::NotificationDetails& details) OVERRIDE;
41 // Called by the timer to cancel the pending detruction and do it now.
42 void DestroyProfile();
44 // Fetch the list of render process hosts that still refer to the profile.
45 // Return true if we found at least one, false otherwise.
46 static bool GetHostsForProfile(
47 Profile* const profile,
48 std::vector<content::RenderProcessHost*> *hosts);
50 // We need access to all pending destroyers so we can cancel them.
51 static std::vector<ProfileDestroyer*>* pending_destroyers_;
53 // We register for render process host termination.
54 content::NotificationRegistrar registrar_;
56 // We don't want to wait forever, so we have a cancellation timer.
57 base::Timer timer_;
59 // Used to count down the number of render process host left.
60 uint32 num_hosts_;
62 Profile* profile_;
64 DISALLOW_COPY_AND_ASSIGN(ProfileDestroyer);
67 #endif // CHROME_BROWSER_PROFILES_PROFILE_DESTROYER_H_