Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: chrome/browser/usb/usb_service.cc

Issue 23483014: Graceful shutdown of UsbService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to origin/master Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/usb/usb_service.cc
diff --git a/chrome/browser/usb/usb_service.cc b/chrome/browser/usb/usb_service.cc
index 0d575fbf3733dc644d12713f69b6645c6b24034a..b44c1fa0136871e2492564da77d2312348ee8b4f 100644
--- a/chrome/browser/usb/usb_service.cc
+++ b/chrome/browser/usb/usb_service.cc
@@ -38,8 +38,12 @@ namespace {
class ExitObserver : public content::NotificationObserver {
public:
explicit ExitObserver(UsbService* service) : service_(service) {
- registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
- content::NotificationService::AllSources());
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&content::NotificationRegistrar::Add,
+ base::Unretained(&registrar_), this,
+ chrome::NOTIFICATION_APP_TERMINATING,
+ content::NotificationService::AllSources()));
}
private:
@@ -48,8 +52,8 @@ class ExitObserver : public content::NotificationObserver {
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE {
if (type == chrome::NOTIFICATION_APP_TERMINATING) {
- registrar_.RemoveAll();
BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, service_);
+ delete this;
}
}
UsbService* service_;
@@ -64,6 +68,8 @@ UsbService::UsbService()
: context_(new UsbContext()),
next_unique_id_(0) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ // Will be deleted upon NOTIFICATION_APP_TERMINATING.
+ new ExitObserver(this);
}
UsbService::~UsbService() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698