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

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

Issue 2117343007: Show download error message if sdcard is not available (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_path_reservation_tracker.h" 5 #include "chrome/browser/download/download_path_reservation_tracker.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "base/third_party/icu/icu_utf.h" 21 #include "base/third_party/icu/icu_utf.h"
22 #include "build/build_config.h" 22 #include "build/build_config.h"
23 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/features.h"
24 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/download_item.h" 26 #include "content/public/browser/download_item.h"
26 27
27 using content::BrowserThread; 28 using content::BrowserThread;
28 using content::DownloadItem; 29 using content::DownloadItem;
29 30
30 namespace { 31 namespace {
31 32
32 typedef DownloadItem* ReservationKey; 33 typedef DownloadItem* ReservationKey;
33 typedef std::map<ReservationKey, base::FilePath> ReservationMap; 34 typedef std::map<ReservationKey, base::FilePath> ReservationMap;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 (create_directory || 196 (create_directory ||
196 (!default_download_path.empty() && 197 (!default_download_path.empty() &&
197 (default_download_path == target_dir)))) { 198 (default_download_path == target_dir)))) {
198 base::CreateDirectory(target_dir); 199 base::CreateDirectory(target_dir);
199 } 200 }
200 201
201 // Check writability of the suggested path. If we can't write to it, default 202 // Check writability of the suggested path. If we can't write to it, default
202 // to the user's "My Documents" directory. We'll prompt them in this case. 203 // to the user's "My Documents" directory. We'll prompt them in this case.
203 if (!base::PathIsWritable(target_dir)) { 204 if (!base::PathIsWritable(target_dir)) {
204 DVLOG(1) << "Unable to write to directory \"" << target_dir.value() << "\""; 205 DVLOG(1) << "Unable to write to directory \"" << target_dir.value() << "\"";
206 #if BUILDFLAG(ANDROID_JAVA_UI)
207 // On Android, DIR_USER_DOCUMENTS is in reality a subdirectory
208 // of DIR_ANDROID_APP_DATA which isn't accessible by other apps.
209 reserved_path->clear();
210 (*g_reservation_map)[key] = *reserved_path;
211 return false;
212 #else
205 is_path_writeable = false; 213 is_path_writeable = false;
206 PathService::Get(chrome::DIR_USER_DOCUMENTS, &target_dir); 214 PathService::Get(chrome::DIR_USER_DOCUMENTS, &target_dir);
207 target_path = target_dir.Append(filename); 215 target_path = target_dir.Append(filename);
216 #endif // BUILDFLAG(ANDROID_JAVA_UI)
208 } 217 }
209 218
210 if (is_path_writeable) { 219 if (is_path_writeable) {
211 // Check the limit of file name length if it could be obtained. When the 220 // Check the limit of file name length if it could be obtained. When the
212 // suggested name exceeds the limit, truncate or prompt the user. 221 // suggested name exceeds the limit, truncate or prompt the user.
213 int max_length = base::GetMaximumPathComponentLength(target_dir); 222 int max_length = base::GetMaximumPathComponentLength(target_dir);
214 if (max_length != -1) { 223 if (max_length != -1) {
215 int limit = max_length - kIntermediateNameSuffixLength; 224 int limit = max_length - kIntermediateNameSuffixLength;
216 if (limit <= 0 || !TruncateFileName(&target_path, limit)) 225 if (limit <= 0 || !TruncateFileName(&target_path, limit))
217 name_too_long = true; 226 name_too_long = true;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 base::Bind(&RunGetReservedPathCallback, 398 base::Bind(&RunGetReservedPathCallback,
390 callback, 399 callback,
391 base::Owned(reserved_path))); 400 base::Owned(reserved_path)));
392 } 401 }
393 402
394 // static 403 // static
395 bool DownloadPathReservationTracker::IsPathInUseForTesting( 404 bool DownloadPathReservationTracker::IsPathInUseForTesting(
396 const base::FilePath& path) { 405 const base::FilePath& path) {
397 return IsPathInUse(path); 406 return IsPathInUse(path);
398 } 407 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698