OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_notification_observer.h" | 5 #include "chrome/browser/extensions/chrome_notification_observer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/extensions/extension_process_manager.h" | |
10 #include "chrome/browser/extensions/extension_system.h" | 9 #include "chrome/browser/extensions/extension_system.h" |
11 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
13 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
| 13 #include "extensions/browser/process_manager.h" |
14 | 14 |
15 namespace extensions { | 15 namespace extensions { |
16 | 16 |
17 ChromeNotificationObserver::ChromeNotificationObserver() { | 17 ChromeNotificationObserver::ChromeNotificationObserver() { |
18 // Notifications for ExtensionProcessManager | 18 // Notifications for extensions::ProcessManager |
19 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 19 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
20 content::NotificationService::AllSources()); | 20 content::NotificationService::AllSources()); |
21 } | 21 } |
22 | 22 |
23 ChromeNotificationObserver::~ChromeNotificationObserver() {} | 23 ChromeNotificationObserver::~ChromeNotificationObserver() {} |
24 | 24 |
25 void ChromeNotificationObserver::OnBrowserWindowReady(Browser* browser) { | 25 void ChromeNotificationObserver::OnBrowserWindowReady(Browser* browser) { |
26 Profile* profile = browser->profile(); | 26 Profile* profile = browser->profile(); |
27 DCHECK(profile); | 27 DCHECK(profile); |
28 | 28 |
29 // Inform the process manager for this profile that the window is ready. | 29 // Inform the process manager for this profile that the window is ready. |
30 // We continue to observe the notification in case browser windows open for | 30 // We continue to observe the notification in case browser windows open for |
31 // a related incognito profile or other regular profiles. | 31 // a related incognito profile or other regular profiles. |
32 ExtensionProcessManager* manager = | 32 extensions::ProcessManager* manager = |
33 ExtensionSystem::Get(profile)->process_manager(); | 33 ExtensionSystem::Get(profile)->process_manager(); |
34 if (!manager) // Tests may not have a process manager. | 34 if (!manager) // Tests may not have a process manager. |
35 return; | 35 return; |
36 DCHECK_EQ(profile, manager->GetBrowserContext()); | 36 DCHECK_EQ(profile, manager->GetBrowserContext()); |
37 manager->OnBrowserWindowReady(); | 37 manager->OnBrowserWindowReady(); |
38 | 38 |
39 // For incognito profiles also inform the original profile's process manager | 39 // For incognito profiles also inform the original profile's process manager |
40 // that the window is ready. This will usually be a no-op because the | 40 // that the window is ready. This will usually be a no-op because the |
41 // original profile's process manager should have been informed when the | 41 // original profile's process manager should have been informed when the |
42 // non-incognito window opened. | 42 // non-incognito window opened. |
43 if (profile->IsOffTheRecord()) { | 43 if (profile->IsOffTheRecord()) { |
44 Profile* original_profile = profile->GetOriginalProfile(); | 44 Profile* original_profile = profile->GetOriginalProfile(); |
45 ExtensionProcessManager* original_manager = | 45 extensions::ProcessManager* original_manager = |
46 ExtensionSystem::Get(original_profile)->process_manager(); | 46 ExtensionSystem::Get(original_profile)->process_manager(); |
47 DCHECK(original_manager); | 47 DCHECK(original_manager); |
48 DCHECK_EQ(original_profile, original_manager->GetBrowserContext()); | 48 DCHECK_EQ(original_profile, original_manager->GetBrowserContext()); |
49 original_manager->OnBrowserWindowReady(); | 49 original_manager->OnBrowserWindowReady(); |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 void ChromeNotificationObserver::Observe(int type, | 53 void ChromeNotificationObserver::Observe(int type, |
54 const content::NotificationSource& source, | 54 const content::NotificationSource& source, |
55 const content::NotificationDetails& details) { | 55 const content::NotificationDetails& details) { |
56 switch (type) { | 56 switch (type) { |
57 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { | 57 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { |
58 Browser* browser = content::Source<Browser>(source).ptr(); | 58 Browser* browser = content::Source<Browser>(source).ptr(); |
59 OnBrowserWindowReady(browser); | 59 OnBrowserWindowReady(browser); |
60 break; | 60 break; |
61 } | 61 } |
62 | 62 |
63 default: | 63 default: |
64 NOTREACHED(); | 64 NOTREACHED(); |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 } // namespace extensions | 68 } // namespace extensions |
OLD | NEW |