Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / extensions / chrome_notification_observer.cc
blobaf7f796069c88af9485464c7e1cdade95d0f1834
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.
5 #include "chrome/browser/extensions/chrome_notification_observer.h"
7 #include "base/logging.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/extensions/extension_system.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "content/public/browser/notification_service.h"
13 #include "extensions/browser/process_manager.h"
15 namespace extensions {
17 ChromeNotificationObserver::ChromeNotificationObserver() {
18 // Notifications for extensions::ProcessManager
19 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY,
20 content::NotificationService::AllSources());
23 ChromeNotificationObserver::~ChromeNotificationObserver() {}
25 void ChromeNotificationObserver::OnBrowserWindowReady(Browser* browser) {
26 Profile* profile = browser->profile();
27 DCHECK(profile);
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 extensions::ProcessManager* 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();
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.
43 if (profile->IsOffTheRecord()) {
44 Profile* original_profile = profile->GetOriginalProfile();
45 extensions::ProcessManager* 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();
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;
63 default:
64 NOTREACHED();
68 } // namespace extensions