| 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_target_determiner.h" | 5 #include "chrome/browser/download/download_target_determiner.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "chrome/browser/extensions/webstore_installer.h" | 32 #include "chrome/browser/extensions/webstore_installer.h" |
| 33 #include "extensions/common/feature_switch.h" | 33 #include "extensions/common/feature_switch.h" |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 #if defined(ENABLE_PLUGINS) | 36 #if defined(ENABLE_PLUGINS) |
| 37 #include "chrome/browser/plugins/plugin_prefs.h" | 37 #include "chrome/browser/plugins/plugin_prefs.h" |
| 38 #include "content/public/browser/plugin_service.h" | 38 #include "content/public/browser/plugin_service.h" |
| 39 #include "content/public/common/webplugininfo.h" | 39 #include "content/public/common/webplugininfo.h" |
| 40 #endif | 40 #endif |
| 41 | 41 |
| 42 #if defined(OS_ANDROID) | |
| 43 #include "content/public/browser/android/download_controller_android.h" | |
| 44 #endif | |
| 45 | |
| 46 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
| 47 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h" | 43 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h" |
| 48 #endif | 44 #endif |
| 49 | 45 |
| 50 using content::BrowserThread; | 46 using content::BrowserThread; |
| 51 using content::DownloadItem; | 47 using content::DownloadItem; |
| 52 | 48 |
| 53 namespace { | 49 namespace { |
| 54 | 50 |
| 55 const base::FilePath::CharType kCrdownloadSuffix[] = | 51 const base::FilePath::CharType kCrdownloadSuffix[] = |
| (...skipping 27 matching lines...) Expand all Loading... |
| 83 | 79 |
| 84 DownloadTargetDeterminerDelegate::~DownloadTargetDeterminerDelegate() { | 80 DownloadTargetDeterminerDelegate::~DownloadTargetDeterminerDelegate() { |
| 85 } | 81 } |
| 86 | 82 |
| 87 DownloadTargetDeterminer::DownloadTargetDeterminer( | 83 DownloadTargetDeterminer::DownloadTargetDeterminer( |
| 88 DownloadItem* download, | 84 DownloadItem* download, |
| 89 const base::FilePath& initial_virtual_path, | 85 const base::FilePath& initial_virtual_path, |
| 90 DownloadPrefs* download_prefs, | 86 DownloadPrefs* download_prefs, |
| 91 DownloadTargetDeterminerDelegate* delegate, | 87 DownloadTargetDeterminerDelegate* delegate, |
| 92 const CompletionCallback& callback) | 88 const CompletionCallback& callback) |
| 93 : next_state_(STATE_PROMPT_USER_FOR_PERMISSION), | 89 : next_state_(STATE_GENERATE_TARGET_PATH), |
| 94 should_prompt_(false), | 90 should_prompt_(false), |
| 95 should_notify_extensions_(false), | 91 should_notify_extensions_(false), |
| 96 create_target_directory_(false), | 92 create_target_directory_(false), |
| 97 conflict_action_(DownloadPathReservationTracker::OVERWRITE), | 93 conflict_action_(DownloadPathReservationTracker::OVERWRITE), |
| 98 danger_type_(download->GetDangerType()), | 94 danger_type_(download->GetDangerType()), |
| 99 is_dangerous_file_(false), | 95 is_dangerous_file_(false), |
| 100 virtual_path_(initial_virtual_path), | 96 virtual_path_(initial_virtual_path), |
| 101 is_filetype_handled_safely_(false), | 97 is_filetype_handled_safely_(false), |
| 102 download_(download), | 98 download_(download), |
| 103 is_resumption_(download_->GetLastReason() != | 99 is_resumption_(download_->GetLastReason() != |
| (...skipping 18 matching lines...) Expand all Loading... |
| 122 download_->RemoveObserver(this); | 118 download_->RemoveObserver(this); |
| 123 } | 119 } |
| 124 | 120 |
| 125 void DownloadTargetDeterminer::DoLoop() { | 121 void DownloadTargetDeterminer::DoLoop() { |
| 126 Result result = CONTINUE; | 122 Result result = CONTINUE; |
| 127 do { | 123 do { |
| 128 State current_state = next_state_; | 124 State current_state = next_state_; |
| 129 next_state_ = STATE_NONE; | 125 next_state_ = STATE_NONE; |
| 130 | 126 |
| 131 switch (current_state) { | 127 switch (current_state) { |
| 132 case STATE_PROMPT_USER_FOR_PERMISSION: | |
| 133 result = DoPromptUserForPermission(); | |
| 134 break; | |
| 135 case STATE_GENERATE_TARGET_PATH: | 128 case STATE_GENERATE_TARGET_PATH: |
| 136 result = DoGenerateTargetPath(); | 129 result = DoGenerateTargetPath(); |
| 137 break; | 130 break; |
| 138 case STATE_NOTIFY_EXTENSIONS: | 131 case STATE_NOTIFY_EXTENSIONS: |
| 139 result = DoNotifyExtensions(); | 132 result = DoNotifyExtensions(); |
| 140 break; | 133 break; |
| 141 case STATE_RESERVE_VIRTUAL_PATH: | 134 case STATE_RESERVE_VIRTUAL_PATH: |
| 142 result = DoReserveVirtualPath(); | 135 result = DoReserveVirtualPath(); |
| 143 break; | 136 break; |
| 144 case STATE_PROMPT_USER_FOR_DOWNLOAD_PATH: | 137 case STATE_PROMPT_USER_FOR_DOWNLOAD_PATH: |
| (...skipping 27 matching lines...) Expand all Loading... |
| 172 } while (result == CONTINUE); | 165 } while (result == CONTINUE); |
| 173 // Note that if a callback completes synchronously, the handler will still | 166 // Note that if a callback completes synchronously, the handler will still |
| 174 // return QUIT_DOLOOP. In this case, an inner DoLoop() may complete the target | 167 // return QUIT_DOLOOP. In this case, an inner DoLoop() may complete the target |
| 175 // determination and delete |this|. | 168 // determination and delete |this|. |
| 176 | 169 |
| 177 if (result == COMPLETE) | 170 if (result == COMPLETE) |
| 178 ScheduleCallbackAndDeleteSelf(); | 171 ScheduleCallbackAndDeleteSelf(); |
| 179 } | 172 } |
| 180 | 173 |
| 181 DownloadTargetDeterminer::Result | 174 DownloadTargetDeterminer::Result |
| 182 DownloadTargetDeterminer::DoPromptUserForPermission() { | |
| 183 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 184 next_state_ = STATE_GENERATE_TARGET_PATH; | |
| 185 #if defined(OS_ANDROID) | |
| 186 content::WebContents* web_contents = download_->GetWebContents(); | |
| 187 content::DownloadControllerAndroid::Get()->AcquireFileAccessPermission( | |
| 188 web_contents, | |
| 189 base::Bind(&DownloadTargetDeterminer::PromptUserForPermissionDone, | |
| 190 weak_ptr_factory_.GetWeakPtr())); | |
| 191 return QUIT_DOLOOP; | |
| 192 #else | |
| 193 return CONTINUE; | |
| 194 #endif | |
| 195 } | |
| 196 | |
| 197 #if defined(OS_ANDROID) | |
| 198 void DownloadTargetDeterminer::PromptUserForPermissionDone(bool granted) { | |
| 199 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 200 DCHECK_EQ(STATE_GENERATE_TARGET_PATH, next_state_); | |
| 201 if (!granted) { | |
| 202 CancelOnFailureAndDeleteSelf(); | |
| 203 return; | |
| 204 } | |
| 205 | |
| 206 DoLoop(); | |
| 207 } | |
| 208 #endif | |
| 209 | |
| 210 DownloadTargetDeterminer::Result | |
| 211 DownloadTargetDeterminer::DoGenerateTargetPath() { | 175 DownloadTargetDeterminer::DoGenerateTargetPath() { |
| 212 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 176 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 213 DCHECK(local_path_.empty()); | 177 DCHECK(local_path_.empty()); |
| 214 DCHECK(!should_prompt_); | 178 DCHECK(!should_prompt_); |
| 215 DCHECK(!should_notify_extensions_); | 179 DCHECK(!should_notify_extensions_); |
| 216 DCHECK_EQ(DownloadPathReservationTracker::OVERWRITE, conflict_action_); | 180 DCHECK_EQ(DownloadPathReservationTracker::OVERWRITE, conflict_action_); |
| 217 bool is_forced_path = !download_->GetForcedFilePath().empty(); | 181 bool is_forced_path = !download_->GetForcedFilePath().empty(); |
| 218 | 182 |
| 219 next_state_ = STATE_NOTIFY_EXTENSIONS; | 183 next_state_ = STATE_NOTIFY_EXTENSIONS; |
| 220 | 184 |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 const base::FilePath& suggested_path) { | 895 const base::FilePath& suggested_path) { |
| 932 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); | 896 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); |
| 933 } | 897 } |
| 934 | 898 |
| 935 #if defined(OS_WIN) | 899 #if defined(OS_WIN) |
| 936 // static | 900 // static |
| 937 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { | 901 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { |
| 938 return g_is_adobe_reader_up_to_date_; | 902 return g_is_adobe_reader_up_to_date_; |
| 939 } | 903 } |
| 940 #endif | 904 #endif |
| OLD | NEW |