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

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

Issue 1090323003: [chrome/browser/download] favor DCHECK_CURRENTLY_ON for better logs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 | « chrome/browser/download/download_request_limiter.cc ('k') | no next file » | 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_target_determiner.h" 5 #include "chrome/browser/download/download_target_determiner.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 virtual_path_(initial_virtual_path), 93 virtual_path_(initial_virtual_path),
94 is_filetype_handled_safely_(false), 94 is_filetype_handled_safely_(false),
95 download_(download), 95 download_(download),
96 is_resumption_(download_->GetLastReason() != 96 is_resumption_(download_->GetLastReason() !=
97 content::DOWNLOAD_INTERRUPT_REASON_NONE && 97 content::DOWNLOAD_INTERRUPT_REASON_NONE &&
98 !initial_virtual_path.empty()), 98 !initial_virtual_path.empty()),
99 download_prefs_(download_prefs), 99 download_prefs_(download_prefs),
100 delegate_(delegate), 100 delegate_(delegate),
101 completion_callback_(callback), 101 completion_callback_(callback),
102 weak_ptr_factory_(this) { 102 weak_ptr_factory_(this) {
103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 103 DCHECK_CURRENTLY_ON(BrowserThread::UI);
104 DCHECK(download_); 104 DCHECK(download_);
105 DCHECK(delegate); 105 DCHECK(delegate);
106 download_->AddObserver(this); 106 download_->AddObserver(this);
107 107
108 DoLoop(); 108 DoLoop();
109 } 109 }
110 110
111 DownloadTargetDeterminer::~DownloadTargetDeterminer() { 111 DownloadTargetDeterminer::~DownloadTargetDeterminer() {
112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 112 DCHECK_CURRENTLY_ON(BrowserThread::UI);
113 DCHECK(download_); 113 DCHECK(download_);
114 DCHECK(completion_callback_.is_null()); 114 DCHECK(completion_callback_.is_null());
115 download_->RemoveObserver(this); 115 download_->RemoveObserver(this);
116 } 116 }
117 117
118 void DownloadTargetDeterminer::DoLoop() { 118 void DownloadTargetDeterminer::DoLoop() {
119 Result result = CONTINUE; 119 Result result = CONTINUE;
120 do { 120 do {
121 State current_state = next_state_; 121 State current_state = next_state_;
122 next_state_ = STATE_NONE; 122 next_state_ = STATE_NONE;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // Note that if a callback completes synchronously, the handler will still 163 // Note that if a callback completes synchronously, the handler will still
164 // return QUIT_DOLOOP. In this case, an inner DoLoop() may complete the target 164 // return QUIT_DOLOOP. In this case, an inner DoLoop() may complete the target
165 // determination and delete |this|. 165 // determination and delete |this|.
166 166
167 if (result == COMPLETE) 167 if (result == COMPLETE)
168 ScheduleCallbackAndDeleteSelf(); 168 ScheduleCallbackAndDeleteSelf();
169 } 169 }
170 170
171 DownloadTargetDeterminer::Result 171 DownloadTargetDeterminer::Result
172 DownloadTargetDeterminer::DoGenerateTargetPath() { 172 DownloadTargetDeterminer::DoGenerateTargetPath() {
173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 173 DCHECK_CURRENTLY_ON(BrowserThread::UI);
174 DCHECK(local_path_.empty()); 174 DCHECK(local_path_.empty());
175 DCHECK(!should_prompt_); 175 DCHECK(!should_prompt_);
176 DCHECK(!should_notify_extensions_); 176 DCHECK(!should_notify_extensions_);
177 DCHECK_EQ(DownloadPathReservationTracker::OVERWRITE, conflict_action_); 177 DCHECK_EQ(DownloadPathReservationTracker::OVERWRITE, conflict_action_);
178 bool is_forced_path = !download_->GetForcedFilePath().empty(); 178 bool is_forced_path = !download_->GetForcedFilePath().empty();
179 179
180 next_state_ = STATE_NOTIFY_EXTENSIONS; 180 next_state_ = STATE_NOTIFY_EXTENSIONS;
181 181
182 if (!virtual_path_.empty() && HasPromptedForPath() && !is_forced_path) { 182 if (!virtual_path_.empty() && HasPromptedForPath() && !is_forced_path) {
183 // The download is being resumed and the user has already been prompted for 183 // The download is being resumed and the user has already been prompted for
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // 233 //
234 // A virtual path is determined for DOA downloads for display purposes. This 234 // A virtual path is determined for DOA downloads for display purposes. This
235 // is why this check is performed here instead of at the start. 235 // is why this check is performed here instead of at the start.
236 if (download_->GetState() != DownloadItem::IN_PROGRESS) 236 if (download_->GetState() != DownloadItem::IN_PROGRESS)
237 return COMPLETE; 237 return COMPLETE;
238 return CONTINUE; 238 return CONTINUE;
239 } 239 }
240 240
241 DownloadTargetDeterminer::Result 241 DownloadTargetDeterminer::Result
242 DownloadTargetDeterminer::DoNotifyExtensions() { 242 DownloadTargetDeterminer::DoNotifyExtensions() {
243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 243 DCHECK_CURRENTLY_ON(BrowserThread::UI);
244 DCHECK(!virtual_path_.empty()); 244 DCHECK(!virtual_path_.empty());
245 245
246 next_state_ = STATE_RESERVE_VIRTUAL_PATH; 246 next_state_ = STATE_RESERVE_VIRTUAL_PATH;
247 247
248 if (!should_notify_extensions_) 248 if (!should_notify_extensions_)
249 return CONTINUE; 249 return CONTINUE;
250 250
251 delegate_->NotifyExtensions(download_, virtual_path_, 251 delegate_->NotifyExtensions(download_, virtual_path_,
252 base::Bind(&DownloadTargetDeterminer::NotifyExtensionsDone, 252 base::Bind(&DownloadTargetDeterminer::NotifyExtensionsDone,
253 weak_ptr_factory_.GetWeakPtr())); 253 weak_ptr_factory_.GetWeakPtr()));
254 return QUIT_DOLOOP; 254 return QUIT_DOLOOP;
255 } 255 }
256 256
257 void DownloadTargetDeterminer::NotifyExtensionsDone( 257 void DownloadTargetDeterminer::NotifyExtensionsDone(
258 const base::FilePath& suggested_path, 258 const base::FilePath& suggested_path,
259 DownloadPathReservationTracker::FilenameConflictAction conflict_action) { 259 DownloadPathReservationTracker::FilenameConflictAction conflict_action) {
260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 260 DCHECK_CURRENTLY_ON(BrowserThread::UI);
261 DVLOG(20) << "Extension suggested path: " << suggested_path.AsUTF8Unsafe(); 261 DVLOG(20) << "Extension suggested path: " << suggested_path.AsUTF8Unsafe();
262 262
263 // Extensions should not call back here more than once. 263 // Extensions should not call back here more than once.
264 DCHECK_EQ(STATE_RESERVE_VIRTUAL_PATH, next_state_); 264 DCHECK_EQ(STATE_RESERVE_VIRTUAL_PATH, next_state_);
265 265
266 if (!suggested_path.empty()) { 266 if (!suggested_path.empty()) {
267 // If an extension overrides the filename, then the target directory will be 267 // If an extension overrides the filename, then the target directory will be
268 // forced to download_prefs_->DownloadPath() since extensions cannot place 268 // forced to download_prefs_->DownloadPath() since extensions cannot place
269 // downloaded files anywhere except there. This prevents subdirectories from 269 // downloaded files anywhere except there. This prevents subdirectories from
270 // accumulating: if an extension is allowed to say that a file should go in 270 // accumulating: if an extension is allowed to say that a file should go in
(...skipping 11 matching lines...) Expand all
282 } 282 }
283 // An extension may set conflictAction without setting filename. 283 // An extension may set conflictAction without setting filename.
284 if (conflict_action != DownloadPathReservationTracker::UNIQUIFY) 284 if (conflict_action != DownloadPathReservationTracker::UNIQUIFY)
285 conflict_action_ = conflict_action; 285 conflict_action_ = conflict_action;
286 286
287 DoLoop(); 287 DoLoop();
288 } 288 }
289 289
290 DownloadTargetDeterminer::Result 290 DownloadTargetDeterminer::Result
291 DownloadTargetDeterminer::DoReserveVirtualPath() { 291 DownloadTargetDeterminer::DoReserveVirtualPath() {
292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 292 DCHECK_CURRENTLY_ON(BrowserThread::UI);
293 DCHECK(!virtual_path_.empty()); 293 DCHECK(!virtual_path_.empty());
294 294
295 next_state_ = STATE_PROMPT_USER_FOR_DOWNLOAD_PATH; 295 next_state_ = STATE_PROMPT_USER_FOR_DOWNLOAD_PATH;
296 296
297 delegate_->ReserveVirtualPath( 297 delegate_->ReserveVirtualPath(
298 download_, virtual_path_, create_target_directory_, conflict_action_, 298 download_, virtual_path_, create_target_directory_, conflict_action_,
299 base::Bind(&DownloadTargetDeterminer::ReserveVirtualPathDone, 299 base::Bind(&DownloadTargetDeterminer::ReserveVirtualPathDone,
300 weak_ptr_factory_.GetWeakPtr())); 300 weak_ptr_factory_.GetWeakPtr()));
301 return QUIT_DOLOOP; 301 return QUIT_DOLOOP;
302 } 302 }
303 303
304 void DownloadTargetDeterminer::ReserveVirtualPathDone( 304 void DownloadTargetDeterminer::ReserveVirtualPathDone(
305 const base::FilePath& path, bool verified) { 305 const base::FilePath& path, bool verified) {
306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 306 DCHECK_CURRENTLY_ON(BrowserThread::UI);
307 DVLOG(20) << "Reserved path: " << path.AsUTF8Unsafe() 307 DVLOG(20) << "Reserved path: " << path.AsUTF8Unsafe()
308 << " Verified:" << verified; 308 << " Verified:" << verified;
309 DCHECK_EQ(STATE_PROMPT_USER_FOR_DOWNLOAD_PATH, next_state_); 309 DCHECK_EQ(STATE_PROMPT_USER_FOR_DOWNLOAD_PATH, next_state_);
310 310
311 should_prompt_ = (should_prompt_ || !verified); 311 should_prompt_ = (should_prompt_ || !verified);
312 virtual_path_ = path; 312 virtual_path_ = path;
313 DoLoop(); 313 DoLoop();
314 } 314 }
315 315
316 DownloadTargetDeterminer::Result 316 DownloadTargetDeterminer::Result
317 DownloadTargetDeterminer::DoPromptUserForDownloadPath() { 317 DownloadTargetDeterminer::DoPromptUserForDownloadPath() {
318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 318 DCHECK_CURRENTLY_ON(BrowserThread::UI);
319 DCHECK(!virtual_path_.empty()); 319 DCHECK(!virtual_path_.empty());
320 320
321 next_state_ = STATE_DETERMINE_LOCAL_PATH; 321 next_state_ = STATE_DETERMINE_LOCAL_PATH;
322 322
323 if (should_prompt_) { 323 if (should_prompt_) {
324 delegate_->PromptUserForDownloadPath( 324 delegate_->PromptUserForDownloadPath(
325 download_, 325 download_,
326 virtual_path_, 326 virtual_path_,
327 base::Bind(&DownloadTargetDeterminer::PromptUserForDownloadPathDone, 327 base::Bind(&DownloadTargetDeterminer::PromptUserForDownloadPathDone,
328 weak_ptr_factory_.GetWeakPtr())); 328 weak_ptr_factory_.GetWeakPtr()));
329 return QUIT_DOLOOP; 329 return QUIT_DOLOOP;
330 } 330 }
331 return CONTINUE; 331 return CONTINUE;
332 } 332 }
333 333
334 void DownloadTargetDeterminer::PromptUserForDownloadPathDone( 334 void DownloadTargetDeterminer::PromptUserForDownloadPathDone(
335 const base::FilePath& virtual_path) { 335 const base::FilePath& virtual_path) {
336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 336 DCHECK_CURRENTLY_ON(BrowserThread::UI);
337 DVLOG(20) << "User selected path:" << virtual_path.AsUTF8Unsafe(); 337 DVLOG(20) << "User selected path:" << virtual_path.AsUTF8Unsafe();
338 if (virtual_path.empty()) { 338 if (virtual_path.empty()) {
339 CancelOnFailureAndDeleteSelf(); 339 CancelOnFailureAndDeleteSelf();
340 return; 340 return;
341 } 341 }
342 DCHECK_EQ(STATE_DETERMINE_LOCAL_PATH, next_state_); 342 DCHECK_EQ(STATE_DETERMINE_LOCAL_PATH, next_state_);
343 343
344 virtual_path_ = virtual_path; 344 virtual_path_ = virtual_path;
345 download_prefs_->SetSaveFilePath(virtual_path_.DirName()); 345 download_prefs_->SetSaveFilePath(virtual_path_.DirName());
346 DoLoop(); 346 DoLoop();
347 } 347 }
348 348
349 DownloadTargetDeterminer::Result 349 DownloadTargetDeterminer::Result
350 DownloadTargetDeterminer::DoDetermineLocalPath() { 350 DownloadTargetDeterminer::DoDetermineLocalPath() {
351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 351 DCHECK_CURRENTLY_ON(BrowserThread::UI);
352 DCHECK(!virtual_path_.empty()); 352 DCHECK(!virtual_path_.empty());
353 DCHECK(local_path_.empty()); 353 DCHECK(local_path_.empty());
354 354
355 next_state_ = STATE_DETERMINE_MIME_TYPE; 355 next_state_ = STATE_DETERMINE_MIME_TYPE;
356 356
357 delegate_->DetermineLocalPath( 357 delegate_->DetermineLocalPath(
358 download_, 358 download_,
359 virtual_path_, 359 virtual_path_,
360 base::Bind(&DownloadTargetDeterminer::DetermineLocalPathDone, 360 base::Bind(&DownloadTargetDeterminer::DetermineLocalPathDone,
361 weak_ptr_factory_.GetWeakPtr())); 361 weak_ptr_factory_.GetWeakPtr()));
362 return QUIT_DOLOOP; 362 return QUIT_DOLOOP;
363 } 363 }
364 364
365 void DownloadTargetDeterminer::DetermineLocalPathDone( 365 void DownloadTargetDeterminer::DetermineLocalPathDone(
366 const base::FilePath& local_path) { 366 const base::FilePath& local_path) {
367 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 367 DCHECK_CURRENTLY_ON(BrowserThread::UI);
368 DVLOG(20) << "Local path: " << local_path.AsUTF8Unsafe(); 368 DVLOG(20) << "Local path: " << local_path.AsUTF8Unsafe();
369 if (local_path.empty()) { 369 if (local_path.empty()) {
370 // Path subsitution failed. 370 // Path subsitution failed.
371 CancelOnFailureAndDeleteSelf(); 371 CancelOnFailureAndDeleteSelf();
372 return; 372 return;
373 } 373 }
374 DCHECK_EQ(STATE_DETERMINE_MIME_TYPE, next_state_); 374 DCHECK_EQ(STATE_DETERMINE_MIME_TYPE, next_state_);
375 375
376 local_path_ = local_path; 376 local_path_ = local_path;
377 DoLoop(); 377 DoLoop();
378 } 378 }
379 379
380 DownloadTargetDeterminer::Result 380 DownloadTargetDeterminer::Result
381 DownloadTargetDeterminer::DoDetermineMimeType() { 381 DownloadTargetDeterminer::DoDetermineMimeType() {
382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 382 DCHECK_CURRENTLY_ON(BrowserThread::UI);
383 DCHECK(!virtual_path_.empty()); 383 DCHECK(!virtual_path_.empty());
384 DCHECK(!local_path_.empty()); 384 DCHECK(!local_path_.empty());
385 DCHECK(mime_type_.empty()); 385 DCHECK(mime_type_.empty());
386 386
387 next_state_ = STATE_DETERMINE_IF_HANDLED_SAFELY_BY_BROWSER; 387 next_state_ = STATE_DETERMINE_IF_HANDLED_SAFELY_BY_BROWSER;
388 388
389 if (virtual_path_ == local_path_) { 389 if (virtual_path_ == local_path_) {
390 delegate_->GetFileMimeType( 390 delegate_->GetFileMimeType(
391 local_path_, 391 local_path_,
392 base::Bind(&DownloadTargetDeterminer::DetermineMimeTypeDone, 392 base::Bind(&DownloadTargetDeterminer::DetermineMimeTypeDone,
393 weak_ptr_factory_.GetWeakPtr())); 393 weak_ptr_factory_.GetWeakPtr()));
394 return QUIT_DOLOOP; 394 return QUIT_DOLOOP;
395 } 395 }
396 return CONTINUE; 396 return CONTINUE;
397 } 397 }
398 398
399 void DownloadTargetDeterminer::DetermineMimeTypeDone( 399 void DownloadTargetDeterminer::DetermineMimeTypeDone(
400 const std::string& mime_type) { 400 const std::string& mime_type) {
401 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 401 DCHECK_CURRENTLY_ON(BrowserThread::UI);
402 DVLOG(20) << "MIME type: " << mime_type; 402 DVLOG(20) << "MIME type: " << mime_type;
403 DCHECK_EQ(STATE_DETERMINE_IF_HANDLED_SAFELY_BY_BROWSER, next_state_); 403 DCHECK_EQ(STATE_DETERMINE_IF_HANDLED_SAFELY_BY_BROWSER, next_state_);
404 404
405 mime_type_ = mime_type; 405 mime_type_ = mime_type;
406 DoLoop(); 406 DoLoop();
407 } 407 }
408 408
409 #if defined(ENABLE_PLUGINS) 409 #if defined(ENABLE_PLUGINS)
410 // The code below is used by DoDetermineIfHandledSafely to determine if the 410 // The code below is used by DoDetermineIfHandledSafely to determine if the
411 // file type is handled by a sandboxed plugin. 411 // file type is handled by a sandboxed plugin.
412 namespace { 412 namespace {
413 413
414 void InvokeClosureAfterGetPluginCallback( 414 void InvokeClosureAfterGetPluginCallback(
415 const base::Closure& closure, 415 const base::Closure& closure,
416 const std::vector<content::WebPluginInfo>& unused) { 416 const std::vector<content::WebPluginInfo>& unused) {
417 closure.Run(); 417 closure.Run();
418 } 418 }
419 419
420 enum ActionOnStalePluginList { 420 enum ActionOnStalePluginList {
421 RETRY_IF_STALE_PLUGIN_LIST, 421 RETRY_IF_STALE_PLUGIN_LIST,
422 IGNORE_IF_STALE_PLUGIN_LIST 422 IGNORE_IF_STALE_PLUGIN_LIST
423 }; 423 };
424 424
425 void IsHandledBySafePlugin(content::ResourceContext* resource_context, 425 void IsHandledBySafePlugin(content::ResourceContext* resource_context,
426 const GURL& url, 426 const GURL& url,
427 const std::string& mime_type, 427 const std::string& mime_type,
428 ActionOnStalePluginList stale_plugin_action, 428 ActionOnStalePluginList stale_plugin_action,
429 const base::Callback<void(bool)>& callback) { 429 const base::Callback<void(bool)>& callback) {
430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 430 DCHECK_CURRENTLY_ON(BrowserThread::IO);
431 DCHECK(!mime_type.empty()); 431 DCHECK(!mime_type.empty());
432 using content::WebPluginInfo; 432 using content::WebPluginInfo;
433 433
434 std::string actual_mime_type; 434 std::string actual_mime_type;
435 bool is_stale = false; 435 bool is_stale = false;
436 WebPluginInfo plugin_info; 436 WebPluginInfo plugin_info;
437 437
438 content::PluginService* plugin_service = 438 content::PluginService* plugin_service =
439 content::PluginService::GetInstance(); 439 content::PluginService::GetInstance();
440 bool plugin_found = plugin_service->GetPluginInfo(-1, -1, resource_context, 440 bool plugin_found = plugin_service->GetPluginInfo(-1, -1, resource_context,
(...skipping 24 matching lines...) Expand all
465 plugin_info.type == WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN); 465 plugin_info.type == WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN);
466 BrowserThread::PostTask( 466 BrowserThread::PostTask(
467 BrowserThread::UI, FROM_HERE, base::Bind(callback, is_handled_safely)); 467 BrowserThread::UI, FROM_HERE, base::Bind(callback, is_handled_safely));
468 } 468 }
469 469
470 } // namespace 470 } // namespace
471 #endif // defined(ENABLE_PLUGINS) 471 #endif // defined(ENABLE_PLUGINS)
472 472
473 DownloadTargetDeterminer::Result 473 DownloadTargetDeterminer::Result
474 DownloadTargetDeterminer::DoDetermineIfHandledSafely() { 474 DownloadTargetDeterminer::DoDetermineIfHandledSafely() {
475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 475 DCHECK_CURRENTLY_ON(BrowserThread::UI);
476 DCHECK(!virtual_path_.empty()); 476 DCHECK(!virtual_path_.empty());
477 DCHECK(!local_path_.empty()); 477 DCHECK(!local_path_.empty());
478 DCHECK(!is_filetype_handled_safely_); 478 DCHECK(!is_filetype_handled_safely_);
479 479
480 next_state_ = STATE_DETERMINE_IF_ADOBE_READER_UP_TO_DATE; 480 next_state_ = STATE_DETERMINE_IF_ADOBE_READER_UP_TO_DATE;
481 481
482 if (mime_type_.empty()) 482 if (mime_type_.empty())
483 return CONTINUE; 483 return CONTINUE;
484 484
485 if (net::IsSupportedMimeType(mime_type_)) { 485 if (net::IsSupportedMimeType(mime_type_)) {
(...skipping 15 matching lines...) Expand all
501 weak_ptr_factory_.GetWeakPtr()))); 501 weak_ptr_factory_.GetWeakPtr())));
502 return QUIT_DOLOOP; 502 return QUIT_DOLOOP;
503 #else 503 #else
504 return CONTINUE; 504 return CONTINUE;
505 #endif 505 #endif
506 } 506 }
507 507
508 #if defined(ENABLE_PLUGINS) 508 #if defined(ENABLE_PLUGINS)
509 void DownloadTargetDeterminer::DetermineIfHandledSafelyDone( 509 void DownloadTargetDeterminer::DetermineIfHandledSafelyDone(
510 bool is_handled_safely) { 510 bool is_handled_safely) {
511 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 511 DCHECK_CURRENTLY_ON(BrowserThread::UI);
512 DVLOG(20) << "Is file type handled safely: " << is_filetype_handled_safely_; 512 DVLOG(20) << "Is file type handled safely: " << is_filetype_handled_safely_;
513 DCHECK_EQ(STATE_DETERMINE_IF_ADOBE_READER_UP_TO_DATE, next_state_); 513 DCHECK_EQ(STATE_DETERMINE_IF_ADOBE_READER_UP_TO_DATE, next_state_);
514 is_filetype_handled_safely_ = is_handled_safely; 514 is_filetype_handled_safely_ = is_handled_safely;
515 DoLoop(); 515 DoLoop();
516 } 516 }
517 #endif 517 #endif
518 518
519 DownloadTargetDeterminer::Result 519 DownloadTargetDeterminer::Result
520 DownloadTargetDeterminer::DoDetermineIfAdobeReaderUpToDate() { 520 DownloadTargetDeterminer::DoDetermineIfAdobeReaderUpToDate() {
521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 521 DCHECK_CURRENTLY_ON(BrowserThread::UI);
522 522
523 next_state_ = STATE_CHECK_DOWNLOAD_URL; 523 next_state_ = STATE_CHECK_DOWNLOAD_URL;
524 524
525 #if defined(OS_WIN) 525 #if defined(OS_WIN)
526 if (!local_path_.MatchesExtension(FILE_PATH_LITERAL(".pdf"))) 526 if (!local_path_.MatchesExtension(FILE_PATH_LITERAL(".pdf")))
527 return CONTINUE; 527 return CONTINUE;
528 if (!IsAdobeReaderDefaultPDFViewer()) { 528 if (!IsAdobeReaderDefaultPDFViewer()) {
529 g_is_adobe_reader_up_to_date_ = false; 529 g_is_adobe_reader_up_to_date_ = false;
530 return CONTINUE; 530 return CONTINUE;
531 } 531 }
532 532
533 base::PostTaskAndReplyWithResult( 533 base::PostTaskAndReplyWithResult(
534 BrowserThread::GetBlockingPool(), 534 BrowserThread::GetBlockingPool(),
535 FROM_HERE, 535 FROM_HERE,
536 base::Bind(&::IsAdobeReaderUpToDate), 536 base::Bind(&::IsAdobeReaderUpToDate),
537 base::Bind(&DownloadTargetDeterminer::DetermineIfAdobeReaderUpToDateDone, 537 base::Bind(&DownloadTargetDeterminer::DetermineIfAdobeReaderUpToDateDone,
538 weak_ptr_factory_.GetWeakPtr())); 538 weak_ptr_factory_.GetWeakPtr()));
539 return QUIT_DOLOOP; 539 return QUIT_DOLOOP;
540 #else 540 #else
541 return CONTINUE; 541 return CONTINUE;
542 #endif 542 #endif
543 } 543 }
544 544
545 #if defined(OS_WIN) 545 #if defined(OS_WIN)
546 void DownloadTargetDeterminer::DetermineIfAdobeReaderUpToDateDone( 546 void DownloadTargetDeterminer::DetermineIfAdobeReaderUpToDateDone(
547 bool adobe_reader_up_to_date) { 547 bool adobe_reader_up_to_date) {
548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 548 DCHECK_CURRENTLY_ON(BrowserThread::UI);
549 DVLOG(20) << "Is Adobe Reader Up To Date: " << adobe_reader_up_to_date; 549 DVLOG(20) << "Is Adobe Reader Up To Date: " << adobe_reader_up_to_date;
550 DCHECK_EQ(STATE_CHECK_DOWNLOAD_URL, next_state_); 550 DCHECK_EQ(STATE_CHECK_DOWNLOAD_URL, next_state_);
551 g_is_adobe_reader_up_to_date_ = adobe_reader_up_to_date; 551 g_is_adobe_reader_up_to_date_ = adobe_reader_up_to_date;
552 DoLoop(); 552 DoLoop();
553 } 553 }
554 #endif 554 #endif
555 555
556 DownloadTargetDeterminer::Result 556 DownloadTargetDeterminer::Result
557 DownloadTargetDeterminer::DoCheckDownloadUrl() { 557 DownloadTargetDeterminer::DoCheckDownloadUrl() {
558 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 558 DCHECK_CURRENTLY_ON(BrowserThread::UI);
559 DCHECK(!virtual_path_.empty()); 559 DCHECK(!virtual_path_.empty());
560 next_state_ = STATE_CHECK_VISITED_REFERRER_BEFORE; 560 next_state_ = STATE_CHECK_VISITED_REFERRER_BEFORE;
561 delegate_->CheckDownloadUrl( 561 delegate_->CheckDownloadUrl(
562 download_, 562 download_,
563 virtual_path_, 563 virtual_path_,
564 base::Bind(&DownloadTargetDeterminer::CheckDownloadUrlDone, 564 base::Bind(&DownloadTargetDeterminer::CheckDownloadUrlDone,
565 weak_ptr_factory_.GetWeakPtr())); 565 weak_ptr_factory_.GetWeakPtr()));
566 return QUIT_DOLOOP; 566 return QUIT_DOLOOP;
567 } 567 }
568 568
569 void DownloadTargetDeterminer::CheckDownloadUrlDone( 569 void DownloadTargetDeterminer::CheckDownloadUrlDone(
570 content::DownloadDangerType danger_type) { 570 content::DownloadDangerType danger_type) {
571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 571 DCHECK_CURRENTLY_ON(BrowserThread::UI);
572 DVLOG(20) << "URL Check Result:" << danger_type; 572 DVLOG(20) << "URL Check Result:" << danger_type;
573 DCHECK_EQ(STATE_CHECK_VISITED_REFERRER_BEFORE, next_state_); 573 DCHECK_EQ(STATE_CHECK_VISITED_REFERRER_BEFORE, next_state_);
574 danger_type_ = danger_type; 574 danger_type_ = danger_type;
575 DoLoop(); 575 DoLoop();
576 } 576 }
577 577
578 DownloadTargetDeterminer::Result 578 DownloadTargetDeterminer::Result
579 DownloadTargetDeterminer::DoCheckVisitedReferrerBefore() { 579 DownloadTargetDeterminer::DoCheckVisitedReferrerBefore() {
580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 580 DCHECK_CURRENTLY_ON(BrowserThread::UI);
581 581
582 next_state_ = STATE_DETERMINE_INTERMEDIATE_PATH; 582 next_state_ = STATE_DETERMINE_INTERMEDIATE_PATH;
583 583
584 // Checking if there are prior visits to the referrer is only necessary if the 584 // Checking if there are prior visits to the referrer is only necessary if the
585 // danger level of the download depends on the file type. 585 // danger level of the download depends on the file type.
586 if (danger_type_ != content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS && 586 if (danger_type_ != content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS &&
587 danger_type_ != content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT) 587 danger_type_ != content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT)
588 return CONTINUE; 588 return CONTINUE;
589 589
590 // Assume that: 590 // Assume that:
(...skipping 27 matching lines...) Expand all
618 // is invalid, then assume the referrer has not been visited before. 618 // is invalid, then assume the referrer has not been visited before.
619 is_dangerous_file_ = true; 619 is_dangerous_file_ = true;
620 if (danger_type_ == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) 620 if (danger_type_ == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS)
621 danger_type_ = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; 621 danger_type_ = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE;
622 } 622 }
623 return CONTINUE; 623 return CONTINUE;
624 } 624 }
625 625
626 void DownloadTargetDeterminer::CheckVisitedReferrerBeforeDone( 626 void DownloadTargetDeterminer::CheckVisitedReferrerBeforeDone(
627 bool visited_referrer_before) { 627 bool visited_referrer_before) {
628 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 628 DCHECK_CURRENTLY_ON(BrowserThread::UI);
629 DCHECK_EQ(STATE_DETERMINE_INTERMEDIATE_PATH, next_state_); 629 DCHECK_EQ(STATE_DETERMINE_INTERMEDIATE_PATH, next_state_);
630 if (IsDangerousFile(visited_referrer_before ? VISITED_REFERRER 630 if (IsDangerousFile(visited_referrer_before ? VISITED_REFERRER
631 : NO_VISITS_TO_REFERRER)) { 631 : NO_VISITS_TO_REFERRER)) {
632 is_dangerous_file_ = true; 632 is_dangerous_file_ = true;
633 if (danger_type_ == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) 633 if (danger_type_ == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS)
634 danger_type_ = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; 634 danger_type_ = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE;
635 } 635 }
636 DoLoop(); 636 DoLoop();
637 } 637 }
638 638
639 DownloadTargetDeterminer::Result 639 DownloadTargetDeterminer::Result
640 DownloadTargetDeterminer::DoDetermineIntermediatePath() { 640 DownloadTargetDeterminer::DoDetermineIntermediatePath() {
641 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 641 DCHECK_CURRENTLY_ON(BrowserThread::UI);
642 DCHECK(!virtual_path_.empty()); 642 DCHECK(!virtual_path_.empty());
643 DCHECK(!local_path_.empty()); 643 DCHECK(!local_path_.empty());
644 DCHECK(intermediate_path_.empty()); 644 DCHECK(intermediate_path_.empty());
645 DCHECK(!virtual_path_.MatchesExtension(kCrdownloadSuffix)); 645 DCHECK(!virtual_path_.MatchesExtension(kCrdownloadSuffix));
646 DCHECK(!local_path_.MatchesExtension(kCrdownloadSuffix)); 646 DCHECK(!local_path_.MatchesExtension(kCrdownloadSuffix));
647 647
648 next_state_ = STATE_NONE; 648 next_state_ = STATE_NONE;
649 649
650 // Note that the intermediate filename is always uniquified (i.e. if a file by 650 // Note that the intermediate filename is always uniquified (i.e. if a file by
651 // the same name exists, it is never overwritten). Therefore the code below 651 // the same name exists, it is never overwritten). Therefore the code below
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 // conflict. 803 // conflict.
804 return false; 804 return false;
805 } 805 }
806 806
807 bool DownloadTargetDeterminer::HasPromptedForPath() const { 807 bool DownloadTargetDeterminer::HasPromptedForPath() const {
808 return (is_resumption_ && download_->GetTargetDisposition() == 808 return (is_resumption_ && download_->GetTargetDisposition() ==
809 DownloadItem::TARGET_DISPOSITION_PROMPT); 809 DownloadItem::TARGET_DISPOSITION_PROMPT);
810 } 810 }
811 811
812 bool DownloadTargetDeterminer::IsDangerousFile(PriorVisitsToReferrer visits) { 812 bool DownloadTargetDeterminer::IsDangerousFile(PriorVisitsToReferrer visits) {
813 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 813 DCHECK_CURRENTLY_ON(BrowserThread::UI);
814 814
815 // If the user has has been prompted or will be, assume that the user has 815 // If the user has has been prompted or will be, assume that the user has
816 // approved the download. A programmatic download is considered safe unless it 816 // approved the download. A programmatic download is considered safe unless it
817 // contains malware. 817 // contains malware.
818 if (HasPromptedForPath() || should_prompt_ || 818 if (HasPromptedForPath() || should_prompt_ ||
819 !download_->GetForcedFilePath().empty()) 819 !download_->GetForcedFilePath().empty())
820 return false; 820 return false;
821 821
822 const bool is_extension_download = 822 const bool is_extension_download =
823 download_crx_util::IsExtensionDownload(*download_); 823 download_crx_util::IsExtensionDownload(*download_);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 862
863 case download_util::DANGEROUS: 863 case download_util::DANGEROUS:
864 return true; 864 return true;
865 } 865 }
866 NOTREACHED(); 866 NOTREACHED();
867 return false; 867 return false;
868 } 868 }
869 869
870 void DownloadTargetDeterminer::OnDownloadDestroyed( 870 void DownloadTargetDeterminer::OnDownloadDestroyed(
871 DownloadItem* download) { 871 DownloadItem* download) {
872 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 872 DCHECK_CURRENTLY_ON(BrowserThread::UI);
873 DCHECK_EQ(download_, download); 873 DCHECK_EQ(download_, download);
874 CancelOnFailureAndDeleteSelf(); 874 CancelOnFailureAndDeleteSelf();
875 } 875 }
876 876
877 // static 877 // static
878 void DownloadTargetDeterminer::Start(content::DownloadItem* download, 878 void DownloadTargetDeterminer::Start(content::DownloadItem* download,
879 const base::FilePath& initial_virtual_path, 879 const base::FilePath& initial_virtual_path,
880 DownloadPrefs* download_prefs, 880 DownloadPrefs* download_prefs,
881 DownloadTargetDeterminerDelegate* delegate, 881 DownloadTargetDeterminerDelegate* delegate,
882 const CompletionCallback& callback) { 882 const CompletionCallback& callback) {
883 // DownloadTargetDeterminer owns itself and will self destruct when the job is 883 // DownloadTargetDeterminer owns itself and will self destruct when the job is
884 // complete or the download item is destroyed. The callback is always invoked 884 // complete or the download item is destroyed. The callback is always invoked
885 // asynchronously. 885 // asynchronously.
886 new DownloadTargetDeterminer(download, initial_virtual_path, download_prefs, 886 new DownloadTargetDeterminer(download, initial_virtual_path, download_prefs,
887 delegate, callback); 887 delegate, callback);
888 } 888 }
889 889
890 // static 890 // static
891 base::FilePath DownloadTargetDeterminer::GetCrDownloadPath( 891 base::FilePath DownloadTargetDeterminer::GetCrDownloadPath(
892 const base::FilePath& suggested_path) { 892 const base::FilePath& suggested_path) {
893 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); 893 return base::FilePath(suggested_path.value() + kCrdownloadSuffix);
894 } 894 }
895 895
896 #if defined(OS_WIN) 896 #if defined(OS_WIN)
897 // static 897 // static
898 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { 898 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() {
899 return g_is_adobe_reader_up_to_date_; 899 return g_is_adobe_reader_up_to_date_;
900 } 900 }
901 #endif 901 #endif
OLDNEW
« no previous file with comments | « chrome/browser/download/download_request_limiter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698