OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_PROFILES_PROFILE_DESTROYER_H_ | 5 #ifndef CHROME_BROWSER_PROFILES_PROFILE_DESTROYER_H_ |
6 #define CHROME_BROWSER_PROFILES_PROFILE_DESTROYER_H_ | 6 #define CHROME_BROWSER_PROFILES_PROFILE_DESTROYER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "content/public/browser/notification_observer.h" | 12 #include "content/public/browser/notification_observer.h" |
13 #include "content/public/browser/notification_registrar.h" | 13 #include "content/public/browser/notification_registrar.h" |
14 | 14 |
15 class Profile; | 15 class Profile; |
16 namespace content { | 16 namespace content { |
17 class RenderProcessHost; | 17 class RenderProcessHost; |
18 } | 18 } |
19 | 19 |
20 // We use this class to destroy the off the record profile so that we can make | 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. | 21 // sure it gets done asynchronously after all render process hosts are gone. |
22 class ProfileDestroyer | 22 class ProfileDestroyer |
23 : public content::NotificationObserver, | 23 : public content::NotificationObserver, |
24 public base::RefCounted<ProfileDestroyer> { | 24 public base::RefCounted<ProfileDestroyer> { |
25 public: | 25 public: |
26 static void DestroyOffTheRecordProfile(Profile* const profile); | 26 static void DestroyProfileWhenAppropriate(Profile* const profile); |
27 | 27 |
28 private: | 28 private: |
29 friend class base::RefCounted<ProfileDestroyer>; | 29 friend class base::RefCounted<ProfileDestroyer>; |
30 | 30 |
31 ProfileDestroyer( | 31 ProfileDestroyer( |
32 Profile* const profile, | 32 Profile* const profile, |
33 const std::vector<content::RenderProcessHost*>& hosts); | 33 const std::vector<content::RenderProcessHost*>& hosts); |
34 virtual ~ProfileDestroyer(); | 34 virtual ~ProfileDestroyer(); |
35 | 35 |
36 // content::NotificationObserver override. | 36 // content::NotificationObserver override. |
37 virtual void Observe(int type, | 37 virtual void Observe(int type, |
38 const content::NotificationSource& source, | 38 const content::NotificationSource& source, |
39 const content::NotificationDetails& details) OVERRIDE; | 39 const content::NotificationDetails& details) OVERRIDE; |
40 | 40 |
41 // Fetch the list of render process hosts that still refer to the profile. | 41 // Fetch the list of render process hosts that still refer to the profile. |
42 // Return true if we found at least one, false otherwise. | 42 // Return true if we found at least one, false otherwise. |
43 static bool GetHostsForProfile( | 43 static bool GetHostsForProfile( |
44 Profile* const profile, | 44 Profile* const profile, |
45 std::vector<content::RenderProcessHost*> *hosts); | 45 std::vector<content::RenderProcessHost*> *hosts); |
46 | 46 |
47 content::NotificationRegistrar registrar_; | 47 content::NotificationRegistrar registrar_; |
48 Profile* const profile_; | 48 Profile* const profile_; |
49 | 49 |
50 DISALLOW_COPY_AND_ASSIGN(ProfileDestroyer); | 50 DISALLOW_COPY_AND_ASSIGN(ProfileDestroyer); |
51 }; | 51 }; |
52 | 52 |
53 #endif // CHROME_BROWSER_PROFILES_PROFILE_DESTROYER_H_ | 53 #endif // CHROME_BROWSER_PROFILES_PROFILE_DESTROYER_H_ |
OLD | NEW |