OLD | NEW |
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 #include "chrome/browser/extensions/chrome_process_manager_delegate.h" | 5 #include "chrome/browser/extensions/chrome_process_manager_delegate.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 namespace extensions { | 24 namespace extensions { |
25 | 25 |
26 ChromeProcessManagerDelegate::ChromeProcessManagerDelegate() { | 26 ChromeProcessManagerDelegate::ChromeProcessManagerDelegate() { |
27 registrar_.Add(this, | 27 registrar_.Add(this, |
28 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 28 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
29 content::NotificationService::AllSources()); | 29 content::NotificationService::AllSources()); |
30 registrar_.Add(this, | 30 registrar_.Add(this, |
31 chrome::NOTIFICATION_PROFILE_CREATED, | 31 chrome::NOTIFICATION_PROFILE_CREATED, |
32 content::NotificationService::AllSources()); | 32 content::NotificationService::AllSources()); |
33 // TODO(jamescook): Move observation of NOTIFICATION_PROFILE_DESTROYED here. | 33 registrar_.Add(this, |
34 // http://crbug.com/392658 | 34 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 35 content::NotificationService::AllSources()); |
35 } | 36 } |
36 | 37 |
37 ChromeProcessManagerDelegate::~ChromeProcessManagerDelegate() { | 38 ChromeProcessManagerDelegate::~ChromeProcessManagerDelegate() { |
38 } | 39 } |
39 | 40 |
40 bool ChromeProcessManagerDelegate::IsBackgroundPageAllowed( | 41 bool ChromeProcessManagerDelegate::IsBackgroundPageAllowed( |
41 content::BrowserContext* context) const { | 42 content::BrowserContext* context) const { |
42 Profile* profile = static_cast<Profile*>(context); | 43 Profile* profile = static_cast<Profile*>(context); |
43 | 44 |
44 // Disallow if the current session is a Guest mode session but the current | 45 // Disallow if the current session is a Guest mode session but the current |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { | 79 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { |
79 Browser* browser = content::Source<Browser>(source).ptr(); | 80 Browser* browser = content::Source<Browser>(source).ptr(); |
80 OnBrowserWindowReady(browser); | 81 OnBrowserWindowReady(browser); |
81 break; | 82 break; |
82 } | 83 } |
83 case chrome::NOTIFICATION_PROFILE_CREATED: { | 84 case chrome::NOTIFICATION_PROFILE_CREATED: { |
84 Profile* profile = content::Source<Profile>(source).ptr(); | 85 Profile* profile = content::Source<Profile>(source).ptr(); |
85 OnProfileCreated(profile); | 86 OnProfileCreated(profile); |
86 break; | 87 break; |
87 } | 88 } |
88 | 89 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
| 90 Profile* profile = content::Source<Profile>(source).ptr(); |
| 91 OnProfileDestroyed(profile); |
| 92 break; |
| 93 } |
89 default: | 94 default: |
90 NOTREACHED(); | 95 NOTREACHED(); |
91 } | 96 } |
92 } | 97 } |
93 | 98 |
94 void ChromeProcessManagerDelegate::OnBrowserWindowReady(Browser* browser) { | 99 void ChromeProcessManagerDelegate::OnBrowserWindowReady(Browser* browser) { |
95 Profile* profile = browser->profile(); | 100 Profile* profile = browser->profile(); |
96 DCHECK(profile); | 101 DCHECK(profile); |
97 | 102 |
98 // If the extension system isn't ready yet the background hosts will be | 103 // If the extension system isn't ready yet the background hosts will be |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 ProcessManager* manager = ExtensionSystem::Get(profile)->process_manager(); | 138 ProcessManager* manager = ExtensionSystem::Get(profile)->process_manager(); |
134 if (!manager) | 139 if (!manager) |
135 return; | 140 return; |
136 | 141 |
137 // The profile might have been initialized asynchronously (in parallel with | 142 // The profile might have been initialized asynchronously (in parallel with |
138 // extension system startup). Now that initialization is complete the | 143 // extension system startup). Now that initialization is complete the |
139 // ProcessManager can load deferred background pages. | 144 // ProcessManager can load deferred background pages. |
140 manager->MaybeCreateStartupBackgroundHosts(); | 145 manager->MaybeCreateStartupBackgroundHosts(); |
141 } | 146 } |
142 | 147 |
| 148 void ChromeProcessManagerDelegate::OnProfileDestroyed(Profile* profile) { |
| 149 // Close background hosts when the last profile is closed so that they |
| 150 // have time to shutdown various objects on different threads. The |
| 151 // ProfileManager destructor is called too late in the shutdown sequence. |
| 152 // http://crbug.com/15708 |
| 153 ProcessManager* manager = ExtensionSystem::Get(profile)->process_manager(); |
| 154 if (manager) |
| 155 manager->CloseBackgroundHosts(); |
| 156 |
| 157 // If this profile owns an incognito profile, but it is destroyed before the |
| 158 // incognito profile is destroyed, then close the incognito background hosts |
| 159 // as well. This happens in a few tests. http://crbug.com/138843 |
| 160 if (!profile->IsOffTheRecord() && profile->HasOffTheRecordProfile()) { |
| 161 ProcessManager* incognito_manager = |
| 162 ExtensionSystem::Get(profile->GetOffTheRecordProfile()) |
| 163 ->process_manager(); |
| 164 if (incognito_manager) |
| 165 incognito_manager->CloseBackgroundHosts(); |
| 166 } |
| 167 } |
| 168 |
143 } // namespace extensions | 169 } // namespace extensions |
OLD | NEW |