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

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

Issue 1217223006: Prompt user for file access permission before download starts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressing asanka's comments 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 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_H_ 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_H_
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_H_ 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_H_
7 7
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/task/cancelable_task_tracker.h" 12 #include "base/task/cancelable_task_tracker.h"
13 #include "chrome/browser/download/download_path_reservation_tracker.h" 13 #include "chrome/browser/download/download_path_reservation_tracker.h"
14 #include "chrome/browser/download/download_target_determiner_delegate.h" 14 #include "chrome/browser/download/download_target_determiner_delegate.h"
15 #include "chrome/browser/download/download_target_info.h" 15 #include "chrome/browser/download/download_target_info.h"
16 #include "content/public/browser/download_danger_type.h" 16 #include "content/public/browser/download_danger_type.h"
17 #include "content/public/browser/download_item.h" 17 #include "content/public/browser/download_item.h"
18 #include "content/public/browser/download_manager_delegate.h" 18 #include "content/public/browser/download_manager_delegate.h"
19 19
20 class ChromeDownloadManagerDelegate; 20 class ChromeDownloadManagerDelegate;
21 class Profile; 21 class Profile;
22 class DownloadPrefs; 22 class DownloadPrefs;
23 23
24 namespace content { 24 namespace content {
25 enum DownloadDangerType; 25 enum DownloadDangerType;
26 #if defined(OS_ANDROID)
27 class DownloadControllerAndroid;
28 #endif
26 } 29 }
27 30
28 // Determines the target of the download. 31 // Determines the target of the download.
29 // 32 //
30 // Terminology: 33 // Terminology:
31 // Virtual Path: A path representing the target of the download that may or 34 // Virtual Path: A path representing the target of the download that may or
32 // may not be a physical file path. E.g. if the target of the download is in 35 // may not be a physical file path. E.g. if the target of the download is in
33 // cloud storage, then the virtual path may be relative to a logical mount 36 // cloud storage, then the virtual path may be relative to a logical mount
34 // point. 37 // point.
35 // 38 //
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 static bool IsAdobeReaderUpToDate(); 89 static bool IsAdobeReaderUpToDate();
87 #endif 90 #endif
88 91
89 private: 92 private:
90 // The main workflow is controlled via a set of state transitions. Each state 93 // The main workflow is controlled via a set of state transitions. Each state
91 // has an associated handler. The handler for STATE_FOO is DoFoo. Each handler 94 // has an associated handler. The handler for STATE_FOO is DoFoo. Each handler
92 // performs work, determines the next state to transition to and returns a 95 // performs work, determines the next state to transition to and returns a
93 // Result indicating how the workflow should proceed. The loop ends when a 96 // Result indicating how the workflow should proceed. The loop ends when a
94 // handler returns COMPLETE. 97 // handler returns COMPLETE.
95 enum State { 98 enum State {
99 STATE_PROMPT_USER_FOR_PERMISSION,
96 STATE_GENERATE_TARGET_PATH, 100 STATE_GENERATE_TARGET_PATH,
97 STATE_NOTIFY_EXTENSIONS, 101 STATE_NOTIFY_EXTENSIONS,
98 STATE_RESERVE_VIRTUAL_PATH, 102 STATE_RESERVE_VIRTUAL_PATH,
99 STATE_PROMPT_USER_FOR_DOWNLOAD_PATH, 103 STATE_PROMPT_USER_FOR_DOWNLOAD_PATH,
100 STATE_DETERMINE_LOCAL_PATH, 104 STATE_DETERMINE_LOCAL_PATH,
101 STATE_DETERMINE_MIME_TYPE, 105 STATE_DETERMINE_MIME_TYPE,
102 STATE_DETERMINE_IF_HANDLED_SAFELY_BY_BROWSER, 106 STATE_DETERMINE_IF_HANDLED_SAFELY_BY_BROWSER,
103 STATE_DETERMINE_IF_ADOBE_READER_UP_TO_DATE, 107 STATE_DETERMINE_IF_ADOBE_READER_UP_TO_DATE,
104 STATE_CHECK_DOWNLOAD_URL, 108 STATE_CHECK_DOWNLOAD_URL,
105 STATE_CHECK_VISITED_REFERRER_BEFORE, 109 STATE_CHECK_VISITED_REFERRER_BEFORE,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 145
142 ~DownloadTargetDeterminer() override; 146 ~DownloadTargetDeterminer() override;
143 147
144 // Invoke each successive handler until a handler returns QUIT_DOLOOP or 148 // Invoke each successive handler until a handler returns QUIT_DOLOOP or
145 // COMPLETE. Note that as a result, this object might be deleted. So |this| 149 // COMPLETE. Note that as a result, this object might be deleted. So |this|
146 // should not be accessed after calling DoLoop(). 150 // should not be accessed after calling DoLoop().
147 void DoLoop(); 151 void DoLoop();
148 152
149 // === Main workflow === 153 // === Main workflow ===
150 154
155 // Prompts user for file access if necessary.
156 // Next state:
157 // - STATE_GENERATE_TARGET_PATH.
158 Result DoPromptUserForPermission();
159
160 // Callback invoked after the file access prompt completes. Cancels the
161 // download if the user doesn't grant file access.
162 void PromptUserForPermissionDone(bool granted);
163
151 // Generates an initial target path. This target is based only on the state of 164 // Generates an initial target path. This target is based only on the state of
152 // the download item. 165 // the download item.
153 // Next state: 166 // Next state:
154 // - STATE_NONE : If the download is not in progress, returns COMPLETE. 167 // - STATE_NONE : If the download is not in progress, returns COMPLETE.
155 // - STATE_NOTIFY_EXTENSIONS : All other downloads. 168 // - STATE_NOTIFY_EXTENSIONS : All other downloads.
156 Result DoGenerateTargetPath(); 169 Result DoGenerateTargetPath();
157 170
158 // Notifies downloads extensions. If any extension wishes to override the 171 // Notifies downloads extensions. If any extension wishes to override the
159 // download filename, it will respond to the OnDeterminingFilename() 172 // download filename, it will respond to the OnDeterminingFilename()
160 // notification. 173 // notification.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 std::string mime_type_; 324 std::string mime_type_;
312 bool is_filetype_handled_safely_; 325 bool is_filetype_handled_safely_;
313 326
314 content::DownloadItem* download_; 327 content::DownloadItem* download_;
315 const bool is_resumption_; 328 const bool is_resumption_;
316 DownloadPrefs* download_prefs_; 329 DownloadPrefs* download_prefs_;
317 DownloadTargetDeterminerDelegate* delegate_; 330 DownloadTargetDeterminerDelegate* delegate_;
318 CompletionCallback completion_callback_; 331 CompletionCallback completion_callback_;
319 base::CancelableTaskTracker history_tracker_; 332 base::CancelableTaskTracker history_tracker_;
320 333
334 #if defined(OS_ANDROID)
335 // Download controller for file access prompt.
336 content::DownloadControllerAndroid* download_controller_;
337 #endif
321 base::WeakPtrFactory<DownloadTargetDeterminer> weak_ptr_factory_; 338 base::WeakPtrFactory<DownloadTargetDeterminer> weak_ptr_factory_;
322 339
323 DISALLOW_COPY_AND_ASSIGN(DownloadTargetDeterminer); 340 DISALLOW_COPY_AND_ASSIGN(DownloadTargetDeterminer);
324 }; 341 };
325 342
326 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_H_ 343 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698