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

Unified Diff: chrome/browser/download/download_extension_api.cc

Issue 8804018: Delay DownloadManager creation by adding a callback queue to DownloadService (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: comments Created 9 years 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 | « chrome/browser/download/download_extension_api.h ('k') | chrome/browser/download/download_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/download_extension_api.cc
diff --git a/chrome/browser/download/download_extension_api.cc b/chrome/browser/download/download_extension_api.cc
index ecc78c9ff5b0c519ebdf2d3c9623253456e020f2..b60ce59df28b63e1a1e1e828474f13ab493fa87f 100644
--- a/chrome/browser/download/download_extension_api.cc
+++ b/chrome/browser/download/download_extension_api.cc
@@ -11,6 +11,7 @@
#include <string>
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
@@ -474,16 +475,24 @@ base::DictionaryValue* DownloadItemToJSON(DownloadItem* item) {
}
} // anonymous namespace
-ExtensionDownloadsEventRouter::ExtensionDownloadsEventRouter(
- Profile* profile)
+ExtensionDownloadsEventRouter::ExtensionDownloadsEventRouter(Profile* profile)
: profile_(profile),
- manager_(
- profile ?
- DownloadServiceFactory::GetForProfile(profile)->GetDownloadManager() :
- NULL) {
+ manager_(NULL) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(profile_);
- DCHECK(manager_);
+ // Register a callback with the DownloadService for this profile to be called
+ // when it creates the DownloadManager, or now if the manager already exists.
+ DownloadServiceFactory::GetForProfile(profile)->OnManagerCreated(base::Bind(
+ &ExtensionDownloadsEventRouter::Init, base::Unretained(this)));
+}
+
+// The only public methods on this class are ModelChanged() and
+// ManagerGoingDown(), and they are only called by DownloadManager, so
+// there's no way for any methods on this class to be called before
+// DownloadService calls Init() via the OnManagerCreated Callback above.
+void ExtensionDownloadsEventRouter::Init(DownloadManager* manager) {
+ DCHECK(manager_ == NULL);
+ manager_ = manager;
manager_->AddObserver(this);
}
« no previous file with comments | « chrome/browser/download/download_extension_api.h ('k') | chrome/browser/download/download_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698