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

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

Issue 390983004: Merge 281172 "Windows: Add an "Open in Adobe Reader" menu item f..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/2062/src/
Patch Set: Created 6 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 | Annotate | Revision Log
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 15 matching lines...) Expand all
26 #include "net/base/filename_util.h" 26 #include "net/base/filename_util.h"
27 #include "net/base/mime_util.h" 27 #include "net/base/mime_util.h"
28 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
29 29
30 #if defined(ENABLE_PLUGINS) 30 #if defined(ENABLE_PLUGINS)
31 #include "chrome/browser/plugins/plugin_prefs.h" 31 #include "chrome/browser/plugins/plugin_prefs.h"
32 #include "content/public/browser/plugin_service.h" 32 #include "content/public/browser/plugin_service.h"
33 #include "content/public/common/webplugininfo.h" 33 #include "content/public/common/webplugininfo.h"
34 #endif 34 #endif
35 35
36 #if defined(OS_WIN)
37 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h"
38 #endif
39
36 using content::BrowserThread; 40 using content::BrowserThread;
37 using content::DownloadItem; 41 using content::DownloadItem;
38 42
39 namespace { 43 namespace {
40 44
41 const base::FilePath::CharType kCrdownloadSuffix[] = 45 const base::FilePath::CharType kCrdownloadSuffix[] =
42 FILE_PATH_LITERAL(".crdownload"); 46 FILE_PATH_LITERAL(".crdownload");
43 47
44 // Condenses the results from HistoryService::GetVisibleVisitCountToHost() to a 48 // Condenses the results from HistoryService::GetVisibleVisitCountToHost() to a
45 // single bool. A host is considered visited before if prior visible visits were 49 // single bool. A host is considered visited before if prior visible visits were
46 // found in history and the first such visit was earlier than the most recent 50 // found in history and the first such visit was earlier than the most recent
47 // midnight. 51 // midnight.
48 void VisitCountsToVisitedBefore( 52 void VisitCountsToVisitedBefore(
49 const base::Callback<void(bool)>& callback, 53 const base::Callback<void(bool)>& callback,
50 HistoryService::Handle unused_handle, 54 HistoryService::Handle unused_handle,
51 bool found_visits, 55 bool found_visits,
52 int count, 56 int count,
53 base::Time first_visit) { 57 base::Time first_visit) {
54 callback.Run( 58 callback.Run(
55 found_visits && count > 0 && 59 found_visits && count > 0 &&
56 (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight())); 60 (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight()));
57 } 61 }
58 62
59 } // namespace 63 #if defined(OS_WIN)
64 // Keeps track of whether Adobe Reader is up to date.
65 bool g_is_adobe_reader_up_to_date_ = false;
66 #endif
67
68 } // namespace
60 69
61 DownloadTargetInfo::DownloadTargetInfo() 70 DownloadTargetInfo::DownloadTargetInfo()
62 : is_filetype_handled_safely(false) {} 71 : is_filetype_handled_safely(false) {}
63 72
64 DownloadTargetInfo::~DownloadTargetInfo() {} 73 DownloadTargetInfo::~DownloadTargetInfo() {}
65 74
66 DownloadTargetDeterminerDelegate::~DownloadTargetDeterminerDelegate() { 75 DownloadTargetDeterminerDelegate::~DownloadTargetDeterminerDelegate() {
67 } 76 }
68 77
69 DownloadTargetDeterminer::DownloadTargetDeterminer( 78 DownloadTargetDeterminer::DownloadTargetDeterminer(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 break; 133 break;
125 case STATE_DETERMINE_LOCAL_PATH: 134 case STATE_DETERMINE_LOCAL_PATH:
126 result = DoDetermineLocalPath(); 135 result = DoDetermineLocalPath();
127 break; 136 break;
128 case STATE_DETERMINE_MIME_TYPE: 137 case STATE_DETERMINE_MIME_TYPE:
129 result = DoDetermineMimeType(); 138 result = DoDetermineMimeType();
130 break; 139 break;
131 case STATE_DETERMINE_IF_HANDLED_SAFELY_BY_BROWSER: 140 case STATE_DETERMINE_IF_HANDLED_SAFELY_BY_BROWSER:
132 result = DoDetermineIfHandledSafely(); 141 result = DoDetermineIfHandledSafely();
133 break; 142 break;
143 case STATE_DETERMINE_IF_ADOBE_READER_UP_TO_DATE:
144 result = DoDetermineIfAdobeReaderUpToDate();
145 break;
134 case STATE_CHECK_DOWNLOAD_URL: 146 case STATE_CHECK_DOWNLOAD_URL:
135 result = DoCheckDownloadUrl(); 147 result = DoCheckDownloadUrl();
136 break; 148 break;
137 case STATE_DETERMINE_INTERMEDIATE_PATH: 149 case STATE_DETERMINE_INTERMEDIATE_PATH:
138 result = DoDetermineIntermediatePath(); 150 result = DoDetermineIntermediatePath();
139 break; 151 break;
140 case STATE_CHECK_VISITED_REFERRER_BEFORE: 152 case STATE_CHECK_VISITED_REFERRER_BEFORE:
141 result = DoCheckVisitedReferrerBefore(); 153 result = DoCheckVisitedReferrerBefore();
142 break; 154 break;
143 case STATE_NONE: 155 case STATE_NONE:
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 // In practice, we assume that retrying once is enough. 452 // In practice, we assume that retrying once is enough.
441 DCHECK(!is_stale); 453 DCHECK(!is_stale);
442 bool is_handled_safely = 454 bool is_handled_safely =
443 plugin_found && 455 plugin_found &&
444 (plugin_info.type == WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS || 456 (plugin_info.type == WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS ||
445 plugin_info.type == WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS); 457 plugin_info.type == WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS);
446 BrowserThread::PostTask( 458 BrowserThread::PostTask(
447 BrowserThread::UI, FROM_HERE, base::Bind(callback, is_handled_safely)); 459 BrowserThread::UI, FROM_HERE, base::Bind(callback, is_handled_safely));
448 } 460 }
449 461
450 } // namespace 462 } // namespace
451 #endif // ENABLE_PLUGINS 463 #endif // defined(ENABLE_PLUGINS)
452 464
453 DownloadTargetDeterminer::Result 465 DownloadTargetDeterminer::Result
454 DownloadTargetDeterminer::DoDetermineIfHandledSafely() { 466 DownloadTargetDeterminer::DoDetermineIfHandledSafely() {
455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 467 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
456 DCHECK(!virtual_path_.empty()); 468 DCHECK(!virtual_path_.empty());
457 DCHECK(!local_path_.empty()); 469 DCHECK(!local_path_.empty());
458 DCHECK(!is_filetype_handled_safely_); 470 DCHECK(!is_filetype_handled_safely_);
459 471
460 next_state_ = STATE_CHECK_DOWNLOAD_URL; 472 next_state_ = STATE_DETERMINE_IF_ADOBE_READER_UP_TO_DATE;
461 473
462 if (mime_type_.empty()) 474 if (mime_type_.empty())
463 return CONTINUE; 475 return CONTINUE;
464 476
465 if (net::IsSupportedMimeType(mime_type_)) { 477 if (net::IsSupportedMimeType(mime_type_)) {
466 is_filetype_handled_safely_ = true; 478 is_filetype_handled_safely_ = true;
467 return CONTINUE; 479 return CONTINUE;
468 } 480 }
469 481
470 #if defined(ENABLE_PLUGINS) 482 #if defined(ENABLE_PLUGINS)
471 BrowserThread::PostTask( 483 BrowserThread::PostTask(
472 BrowserThread::IO, 484 BrowserThread::IO,
473 FROM_HERE, 485 FROM_HERE,
474 base::Bind( 486 base::Bind(
475 &IsHandledBySafePlugin, 487 &IsHandledBySafePlugin,
476 GetProfile()->GetResourceContext(), 488 GetProfile()->GetResourceContext(),
477 net::FilePathToFileURL(local_path_), 489 net::FilePathToFileURL(local_path_),
478 mime_type_, 490 mime_type_,
479 RETRY_IF_STALE_PLUGIN_LIST, 491 RETRY_IF_STALE_PLUGIN_LIST,
480 base::Bind(&DownloadTargetDeterminer::DetermineIfHandledSafelyDone, 492 base::Bind(&DownloadTargetDeterminer::DetermineIfHandledSafelyDone,
481 weak_ptr_factory_.GetWeakPtr()))); 493 weak_ptr_factory_.GetWeakPtr())));
482 return QUIT_DOLOOP; 494 return QUIT_DOLOOP;
483 #else 495 #else
484 return CONTINUE; 496 return CONTINUE;
485 #endif 497 #endif
486 } 498 }
487 499
500 #if defined(ENABLE_PLUGINS)
488 void DownloadTargetDeterminer::DetermineIfHandledSafelyDone( 501 void DownloadTargetDeterminer::DetermineIfHandledSafelyDone(
489 bool is_handled_safely) { 502 bool is_handled_safely) {
490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
491 DVLOG(20) << "Is file type handled safely: " << is_filetype_handled_safely_; 504 DVLOG(20) << "Is file type handled safely: " << is_filetype_handled_safely_;
492 DCHECK_EQ(STATE_CHECK_DOWNLOAD_URL, next_state_); 505 DCHECK_EQ(STATE_DETERMINE_IF_ADOBE_READER_UP_TO_DATE, next_state_);
493 is_filetype_handled_safely_ = is_handled_safely; 506 is_filetype_handled_safely_ = is_handled_safely;
494 DoLoop(); 507 DoLoop();
495 } 508 }
509 #endif
510
511 DownloadTargetDeterminer::Result
512 DownloadTargetDeterminer::DoDetermineIfAdobeReaderUpToDate() {
513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
514
515 next_state_ = STATE_CHECK_DOWNLOAD_URL;
516
517 #if defined(OS_WIN)
518 if (!local_path_.MatchesExtension(FILE_PATH_LITERAL(".pdf")))
519 return CONTINUE;
520 if (!IsAdobeReaderDefaultPDFViewer())
521 return CONTINUE;
522
523 base::PostTaskAndReplyWithResult(
524 BrowserThread::GetBlockingPool(),
525 FROM_HERE,
526 base::Bind(&::IsAdobeReaderUpToDate),
527 base::Bind(&DownloadTargetDeterminer::DetermineIfAdobeReaderUpToDateDone,
528 weak_ptr_factory_.GetWeakPtr()));
529 return QUIT_DOLOOP;
530 #else
531 return CONTINUE;
532 #endif
533 }
534
535 #if defined(OS_WIN)
536 void DownloadTargetDeterminer::DetermineIfAdobeReaderUpToDateDone(
537 bool adobe_reader_up_to_date) {
538 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
539 DVLOG(20) << "Is Adobe Reader Up To Date: " << adobe_reader_up_to_date;
540 DCHECK_EQ(STATE_CHECK_DOWNLOAD_URL, next_state_);
541 g_is_adobe_reader_up_to_date_ = adobe_reader_up_to_date;
542 DoLoop();
543 }
544 #endif
496 545
497 DownloadTargetDeterminer::Result 546 DownloadTargetDeterminer::Result
498 DownloadTargetDeterminer::DoCheckDownloadUrl() { 547 DownloadTargetDeterminer::DoCheckDownloadUrl() {
499 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
500 DCHECK(!virtual_path_.empty()); 549 DCHECK(!virtual_path_.empty());
501 next_state_ = STATE_CHECK_VISITED_REFERRER_BEFORE; 550 next_state_ = STATE_CHECK_VISITED_REFERRER_BEFORE;
502 delegate_->CheckDownloadUrl( 551 delegate_->CheckDownloadUrl(
503 download_, 552 download_,
504 virtual_path_, 553 virtual_path_,
505 base::Bind(&DownloadTargetDeterminer::CheckDownloadUrlDone, 554 base::Bind(&DownloadTargetDeterminer::CheckDownloadUrlDone,
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 // asynchronously. 863 // asynchronously.
815 new DownloadTargetDeterminer(download, initial_virtual_path, download_prefs, 864 new DownloadTargetDeterminer(download, initial_virtual_path, download_prefs,
816 delegate, callback); 865 delegate, callback);
817 } 866 }
818 867
819 // static 868 // static
820 base::FilePath DownloadTargetDeterminer::GetCrDownloadPath( 869 base::FilePath DownloadTargetDeterminer::GetCrDownloadPath(
821 const base::FilePath& suggested_path) { 870 const base::FilePath& suggested_path) {
822 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); 871 return base::FilePath(suggested_path.value() + kCrdownloadSuffix);
823 } 872 }
873
874 #if defined(OS_WIN)
875 // static
876 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() {
877 return g_is_adobe_reader_up_to_date_;
878 }
879 #endif
OLDNEW
« no previous file with comments | « chrome/browser/download/download_target_determiner.h ('k') | chrome/browser/ui/pdf/adobe_reader_info_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698