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

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

Issue 1217223006: Prompt user for file access permission before download starts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: FixDownloadManagerDelegateTest 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
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/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
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
42 #if defined(OS_WIN) 46 #if defined(OS_WIN)
43 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h" 47 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h"
44 #endif 48 #endif
45 49
46 using content::BrowserThread; 50 using content::BrowserThread;
47 using content::DownloadItem; 51 using content::DownloadItem;
48 52
49 namespace { 53 namespace {
50 54
51 const base::FilePath::CharType kCrdownloadSuffix[] = 55 const base::FilePath::CharType kCrdownloadSuffix[] =
(...skipping 27 matching lines...) Expand all
79 83
80 DownloadTargetDeterminerDelegate::~DownloadTargetDeterminerDelegate() { 84 DownloadTargetDeterminerDelegate::~DownloadTargetDeterminerDelegate() {
81 } 85 }
82 86
83 DownloadTargetDeterminer::DownloadTargetDeterminer( 87 DownloadTargetDeterminer::DownloadTargetDeterminer(
84 DownloadItem* download, 88 DownloadItem* download,
85 const base::FilePath& initial_virtual_path, 89 const base::FilePath& initial_virtual_path,
86 DownloadPrefs* download_prefs, 90 DownloadPrefs* download_prefs,
87 DownloadTargetDeterminerDelegate* delegate, 91 DownloadTargetDeterminerDelegate* delegate,
88 const CompletionCallback& callback) 92 const CompletionCallback& callback)
89 : next_state_(STATE_GENERATE_TARGET_PATH), 93 : next_state_(STATE_PROMPT_USER_FOR_PERMISSION),
90 should_prompt_(false), 94 should_prompt_(false),
91 should_notify_extensions_(false), 95 should_notify_extensions_(false),
92 create_target_directory_(false), 96 create_target_directory_(false),
93 conflict_action_(DownloadPathReservationTracker::OVERWRITE), 97 conflict_action_(DownloadPathReservationTracker::OVERWRITE),
94 danger_type_(download->GetDangerType()), 98 danger_type_(download->GetDangerType()),
95 is_dangerous_file_(false), 99 is_dangerous_file_(false),
96 virtual_path_(initial_virtual_path), 100 virtual_path_(initial_virtual_path),
97 is_filetype_handled_safely_(false), 101 is_filetype_handled_safely_(false),
98 download_(download), 102 download_(download),
99 is_resumption_(download_->GetLastReason() != 103 is_resumption_(download_->GetLastReason() !=
(...skipping 18 matching lines...) Expand all
118 download_->RemoveObserver(this); 122 download_->RemoveObserver(this);
119 } 123 }
120 124
121 void DownloadTargetDeterminer::DoLoop() { 125 void DownloadTargetDeterminer::DoLoop() {
122 Result result = CONTINUE; 126 Result result = CONTINUE;
123 do { 127 do {
124 State current_state = next_state_; 128 State current_state = next_state_;
125 next_state_ = STATE_NONE; 129 next_state_ = STATE_NONE;
126 130
127 switch (current_state) { 131 switch (current_state) {
132 case STATE_PROMPT_USER_FOR_PERMISSION:
133 result = DoPromptUserForPermission();
134 break;
128 case STATE_GENERATE_TARGET_PATH: 135 case STATE_GENERATE_TARGET_PATH:
129 result = DoGenerateTargetPath(); 136 result = DoGenerateTargetPath();
130 break; 137 break;
131 case STATE_NOTIFY_EXTENSIONS: 138 case STATE_NOTIFY_EXTENSIONS:
132 result = DoNotifyExtensions(); 139 result = DoNotifyExtensions();
133 break; 140 break;
134 case STATE_RESERVE_VIRTUAL_PATH: 141 case STATE_RESERVE_VIRTUAL_PATH:
135 result = DoReserveVirtualPath(); 142 result = DoReserveVirtualPath();
136 break; 143 break;
137 case STATE_PROMPT_USER_FOR_DOWNLOAD_PATH: 144 case STATE_PROMPT_USER_FOR_DOWNLOAD_PATH:
(...skipping 27 matching lines...) Expand all
165 } while (result == CONTINUE); 172 } while (result == CONTINUE);
166 // Note that if a callback completes synchronously, the handler will still 173 // Note that if a callback completes synchronously, the handler will still
167 // return QUIT_DOLOOP. In this case, an inner DoLoop() may complete the target 174 // return QUIT_DOLOOP. In this case, an inner DoLoop() may complete the target
168 // determination and delete |this|. 175 // determination and delete |this|.
169 176
170 if (result == COMPLETE) 177 if (result == COMPLETE)
171 ScheduleCallbackAndDeleteSelf(); 178 ScheduleCallbackAndDeleteSelf();
172 } 179 }
173 180
174 DownloadTargetDeterminer::Result 181 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 void DownloadTargetDeterminer::PromptUserForPermissionDone(bool granted) {
asanka 2015/07/07 17:39:24 Nit: This is dead code on non OS_ANDROID
qinmin 2015/07/07 20:52:50 Done.
198 DCHECK_CURRENTLY_ON(BrowserThread::UI);
199 DCHECK_EQ(STATE_GENERATE_TARGET_PATH, next_state_);
200 if (!granted) {
201 CancelOnFailureAndDeleteSelf();
202 return;
203 }
204
205 DoLoop();
206 }
207
208 DownloadTargetDeterminer::Result
175 DownloadTargetDeterminer::DoGenerateTargetPath() { 209 DownloadTargetDeterminer::DoGenerateTargetPath() {
176 DCHECK_CURRENTLY_ON(BrowserThread::UI); 210 DCHECK_CURRENTLY_ON(BrowserThread::UI);
177 DCHECK(local_path_.empty()); 211 DCHECK(local_path_.empty());
178 DCHECK(!should_prompt_); 212 DCHECK(!should_prompt_);
179 DCHECK(!should_notify_extensions_); 213 DCHECK(!should_notify_extensions_);
180 DCHECK_EQ(DownloadPathReservationTracker::OVERWRITE, conflict_action_); 214 DCHECK_EQ(DownloadPathReservationTracker::OVERWRITE, conflict_action_);
181 bool is_forced_path = !download_->GetForcedFilePath().empty(); 215 bool is_forced_path = !download_->GetForcedFilePath().empty();
182 216
183 next_state_ = STATE_NOTIFY_EXTENSIONS; 217 next_state_ = STATE_NOTIFY_EXTENSIONS;
184 218
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 const base::FilePath& suggested_path) { 929 const base::FilePath& suggested_path) {
896 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); 930 return base::FilePath(suggested_path.value() + kCrdownloadSuffix);
897 } 931 }
898 932
899 #if defined(OS_WIN) 933 #if defined(OS_WIN)
900 // static 934 // static
901 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { 935 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() {
902 return g_is_adobe_reader_up_to_date_; 936 return g_is_adobe_reader_up_to_date_;
903 } 937 }
904 #endif 938 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698