Use DownloadManager::Observer in TestDownloadShelf

Use DownloadManager::Observer interface to track the lifetime of
DownloadManager instead of keeping a counted reference to it.

This will easy the transition of DownloadManager from being refcounted
to be owned by the BrowserContext.

BUG=237871
TEST=unit_tests with filter for Download\*

Review URL: https://chromiumcodereview.appspot.com/15575002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201768 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/download/test_download_shelf.cc b/chrome/browser/download/test_download_shelf.cc
index c28cb03..9538b7cd 100644
--- a/chrome/browser/download/test_download_shelf.cc
+++ b/chrome/browser/download/test_download_shelf.cc
@@ -8,10 +8,13 @@
 
 TestDownloadShelf::TestDownloadShelf()
     : is_showing_(false),
-      did_add_download_(false) {
+      did_add_download_(false),
+      download_manager_(NULL) {
 }
 
 TestDownloadShelf::~TestDownloadShelf() {
+  if (download_manager_)
+    download_manager_->RemoveObserver(this);
 }
 
 bool TestDownloadShelf::IsShowing() const {
@@ -28,7 +31,16 @@
 
 void TestDownloadShelf::set_download_manager(
     content::DownloadManager* download_manager) {
+  if (download_manager_)
+    download_manager_->RemoveObserver(this);
   download_manager_ = download_manager;
+  if (download_manager_)
+    download_manager_->AddObserver(this);
+}
+
+void TestDownloadShelf::ManagerGoingDown(content::DownloadManager* manager) {
+  DCHECK_EQ(manager, download_manager_);
+  download_manager_ = NULL;
 }
 
 void TestDownloadShelf::DoAddDownload(content::DownloadItem* download) {
@@ -48,5 +60,5 @@
 }
 
 content::DownloadManager* TestDownloadShelf::GetDownloadManager() {
-  return download_manager_.get();
+  return download_manager_;
 }