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

Side by Side Diff: chrome/browser/file_select_helper.cc

Issue 1551503002: Convert Pass()→std::move() in //chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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/file_select_helper.h" 5 #include "chrome/browser/file_select_helper.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 Release(); 314 Release();
315 } 315 }
316 } 316 }
317 317
318 scoped_ptr<ui::SelectFileDialog::FileTypeInfo> 318 scoped_ptr<ui::SelectFileDialog::FileTypeInfo>
319 FileSelectHelper::GetFileTypesFromAcceptType( 319 FileSelectHelper::GetFileTypesFromAcceptType(
320 const std::vector<base::string16>& accept_types) { 320 const std::vector<base::string16>& accept_types) {
321 scoped_ptr<ui::SelectFileDialog::FileTypeInfo> base_file_type( 321 scoped_ptr<ui::SelectFileDialog::FileTypeInfo> base_file_type(
322 new ui::SelectFileDialog::FileTypeInfo()); 322 new ui::SelectFileDialog::FileTypeInfo());
323 if (accept_types.empty()) 323 if (accept_types.empty())
324 return base_file_type.Pass(); 324 return base_file_type;
325 325
326 // Create FileTypeInfo and pre-allocate for the first extension list. 326 // Create FileTypeInfo and pre-allocate for the first extension list.
327 scoped_ptr<ui::SelectFileDialog::FileTypeInfo> file_type( 327 scoped_ptr<ui::SelectFileDialog::FileTypeInfo> file_type(
328 new ui::SelectFileDialog::FileTypeInfo(*base_file_type)); 328 new ui::SelectFileDialog::FileTypeInfo(*base_file_type));
329 file_type->include_all_files = true; 329 file_type->include_all_files = true;
330 file_type->extensions.resize(1); 330 file_type->extensions.resize(1);
331 std::vector<base::FilePath::StringType>* extensions = 331 std::vector<base::FilePath::StringType>* extensions =
332 &file_type->extensions.back(); 332 &file_type->extensions.back();
333 333
334 // Find the corresponding extensions. 334 // Find the corresponding extensions.
(...skipping 20 matching lines...) Expand all
355 355
356 net::GetExtensionsForMimeType(ascii_type, extensions); 356 net::GetExtensionsForMimeType(ascii_type, extensions);
357 } 357 }
358 358
359 if (extensions->size() > old_extension_size) 359 if (extensions->size() > old_extension_size)
360 valid_type_count++; 360 valid_type_count++;
361 } 361 }
362 362
363 // If no valid extension is added, bail out. 363 // If no valid extension is added, bail out.
364 if (valid_type_count == 0) 364 if (valid_type_count == 0)
365 return base_file_type.Pass(); 365 return base_file_type;
366 366
367 // Use a generic description "Custom Files" if either of the following is 367 // Use a generic description "Custom Files" if either of the following is
368 // true: 368 // true:
369 // 1) There're multiple types specified, like "audio/*,video/*" 369 // 1) There're multiple types specified, like "audio/*,video/*"
370 // 2) There're multiple extensions for a MIME type without parameter, like 370 // 2) There're multiple extensions for a MIME type without parameter, like
371 // "ehtml,shtml,htm,html" for "text/html". On Windows, the select file 371 // "ehtml,shtml,htm,html" for "text/html". On Windows, the select file
372 // dialog uses the first extension in the list to form the description, 372 // dialog uses the first extension in the list to form the description,
373 // like "EHTML Files". This is not what we want. 373 // like "EHTML Files". This is not what we want.
374 if (valid_type_count > 1 || 374 if (valid_type_count > 1 ||
375 (valid_type_count == 1 && description_id == 0 && extensions->size() > 1)) 375 (valid_type_count == 1 && description_id == 0 && extensions->size() > 1))
376 description_id = IDS_CUSTOM_FILES; 376 description_id = IDS_CUSTOM_FILES;
377 377
378 if (description_id) { 378 if (description_id) {
379 file_type->extension_description_overrides.push_back( 379 file_type->extension_description_overrides.push_back(
380 l10n_util::GetStringUTF16(description_id)); 380 l10n_util::GetStringUTF16(description_id));
381 } 381 }
382 382
383 return file_type.Pass(); 383 return file_type;
384 } 384 }
385 385
386 // static 386 // static
387 void FileSelectHelper::RunFileChooser(content::WebContents* tab, 387 void FileSelectHelper::RunFileChooser(content::WebContents* tab,
388 const FileChooserParams& params) { 388 const FileChooserParams& params) {
389 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); 389 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
390 // FileSelectHelper will keep itself alive until it sends the result message. 390 // FileSelectHelper will keep itself alive until it sends the result message.
391 scoped_refptr<FileSelectHelper> file_select_helper( 391 scoped_refptr<FileSelectHelper> file_select_helper(
392 new FileSelectHelper(profile)); 392 new FileSelectHelper(profile));
393 file_select_helper->RunFileChooser( 393 file_select_helper->RunFileChooser(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 !params->default_file_name.empty()) { 463 !params->default_file_name.empty()) {
464 GURL requestor = params->requestor; 464 GURL requestor = params->requestor;
465 safe_browsing::CheckUnverifiedDownloadPolicy( 465 safe_browsing::CheckUnverifiedDownloadPolicy(
466 requestor, default_file_path, 466 requestor, default_file_path,
467 base::Bind(&FileSelectHelper::ApplyUnverifiedDownloadPolicy, this, 467 base::Bind(&FileSelectHelper::ApplyUnverifiedDownloadPolicy, this,
468 default_file_path, base::Passed(&params))); 468 default_file_path, base::Passed(&params)));
469 return; 469 return;
470 } 470 }
471 #endif 471 #endif
472 472
473 RunFileChooserOnUIThread(default_file_path, params.Pass()); 473 RunFileChooserOnUIThread(default_file_path, std::move(params));
474 } 474 }
475 475
476 #if defined(FULL_SAFE_BROWSING) 476 #if defined(FULL_SAFE_BROWSING)
477 void FileSelectHelper::ApplyUnverifiedDownloadPolicy( 477 void FileSelectHelper::ApplyUnverifiedDownloadPolicy(
478 const base::FilePath& default_path, 478 const base::FilePath& default_path,
479 scoped_ptr<FileChooserParams> params, 479 scoped_ptr<FileChooserParams> params,
480 safe_browsing::UnverifiedDownloadPolicy policy) { 480 safe_browsing::UnverifiedDownloadPolicy policy) {
481 DCHECK(params); 481 DCHECK(params);
482 if (policy == safe_browsing::UnverifiedDownloadPolicy::DISALLOWED) { 482 if (policy == safe_browsing::UnverifiedDownloadPolicy::DISALLOWED) {
483 NotifyRenderViewHostAndEnd(std::vector<ui::SelectedFileInfo>()); 483 NotifyRenderViewHostAndEnd(std::vector<ui::SelectedFileInfo>());
484 return; 484 return;
485 } 485 }
486 486
487 RunFileChooserOnUIThread(default_path, params.Pass()); 487 RunFileChooserOnUIThread(default_path, std::move(params));
488 } 488 }
489 #endif 489 #endif
490 490
491 void FileSelectHelper::RunFileChooserOnUIThread( 491 void FileSelectHelper::RunFileChooserOnUIThread(
492 const base::FilePath& default_file_path, 492 const base::FilePath& default_file_path,
493 scoped_ptr<FileChooserParams> params) { 493 scoped_ptr<FileChooserParams> params) {
494 DCHECK(params); 494 DCHECK(params);
495 if (!render_view_host_ || !web_contents_ || !IsValidProfile(profile_) || 495 if (!render_view_host_ || !web_contents_ || !IsValidProfile(profile_) ||
496 !render_view_host_->GetWidget()->GetView()) { 496 !render_view_host_->GetWidget()->GetView()) {
497 // If the renderer was destroyed before we started, just cancel the 497 // If the renderer was destroyed before we started, just cancel the
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 627
628 // static 628 // static
629 base::FilePath FileSelectHelper::GetSanitizedFileName( 629 base::FilePath FileSelectHelper::GetSanitizedFileName(
630 const base::FilePath& suggested_filename) { 630 const base::FilePath& suggested_filename) {
631 if (suggested_filename.empty()) 631 if (suggested_filename.empty())
632 return base::FilePath(); 632 return base::FilePath();
633 return net::GenerateFileName( 633 return net::GenerateFileName(
634 GURL(), std::string(), std::string(), suggested_filename.AsUTF8Unsafe(), 634 GURL(), std::string(), std::string(), suggested_filename.AsUTF8Unsafe(),
635 std::string(), l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); 635 std::string(), l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME));
636 } 636 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698