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

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

Issue 3177034: Makes the download shelf auto-close after the user opens all downloads (Closed)
Patch Set: Have OnDownloadOpened invoked before opened to match old behavior Created 10 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_item.h" 5 #include "chrome/browser/download/download_item.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/timer.h" 10 #include "base/timer.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 safety_state_(SAFE), 56 safety_state_(SAFE),
57 auto_opened_(false), 57 auto_opened_(false),
58 original_name_(info.original_name), 58 original_name_(info.original_name),
59 render_process_id_(-1), 59 render_process_id_(-1),
60 request_id_(-1), 60 request_id_(-1),
61 save_as_(false), 61 save_as_(false),
62 is_otr_(false), 62 is_otr_(false),
63 is_extension_install_(info.is_extension_install), 63 is_extension_install_(info.is_extension_install),
64 name_finalized_(false), 64 name_finalized_(false),
65 is_temporary_(false), 65 is_temporary_(false),
66 need_final_rename_(false) { 66 need_final_rename_(false),
67 opened_(false) {
67 if (state_ == IN_PROGRESS) 68 if (state_ == IN_PROGRESS)
68 state_ = CANCELLED; 69 state_ = CANCELLED;
69 Init(false /* don't start progress timer */); 70 Init(false /* don't start progress timer */);
70 } 71 }
71 72
72 // Constructing for a regular download: 73 // Constructing for a regular download:
73 DownloadItem::DownloadItem(DownloadManager* download_manager, 74 DownloadItem::DownloadItem(DownloadManager* download_manager,
74 const DownloadCreateInfo& info, 75 const DownloadCreateInfo& info,
75 bool is_otr) 76 bool is_otr)
76 : id_(info.download_id), 77 : id_(info.download_id),
(...skipping 15 matching lines...) Expand all
92 safety_state_(info.is_dangerous ? DANGEROUS : SAFE), 93 safety_state_(info.is_dangerous ? DANGEROUS : SAFE),
93 auto_opened_(false), 94 auto_opened_(false),
94 original_name_(info.original_name), 95 original_name_(info.original_name),
95 render_process_id_(info.child_id), 96 render_process_id_(info.child_id),
96 request_id_(info.request_id), 97 request_id_(info.request_id),
97 save_as_(info.prompt_user_for_save_location), 98 save_as_(info.prompt_user_for_save_location),
98 is_otr_(is_otr), 99 is_otr_(is_otr),
99 is_extension_install_(info.is_extension_install), 100 is_extension_install_(info.is_extension_install),
100 name_finalized_(false), 101 name_finalized_(false),
101 is_temporary_(!info.save_info.file_path.empty()), 102 is_temporary_(!info.save_info.file_path.empty()),
102 need_final_rename_(false) { 103 need_final_rename_(false),
104 opened_(false) {
103 Init(true /* start progress timer */); 105 Init(true /* start progress timer */);
104 } 106 }
105 107
106 // Constructing for the "Save Page As..." feature: 108 // Constructing for the "Save Page As..." feature:
107 DownloadItem::DownloadItem(DownloadManager* download_manager, 109 DownloadItem::DownloadItem(DownloadManager* download_manager,
108 const FilePath& path, 110 const FilePath& path,
109 const GURL& url, 111 const GURL& url,
110 bool is_otr) 112 bool is_otr)
111 : id_(1), 113 : id_(1),
112 full_path_(path), 114 full_path_(path),
(...skipping 14 matching lines...) Expand all
127 safety_state_(SAFE), 129 safety_state_(SAFE),
128 auto_opened_(false), 130 auto_opened_(false),
129 original_name_(FilePath()), 131 original_name_(FilePath()),
130 render_process_id_(-1), 132 render_process_id_(-1),
131 request_id_(-1), 133 request_id_(-1),
132 save_as_(false), 134 save_as_(false),
133 is_otr_(is_otr), 135 is_otr_(is_otr),
134 is_extension_install_(false), 136 is_extension_install_(false),
135 name_finalized_(false), 137 name_finalized_(false),
136 is_temporary_(false), 138 is_temporary_(false),
137 need_final_rename_(false) { 139 need_final_rename_(false),
140 opened_(false) {
138 Init(true /* start progress timer */); 141 Init(true /* start progress timer */);
139 } 142 }
140 143
141 DownloadItem::~DownloadItem() { 144 DownloadItem::~DownloadItem() {
142 state_ = REMOVING; 145 state_ = REMOVING;
143 UpdateObservers(); 146 UpdateObservers();
144 } 147 }
145 148
146 void DownloadItem::AddObserver(Observer* observer) { 149 void DownloadItem::AddObserver(Observer* observer) {
147 observers_.AddObserver(observer); 150 observers_.AddObserver(observer);
(...skipping 25 matching lines...) Expand all
173 } 176 }
174 177
175 void DownloadItem::OpenFilesBasedOnExtension(bool open) { 178 void DownloadItem::OpenFilesBasedOnExtension(bool open) {
176 return download_manager_->OpenFilesBasedOnExtension(full_path(), open); 179 return download_manager_->OpenFilesBasedOnExtension(full_path(), open);
177 } 180 }
178 181
179 void DownloadItem::OpenDownload() { 182 void DownloadItem::OpenDownload() {
180 if (state() == DownloadItem::IN_PROGRESS) { 183 if (state() == DownloadItem::IN_PROGRESS) {
181 open_when_complete_ = !open_when_complete_; 184 open_when_complete_ = !open_when_complete_;
182 } else if (state() == DownloadItem::COMPLETE) { 185 } else if (state() == DownloadItem::COMPLETE) {
183 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadOpened(this));
184 download_manager_->OpenDownload(this, NULL); 186 download_manager_->OpenDownload(this, NULL);
185 } 187 }
186 } 188 }
187 189
190 void DownloadItem::Opened() {
191 opened_ = true;
192 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadOpened(this));
193 }
194
188 void DownloadItem::ShowDownloadInShell() { 195 void DownloadItem::ShowDownloadInShell() {
189 download_manager_->ShowDownloadInShell(this); 196 download_manager_->ShowDownloadInShell(this);
190 } 197 }
191 198
192 void DownloadItem::DangerousDownloadValidated() { 199 void DownloadItem::DangerousDownloadValidated() {
193 download_manager_->DangerousDownloadValidated(this); 200 download_manager_->DangerousDownloadValidated(this);
194 } 201 }
195 202
196 void DownloadItem::UpdateSize(int64 bytes_so_far) { 203 void DownloadItem::UpdateSize(int64 bytes_so_far) {
197 received_bytes_ = bytes_so_far; 204 received_bytes_ = bytes_so_far;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 return name; 349 return name;
343 } 350 }
344 return original_name_; 351 return original_name_;
345 } 352 }
346 353
347 void DownloadItem::Init(bool start_timer) { 354 void DownloadItem::Init(bool start_timer) {
348 file_name_ = full_path_.BaseName(); 355 file_name_ = full_path_.BaseName();
349 if (start_timer) 356 if (start_timer)
350 StartProgressTimer(); 357 StartProgressTimer();
351 } 358 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698