OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/extensions/chrome_notification_observer.h" | |
6 | |
7 #include "base/logging.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" | |
11 #include "chrome/browser/profiles/profile.h" | |
12 #include "chrome/browser/ui/browser.h" | |
13 #include "content/public/browser/notification_service.h" | |
14 | |
15 namespace extensions { | |
16 | |
17 ChromeNotificationObserver::ChromeNotificationObserver() { | |
18 // Notifications for ExtensionProcessManager | |
19 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, | |
20 content::NotificationService::AllSources()); | |
21 } | |
22 | |
23 ChromeNotificationObserver::~ChromeNotificationObserver() {} | |
24 | |
25 void ChromeNotificationObserver::OnBrowserWindowReady(Browser* browser) { | |
26 Profile* profile = browser->profile(); | |
27 DCHECK(profile); | |
28 | |
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 | |
31 // a related incognito profile or other regular profiles. | |
32 ExtensionProcessManager* manager = | |
33 ExtensionSystem::Get(profile)->process_manager(); | |
34 if (!manager) // Tests may not have a process manager. | |
35 return; | |
36 DCHECK_EQ(profile, manager->GetBrowserContext()); | |
37 manager->OnBrowserWindowReady(); | |
38 | |
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 | |
41 // original profile's process manager should have been informed when the | |
42 // non-incognito window opened. | |
James Cook
2013/11/01 20:53:12
This code replicates the behavior of the NOTIFICAT
| |
43 if (profile->IsOffTheRecord()) { | |
44 Profile* original_profile = profile->GetOriginalProfile(); | |
45 ExtensionProcessManager* original_manager = | |
46 ExtensionSystem::Get(original_profile)->process_manager(); | |
47 DCHECK(original_manager); | |
48 DCHECK_EQ(original_profile, original_manager->GetBrowserContext()); | |
49 original_manager->OnBrowserWindowReady(); | |
50 } | |
51 } | |
52 | |
53 void ChromeNotificationObserver::Observe(int type, | |
54 const content::NotificationSource& source, | |
55 const content::NotificationDetails& details) { | |
56 switch (type) { | |
57 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { | |
58 Browser* browser = content::Source<Browser>(source).ptr(); | |
59 OnBrowserWindowReady(browser); | |
60 break; | |
61 } | |
62 | |
63 default: | |
64 NOTREACHED(); | |
65 } | |
66 } | |
67 | |
68 } // namespace extensions | |
OLD | NEW |