OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/download/download_ui_controller.h" | 5 #include "chrome/browser/download/download_ui_controller.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "chrome/browser/download/download_item_model.h" | 9 #include "chrome/browser/download/download_item_model.h" |
10 #include "chrome/browser/download/download_shelf.h" | 10 #include "chrome/browser/download/download_shelf.h" |
11 #include "chrome/browser/ui/browser_finder.h" | 11 #include "chrome/browser/ui/browser_finder.h" |
12 #include "chrome/browser/ui/browser_tabstrip.h" | 12 #include "chrome/browser/ui/browser_tabstrip.h" |
13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "content/public/browser/download_item.h" | 15 #include "content/public/browser/download_item.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/browser/web_contents_delegate.h" | 17 #include "content/public/browser/web_contents_delegate.h" |
18 | 18 |
19 #if defined(OS_ANDROID) | 19 #if defined(OS_ANDROID) |
20 #include "content/public/browser/android/download_controller_android.h" | 20 #include "content/public/browser/android/download_controller_android.h" |
21 #else | 21 #else |
22 #include "chrome/browser/download/notification/download_notification_manager.h" | |
23 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/ui/browser_finder.h" | 23 #include "chrome/browser/ui/browser_finder.h" |
25 #include "chrome/browser/ui/host_desktop.h" | 24 #include "chrome/browser/ui/host_desktop.h" |
26 #endif | 25 #endif |
27 | 26 |
| 27 #if defined(OS_CHROMEOS) |
| 28 #include "chrome/browser/download/notification/download_notification_manager.h" |
| 29 #endif |
| 30 |
28 namespace { | 31 namespace { |
29 | 32 |
30 // DownloadShelfUIControllerDelegate{Android,} is used when a | 33 // DownloadShelfUIControllerDelegate{Android,} is used when a |
31 // DownloadUIController is | 34 // DownloadUIController is |
32 // constructed without specifying an explicit Delegate. | 35 // constructed without specifying an explicit Delegate. |
33 #if defined(OS_ANDROID) | 36 #if defined(OS_ANDROID) |
34 | 37 |
35 class AndroidUIControllerDelegate : public DownloadUIController::Delegate { | 38 class AndroidUIControllerDelegate : public DownloadUIController::Delegate { |
36 public: | 39 public: |
37 AndroidUIControllerDelegate() {} | 40 AndroidUIControllerDelegate() {} |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 100 |
98 } // namespace | 101 } // namespace |
99 | 102 |
100 DownloadUIController::Delegate::~Delegate() { | 103 DownloadUIController::Delegate::~Delegate() { |
101 } | 104 } |
102 | 105 |
103 DownloadUIController::DownloadUIController(content::DownloadManager* manager, | 106 DownloadUIController::DownloadUIController(content::DownloadManager* manager, |
104 scoped_ptr<Delegate> delegate) | 107 scoped_ptr<Delegate> delegate) |
105 : download_notifier_(manager, this), | 108 : download_notifier_(manager, this), |
106 delegate_(delegate.Pass()) { | 109 delegate_(delegate.Pass()) { |
107 if (!delegate_) { | |
108 #if defined(OS_ANDROID) | 110 #if defined(OS_ANDROID) |
| 111 if (!delegate_) |
109 delegate_.reset(new AndroidUIControllerDelegate()); | 112 delegate_.reset(new AndroidUIControllerDelegate()); |
110 #else | 113 #else |
111 // The delegate should not be invoked after the profile has gone away. This | 114 #if defined(OS_CHROMEOS) |
112 // should be the case since DownloadUIController is owned by | 115 if (!delegate_ && DownloadNotificationManager::IsEnabled()) { |
113 // DownloadService, which in turn is a profile keyed service. | 116 // The Profile is guaranteed to be valid since DownloadUIController is owned |
114 if (DownloadNotificationManager::IsEnabled()) { | 117 // by DownloadService, which in turn is a profile keyed service. |
115 delegate_.reset(new DownloadNotificationManager( | 118 delegate_.reset(new DownloadNotificationManager( |
116 Profile::FromBrowserContext(manager->GetBrowserContext()))); | 119 Profile::FromBrowserContext(manager->GetBrowserContext()))); |
117 } else { | |
118 delegate_.reset(new DownloadShelfUIControllerDelegate( | |
119 Profile::FromBrowserContext(manager->GetBrowserContext()))); | |
120 } | |
121 #endif | |
122 } | 120 } |
| 121 #endif // defined(OS_CHROMEOS) |
| 122 if (!delegate_) { |
| 123 delegate_.reset(new DownloadShelfUIControllerDelegate( |
| 124 Profile::FromBrowserContext(manager->GetBrowserContext()))); |
| 125 } |
| 126 #endif // defined(OS_ANDROID) |
123 } | 127 } |
124 | 128 |
125 DownloadUIController::~DownloadUIController() { | 129 DownloadUIController::~DownloadUIController() { |
126 } | 130 } |
127 | 131 |
128 void DownloadUIController::OnDownloadCreated(content::DownloadManager* manager, | 132 void DownloadUIController::OnDownloadCreated(content::DownloadManager* manager, |
129 content::DownloadItem* item) { | 133 content::DownloadItem* item) { |
130 // SavePackage downloads are created in a state where they can be shown in the | 134 // SavePackage downloads are created in a state where they can be shown in the |
131 // browser. Call OnDownloadUpdated() once to notify the UI immediately. | 135 // browser. Call OnDownloadUpdated() once to notify the UI immediately. |
132 OnDownloadUpdated(manager, item); | 136 OnDownloadUpdated(manager, item); |
(...skipping 28 matching lines...) Expand all Loading... |
161 browser->tab_strip_model()->GetIndexOfWebContents(web_contents) != | 165 browser->tab_strip_model()->GetIndexOfWebContents(web_contents) != |
162 TabStripModel::kNoTab && | 166 TabStripModel::kNoTab && |
163 !item->IsSavePackageDownload()) { | 167 !item->IsSavePackageDownload()) { |
164 web_contents->Close(); | 168 web_contents->Close(); |
165 } | 169 } |
166 } | 170 } |
167 #endif | 171 #endif |
168 | 172 |
169 delegate_->OnNewDownloadReady(item); | 173 delegate_->OnNewDownloadReady(item); |
170 } | 174 } |
OLD | NEW |