| OLD | NEW |
| 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/chromeos/drive/debug_info_collector.h" | 5 #include "chrome/browser/chromeos/drive/debug_info_collector.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "google_apis/drive/task_util.h" | 11 #include "google_apis/drive/task_util.h" |
| 12 | 12 |
| 13 namespace drive { | 13 namespace drive { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 void IterateFileCacheInternal( | 17 void IterateFileCacheInternal( |
| 18 internal::ResourceMetadata* metadata, | 18 internal::ResourceMetadata* metadata, |
| 19 const DebugInfoCollector::IterateFileCacheCallback& iteration_callback) { | 19 const DebugInfoCollector::IterateFileCacheCallback& iteration_callback) { |
| 20 scoped_ptr<internal::ResourceMetadata::Iterator> it = metadata->GetIterator(); | 20 std::unique_ptr<internal::ResourceMetadata::Iterator> it = |
| 21 metadata->GetIterator(); |
| 21 for (; !it->IsAtEnd(); it->Advance()) { | 22 for (; !it->IsAtEnd(); it->Advance()) { |
| 22 if (it->GetValue().file_specific_info().has_cache_state()) { | 23 if (it->GetValue().file_specific_info().has_cache_state()) { |
| 23 iteration_callback.Run(it->GetID(), | 24 iteration_callback.Run(it->GetID(), |
| 24 it->GetValue().file_specific_info().cache_state()); | 25 it->GetValue().file_specific_info().cache_state()); |
| 25 } | 26 } |
| 26 } | 27 } |
| 27 DCHECK(!it->HasError()); | 28 DCHECK(!it->HasError()); |
| 28 } | 29 } |
| 29 | 30 |
| 30 // Runs the callback with arguments. | 31 // Runs the callback with arguments. |
| 31 void RunGetResourceEntryCallback(const GetResourceEntryCallback& callback, | 32 void RunGetResourceEntryCallback(const GetResourceEntryCallback& callback, |
| 32 scoped_ptr<ResourceEntry> entry, | 33 std::unique_ptr<ResourceEntry> entry, |
| 33 FileError error) { | 34 FileError error) { |
| 34 DCHECK(!callback.is_null()); | 35 DCHECK(!callback.is_null()); |
| 35 if (error != FILE_ERROR_OK) | 36 if (error != FILE_ERROR_OK) |
| 36 entry.reset(); | 37 entry.reset(); |
| 37 callback.Run(error, std::move(entry)); | 38 callback.Run(error, std::move(entry)); |
| 38 } | 39 } |
| 39 | 40 |
| 40 // Runs the callback with arguments. | 41 // Runs the callback with arguments. |
| 41 void RunReadDirectoryCallback( | 42 void RunReadDirectoryCallback( |
| 42 const DebugInfoCollector::ReadDirectoryCallback& callback, | 43 const DebugInfoCollector::ReadDirectoryCallback& callback, |
| 43 scoped_ptr<ResourceEntryVector> entries, | 44 std::unique_ptr<ResourceEntryVector> entries, |
| 44 FileError error) { | 45 FileError error) { |
| 45 DCHECK(!callback.is_null()); | 46 DCHECK(!callback.is_null()); |
| 46 if (error != FILE_ERROR_OK) | 47 if (error != FILE_ERROR_OK) |
| 47 entries.reset(); | 48 entries.reset(); |
| 48 callback.Run(error, std::move(entries)); | 49 callback.Run(error, std::move(entries)); |
| 49 } | 50 } |
| 50 | 51 |
| 51 } // namespace | 52 } // namespace |
| 52 | 53 |
| 53 DebugInfoCollector::DebugInfoCollector( | 54 DebugInfoCollector::DebugInfoCollector( |
| 54 internal::ResourceMetadata* metadata, | 55 internal::ResourceMetadata* metadata, |
| 55 FileSystemInterface* file_system, | 56 FileSystemInterface* file_system, |
| 56 base::SequencedTaskRunner* blocking_task_runner) | 57 base::SequencedTaskRunner* blocking_task_runner) |
| 57 : metadata_(metadata), | 58 : metadata_(metadata), |
| 58 file_system_(file_system), | 59 file_system_(file_system), |
| 59 blocking_task_runner_(blocking_task_runner) { | 60 blocking_task_runner_(blocking_task_runner) { |
| 60 DCHECK(metadata_); | 61 DCHECK(metadata_); |
| 61 DCHECK(file_system_); | 62 DCHECK(file_system_); |
| 62 } | 63 } |
| 63 | 64 |
| 64 DebugInfoCollector::~DebugInfoCollector() { | 65 DebugInfoCollector::~DebugInfoCollector() { |
| 65 } | 66 } |
| 66 | 67 |
| 67 void DebugInfoCollector::GetResourceEntry( | 68 void DebugInfoCollector::GetResourceEntry( |
| 68 const base::FilePath& file_path, | 69 const base::FilePath& file_path, |
| 69 const GetResourceEntryCallback& callback) { | 70 const GetResourceEntryCallback& callback) { |
| 70 DCHECK(thread_checker_.CalledOnValidThread()); | 71 DCHECK(thread_checker_.CalledOnValidThread()); |
| 71 DCHECK(!callback.is_null()); | 72 DCHECK(!callback.is_null()); |
| 72 | 73 |
| 73 scoped_ptr<ResourceEntry> entry(new ResourceEntry); | 74 std::unique_ptr<ResourceEntry> entry(new ResourceEntry); |
| 74 ResourceEntry* entry_ptr = entry.get(); | 75 ResourceEntry* entry_ptr = entry.get(); |
| 75 base::PostTaskAndReplyWithResult( | 76 base::PostTaskAndReplyWithResult( |
| 76 blocking_task_runner_.get(), | 77 blocking_task_runner_.get(), |
| 77 FROM_HERE, | 78 FROM_HERE, |
| 78 base::Bind(&internal::ResourceMetadata::GetResourceEntryByPath, | 79 base::Bind(&internal::ResourceMetadata::GetResourceEntryByPath, |
| 79 base::Unretained(metadata_), | 80 base::Unretained(metadata_), |
| 80 file_path, | 81 file_path, |
| 81 entry_ptr), | 82 entry_ptr), |
| 82 base::Bind(&RunGetResourceEntryCallback, callback, base::Passed(&entry))); | 83 base::Bind(&RunGetResourceEntryCallback, callback, base::Passed(&entry))); |
| 83 } | 84 } |
| 84 | 85 |
| 85 void DebugInfoCollector::ReadDirectory( | 86 void DebugInfoCollector::ReadDirectory( |
| 86 const base::FilePath& file_path, | 87 const base::FilePath& file_path, |
| 87 const ReadDirectoryCallback& callback) { | 88 const ReadDirectoryCallback& callback) { |
| 88 DCHECK(thread_checker_.CalledOnValidThread()); | 89 DCHECK(thread_checker_.CalledOnValidThread()); |
| 89 DCHECK(!callback.is_null()); | 90 DCHECK(!callback.is_null()); |
| 90 | 91 |
| 91 scoped_ptr<ResourceEntryVector> entries(new ResourceEntryVector); | 92 std::unique_ptr<ResourceEntryVector> entries(new ResourceEntryVector); |
| 92 ResourceEntryVector* entries_ptr = entries.get(); | 93 ResourceEntryVector* entries_ptr = entries.get(); |
| 93 base::PostTaskAndReplyWithResult( | 94 base::PostTaskAndReplyWithResult( |
| 94 blocking_task_runner_.get(), | 95 blocking_task_runner_.get(), |
| 95 FROM_HERE, | 96 FROM_HERE, |
| 96 base::Bind(&internal::ResourceMetadata::ReadDirectoryByPath, | 97 base::Bind(&internal::ResourceMetadata::ReadDirectoryByPath, |
| 97 base::Unretained(metadata_), | 98 base::Unretained(metadata_), |
| 98 file_path, | 99 file_path, |
| 99 entries_ptr), | 100 entries_ptr), |
| 100 base::Bind(&RunReadDirectoryCallback, callback, base::Passed(&entries))); | 101 base::Bind(&RunReadDirectoryCallback, callback, base::Passed(&entries))); |
| 101 } | 102 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 120 DCHECK(thread_checker_.CalledOnValidThread()); | 121 DCHECK(thread_checker_.CalledOnValidThread()); |
| 121 DCHECK(!callback.is_null()); | 122 DCHECK(!callback.is_null()); |
| 122 | 123 |
| 123 // Currently, this is just a proxy to the FileSystem. | 124 // Currently, this is just a proxy to the FileSystem. |
| 124 // TODO(hidehiko): Move the implementation to here to simplify the | 125 // TODO(hidehiko): Move the implementation to here to simplify the |
| 125 // FileSystem's implementation. crbug.com/237088 | 126 // FileSystem's implementation. crbug.com/237088 |
| 126 file_system_->GetMetadata(callback); | 127 file_system_->GetMetadata(callback); |
| 127 } | 128 } |
| 128 | 129 |
| 129 } // namespace drive | 130 } // namespace drive |
| OLD | NEW |