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

Side by Side Diff: chrome/browser/download/download_ui_controller.cc

Issue 1236003005: Move closing-blank-tab logic in Browser class to DownloadUIConttroller (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 5 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/download/download_ui_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "chrome/browser/download/download_item_model.h" 10 #include "chrome/browser/download/download_item_model.h"
11 #include "chrome/browser/download/download_shelf.h"
11 #include "chrome/browser/ui/browser_finder.h" 12 #include "chrome/browser/ui/browser_finder.h"
12 #include "chrome/browser/ui/browser_tabstrip.h" 13 #include "chrome/browser/ui/browser_tabstrip.h"
14 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
14 #include "content/public/browser/download_item.h" 17 #include "content/public/browser/download_item.h"
15 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_contents_delegate.h" 19 #include "content/public/browser/web_contents_delegate.h"
17 20
18 #if defined(OS_ANDROID) 21 #if defined(OS_ANDROID)
19 #include "content/public/browser/android/download_controller_android.h" 22 #include "content/public/browser/android/download_controller_android.h"
20 #else 23 #else
21 #include "chrome/browser/download/notification/download_notification_manager.h" 24 #include "chrome/browser/download/notification/download_notification_manager.h"
22 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 Browser* browser = 81 Browser* browser =
79 web_contents ? chrome::FindBrowserWithWebContents(web_contents) : NULL; 82 web_contents ? chrome::FindBrowserWithWebContents(web_contents) : NULL;
80 83
81 // As a last resort, use the last active browser for this profile. Not ideal, 84 // As a last resort, use the last active browser for this profile. Not ideal,
82 // but better than not showing the download at all. 85 // but better than not showing the download at all.
83 if (browser == NULL) { 86 if (browser == NULL) {
84 browser = chrome::FindLastActiveWithProfile(profile_, 87 browser = chrome::FindLastActiveWithProfile(profile_,
85 chrome::GetActiveDesktop()); 88 chrome::GetActiveDesktop());
86 } 89 }
87 90
88 if (browser) 91 if (browser && browser->window() &&
89 browser->ShowDownload(item); 92 // Some (app downloads) are not supposed to appear on the shelf.
msw 2015/07/17 01:15:34 nit: please move this comment above the start of t
yoshiki 2015/07/17 01:40:04 Done. Removed the first comment.
93 DownloadItemModel(item).ShouldShowInShelf()) {
94 // GetDownloadShelf creates the download shelf if it was not yet created.
95 browser->window()->GetDownloadShelf()->AddDownload(item);
96 }
90 } 97 }
91 98
92 #endif // !OS_ANDROID 99 #endif // !OS_ANDROID
93 100
94 } // namespace 101 } // namespace
95 102
96 DownloadUIController::Delegate::~Delegate() { 103 DownloadUIController::Delegate::~Delegate() {
97 } 104 }
98 105
99 DownloadUIController::DownloadUIController(content::DownloadManager* manager, 106 DownloadUIController::DownloadUIController(content::DownloadManager* manager,
(...skipping 22 matching lines...) Expand all
122 DownloadUIController::~DownloadUIController() { 129 DownloadUIController::~DownloadUIController() {
123 } 130 }
124 131
125 void DownloadUIController::OnDownloadCreated(content::DownloadManager* manager, 132 void DownloadUIController::OnDownloadCreated(content::DownloadManager* manager,
126 content::DownloadItem* item) { 133 content::DownloadItem* item) {
127 // 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
128 // browser. Call OnDownloadUpdated() once to notify the UI immediately. 135 // browser. Call OnDownloadUpdated() once to notify the UI immediately.
129 OnDownloadUpdated(manager, item); 136 OnDownloadUpdated(manager, item);
130 } 137 }
131 138
132 void DownloadUIController::OnDownloadUpdated(content::DownloadManager* manager, 139 void DownloadUIController::OnDownloadUpdated(content::DownloadManager* manager,
msw 2015/07/17 01:15:35 OnDownloadUpdated is called (via DownloadItemImpl:
yoshiki 2015/07/17 01:40:04 Thank you for pointing out. But any new performan
msw 2015/07/17 02:11:33 Ah, I totally missed that, thanks for the explanat
133 content::DownloadItem* item) { 140 content::DownloadItem* item) {
134 DownloadItemModel item_model(item); 141 DownloadItemModel item_model(item);
135 142
136 // Ignore if we've already notified the UI about |item| or if it isn't a new 143 // Ignore if we've already notified the UI about |item| or if it isn't a new
137 // download. 144 // download.
138 if (item_model.WasUINotified() || !item_model.ShouldNotifyUI()) 145 if (item_model.WasUINotified() || !item_model.ShouldNotifyUI())
139 return; 146 return;
140 147
141 // Wait until the target path is determined. 148 // Wait until the target path is determined.
142 if (item->GetTargetFilePath().empty()) 149 if (item->GetTargetFilePath().empty())
143 return; 150 return;
144 151
145 DownloadItemModel(item).SetWasUINotified(true); 152 DownloadItemModel(item).SetWasUINotified(true);
153
154 #if !defined(OS_ANDROID)
155 content::WebContents* web_contents = item->GetWebContents();
156 if (web_contents) {
157 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
158 // If the download occurs in a new tab, and it's not a save page
159 // download (started before initial navigation completed) close it.
160 // Avoid calling CloseContents if the tab is not in this browser's tab strip
161 // model; this can happen if the download was initiated by something
162 // internal to Chrome, such as by the app list.
163 if (browser && web_contents->GetController().IsInitialNavigation() &&
164 browser->tab_strip_model()->count() > 1 &&
165 browser->tab_strip_model()->GetIndexOfWebContents(web_contents) !=
166 TabStripModel::kNoTab &&
167 !item->IsSavePackageDownload()) {
168 web_contents->Close();
msw 2015/07/17 01:15:34 Will changing Browser::CloseContents to WebContent
yoshiki 2015/07/17 01:40:04 WebContents::Close calls Browser::CloseContents in
msw 2015/07/17 02:11:33 Acknowledged.
169 }
170 }
171 #endif
172
146 delegate_->OnNewDownloadReady(item); 173 delegate_->OnNewDownloadReady(item);
147 } 174 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_ui_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698