| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/background/background_contents_service.h" | 5 #include "chrome/browser/background/background_contents_service.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "chrome/browser/background/background_contents_service_factory.h" | 13 #include "chrome/browser/background/background_contents_service_factory.h" |
| 13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/extensions/extension_host.h" | 15 #include "chrome/browser/extensions/extension_host.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/notifications/desktop_notification_service.h" | 17 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 17 #include "chrome/browser/notifications/notification.h" | 18 #include "chrome/browser/notifications/notification.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 37 | 38 |
| 38 const char kNotificationPrefix[] = "app.background.crashed."; | 39 const char kNotificationPrefix[] = "app.background.crashed."; |
| 39 | 40 |
| 40 void CloseBalloon(const std::string id) { | 41 void CloseBalloon(const std::string id) { |
| 41 g_browser_process->notification_ui_manager()->CancelById(id); | 42 g_browser_process->notification_ui_manager()->CancelById(id); |
| 42 } | 43 } |
| 43 | 44 |
| 44 void ScheduleCloseBalloon(const std::string& extension_id) { | 45 void ScheduleCloseBalloon(const std::string& extension_id) { |
| 45 if (!MessageLoop::current()) // For unit_tests | 46 if (!MessageLoop::current()) // For unit_tests |
| 46 return; | 47 return; |
| 47 MessageLoop::current()->PostTask(FROM_HERE, | 48 MessageLoop::current()->PostTask( |
| 48 NewRunnableFunction(&CloseBalloon, | 49 FROM_HERE, base::Bind(&CloseBalloon, kNotificationPrefix + extension_id)); |
| 49 kNotificationPrefix + extension_id)); | |
| 50 } | 50 } |
| 51 | 51 |
| 52 class CrashNotificationDelegate : public NotificationDelegate { | 52 class CrashNotificationDelegate : public NotificationDelegate { |
| 53 public: | 53 public: |
| 54 CrashNotificationDelegate(Profile* profile, const Extension* extension) | 54 CrashNotificationDelegate(Profile* profile, const Extension* extension) |
| 55 : profile_(profile), | 55 : profile_(profile), |
| 56 is_hosted_app_(extension->is_hosted_app()), | 56 is_hosted_app_(extension->is_hosted_app()), |
| 57 extension_id_(extension->id()) { | 57 extension_id_(extension->id()) { |
| 58 } | 58 } |
| 59 | 59 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 extension = extension_host->extension(); | 286 extension = extension_host->extension(); |
| 287 } | 287 } |
| 288 if (!extension) | 288 if (!extension) |
| 289 break; | 289 break; |
| 290 | 290 |
| 291 // When an extension crashes, EXTENSION_PROCESS_TERMINATED is followed by | 291 // When an extension crashes, EXTENSION_PROCESS_TERMINATED is followed by |
| 292 // an EXTENSION_UNLOADED notification. This UNLOADED signal causes all the | 292 // an EXTENSION_UNLOADED notification. This UNLOADED signal causes all the |
| 293 // notifications for this extension to be cancelled by | 293 // notifications for this extension to be cancelled by |
| 294 // DesktopNotificationService. For this reason, instead of showing the | 294 // DesktopNotificationService. For this reason, instead of showing the |
| 295 // balloon right now, we schedule it to show a little later. | 295 // balloon right now, we schedule it to show a little later. |
| 296 MessageLoop::current()->PostTask(FROM_HERE, | 296 MessageLoop::current()->PostTask( |
| 297 NewRunnableFunction(&ShowBalloon, extension, profile)); | 297 FROM_HERE, base::Bind(&ShowBalloon, extension, profile)); |
| 298 break; | 298 break; |
| 299 } | 299 } |
| 300 case chrome::NOTIFICATION_EXTENSION_UNLOADED: | 300 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
| 301 switch (content::Details<UnloadedExtensionInfo>(details)->reason) { | 301 switch (content::Details<UnloadedExtensionInfo>(details)->reason) { |
| 302 // Intentionally fall through. | 302 // Intentionally fall through. |
| 303 case extension_misc::UNLOAD_REASON_DISABLE: | 303 case extension_misc::UNLOAD_REASON_DISABLE: |
| 304 case extension_misc::UNLOAD_REASON_UNINSTALL: | 304 case extension_misc::UNLOAD_REASON_UNINSTALL: |
| 305 ShutdownAssociatedBackgroundContents( | 305 ShutdownAssociatedBackgroundContents( |
| 306 ASCIIToUTF16(content::Details<UnloadedExtensionInfo>(details)-> | 306 ASCIIToUTF16(content::Details<UnloadedExtensionInfo>(details)-> |
| 307 extension->id())); | 307 extension->id())); |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 TabContents* new_contents, | 574 TabContents* new_contents, |
| 575 WindowOpenDisposition disposition, | 575 WindowOpenDisposition disposition, |
| 576 const gfx::Rect& initial_pos, | 576 const gfx::Rect& initial_pos, |
| 577 bool user_gesture) { | 577 bool user_gesture) { |
| 578 Browser* browser = BrowserList::GetLastActiveWithProfile( | 578 Browser* browser = BrowserList::GetLastActiveWithProfile( |
| 579 Profile::FromBrowserContext(new_contents->browser_context())); | 579 Profile::FromBrowserContext(new_contents->browser_context())); |
| 580 if (!browser) | 580 if (!browser) |
| 581 return; | 581 return; |
| 582 browser->AddTabContents(new_contents, disposition, initial_pos, user_gesture); | 582 browser->AddTabContents(new_contents, disposition, initial_pos, user_gesture); |
| 583 } | 583 } |
| OLD | NEW |