OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/media_galleries/media_folder_finder.h" | 5 #include "chrome/browser/media_galleries/media_folder_finder.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 | 410 |
411 if (folders_to_scan_.empty()) { | 411 if (folders_to_scan_.empty()) { |
412 scan_state_ = SCAN_STATE_FINISHED; | 412 scan_state_ = SCAN_STATE_FINISHED; |
413 results_callback_.Run(true /* success? */, results_); | 413 results_callback_.Run(true /* success? */, results_); |
414 return; | 414 return; |
415 } | 415 } |
416 | 416 |
417 base::FilePath folder_to_scan = folders_to_scan_.back(); | 417 base::FilePath folder_to_scan = folders_to_scan_.back(); |
418 folders_to_scan_.pop_back(); | 418 folders_to_scan_.pop_back(); |
419 base::PostTaskAndReplyWithResult( | 419 base::PostTaskAndReplyWithResult( |
420 worker_task_runner_, FROM_HERE, | 420 worker_task_runner_.get(), |
421 base::Bind(&Worker::ScanFolder, | 421 FROM_HERE, |
422 base::Unretained(worker_), | 422 base::Bind( |
423 folder_to_scan), | 423 &Worker::ScanFolder, base::Unretained(worker_), folder_to_scan), |
424 base::Bind(&MediaFolderFinder::GotScanResults, | 424 base::Bind(&MediaFolderFinder::GotScanResults, |
425 weak_factory_.GetWeakPtr(), | 425 weak_factory_.GetWeakPtr(), |
426 folder_to_scan)); | 426 folder_to_scan)); |
427 } | 427 } |
428 | 428 |
429 void MediaFolderFinder::GotScanResults(const base::FilePath& path, | 429 void MediaFolderFinder::GotScanResults(const base::FilePath& path, |
430 const WorkerReply& reply) { | 430 const WorkerReply& reply) { |
431 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 431 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
432 DCHECK_EQ(SCAN_STATE_STARTED, scan_state_); | 432 DCHECK_EQ(SCAN_STATE_STARTED, scan_state_); |
433 DCHECK(!path.empty()); | 433 DCHECK(!path.empty()); |
434 CHECK(!ContainsKey(results_, path)); | 434 CHECK(!ContainsKey(results_, path)); |
435 | 435 |
436 if (!IsEmptyScanResult(reply.scan_result)) | 436 if (!IsEmptyScanResult(reply.scan_result)) |
437 results_[path] = reply.scan_result; | 437 results_[path] = reply.scan_result; |
438 | 438 |
439 // Push new folders to the |folders_to_scan_| in reverse order. | 439 // Push new folders to the |folders_to_scan_| in reverse order. |
440 std::copy(reply.new_folders.rbegin(), reply.new_folders.rend(), | 440 std::copy(reply.new_folders.rbegin(), reply.new_folders.rend(), |
441 std::back_inserter(folders_to_scan_)); | 441 std::back_inserter(folders_to_scan_)); |
442 | 442 |
443 ScanFolder(); | 443 ScanFolder(); |
444 } | 444 } |
OLD | NEW |