| 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 "base/timer.h" | 
|  12 #include "content/public/browser/notification_observer.h" |  13 #include "content/public/browser/notification_observer.h" | 
|  13 #include "content/public/browser/notification_registrar.h" |  14 #include "content/public/browser/notification_registrar.h" | 
|  14  |  15  | 
|  15 class Profile; |  16 class Profile; | 
|  16 namespace content { |  17 namespace content { | 
|  17 class RenderProcessHost; |  18 class RenderProcessHost; | 
|  18 } |  19 } | 
|  19  |  20  | 
|  20 // We use this class to destroy the off the record profile so that we can make |  21 // 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 // sure it gets done asynchronously after all render process hosts are gone. | 
|  22 class ProfileDestroyer |  23 class ProfileDestroyer | 
|  23     : public content::NotificationObserver, |  24     : public content::NotificationObserver, | 
|  24       public base::RefCounted<ProfileDestroyer> { |  25       public base::RefCounted<ProfileDestroyer> { | 
|  25  public: |  26  public: | 
|  26   static void DestroyProfileWhenAppropriate(Profile* const profile); |  27   static void DestroyProfileWhenAppropriate(Profile* const profile); | 
 |  28   static void DestroyOffTheRecordProfileNow(Profile* const profile); | 
|  27  |  29  | 
|  28  private: |  30  private: | 
|  29   friend class base::RefCounted<ProfileDestroyer>; |  31   friend class base::RefCounted<ProfileDestroyer>; | 
|  30  |  32  | 
|  31   ProfileDestroyer( |  33   ProfileDestroyer( | 
|  32       Profile* const profile, |  34       Profile* const profile, | 
|  33       const std::vector<content::RenderProcessHost*>& hosts); |  35       const std::vector<content::RenderProcessHost*>& hosts); | 
|  34   virtual ~ProfileDestroyer(); |  36   virtual ~ProfileDestroyer(); | 
|  35  |  37  | 
|  36   // content::NotificationObserver override. |  38   // content::NotificationObserver override. | 
|  37   virtual void Observe(int type, |  39   virtual void Observe(int type, | 
|  38                        const content::NotificationSource& source, |  40                        const content::NotificationSource& source, | 
|  39                        const content::NotificationDetails& details) OVERRIDE; |  41                        const content::NotificationDetails& details) OVERRIDE; | 
 |  42   // Called by the timer to cancel the pending detruction and do it now. | 
 |  43   void DestroyProfile(); | 
|  40  |  44  | 
|  41   // Fetch the list of render process hosts that still refer to the profile. |  45   // Fetch the list of render process hosts that still refer to the profile. | 
|  42   // Return true if we found at least one, false otherwise. |  46   // Return true if we found at least one, false otherwise. | 
|  43   static bool GetHostsForProfile( |  47   static bool GetHostsForProfile( | 
|  44       Profile* const profile, |  48       Profile* const profile, | 
|  45       std::vector<content::RenderProcessHost*> *hosts); |  49       std::vector<content::RenderProcessHost*> *hosts); | 
|  46  |  50  | 
 |  51   // We need access to all pending destroyers so we can cancel them. | 
 |  52   static std::vector<ProfileDestroyer*>* pending_destroyers_; | 
 |  53  | 
 |  54   // We register for render process host termination. | 
|  47   content::NotificationRegistrar registrar_; |  55   content::NotificationRegistrar registrar_; | 
|  48   Profile* const profile_; |  56  | 
 |  57   // We don't want to wait forever, so we have a cancellation timer. | 
 |  58   base::Timer timer_; | 
 |  59  | 
 |  60   // Used to count down the number of render process host left. | 
 |  61   uint32 num_hosts_; | 
 |  62  | 
 |  63   Profile* profile_; | 
|  49  |  64  | 
|  50   DISALLOW_COPY_AND_ASSIGN(ProfileDestroyer); |  65   DISALLOW_COPY_AND_ASSIGN(ProfileDestroyer); | 
|  51 }; |  66 }; | 
|  52  |  67  | 
|  53 #endif  // CHROME_BROWSER_PROFILES_PROFILE_DESTROYER_H_ |  68 #endif  // CHROME_BROWSER_PROFILES_PROFILE_DESTROYER_H_ | 
| OLD | NEW |