Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / debug_info_collector.cc
blobcf50912baa751718d891fa548d2220c0472b9a24
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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/drive/debug_info_collector.h"
7 #include "base/callback.h"
8 #include "base/logging.h"
9 #include "google_apis/drive/task_util.h"
11 namespace drive {
13 namespace {
15 void IterateFileCacheInternal(
16 internal::ResourceMetadata* metadata,
17 const DebugInfoCollector::IterateFileCacheCallback& iteration_callback) {
18 scoped_ptr<internal::ResourceMetadata::Iterator> it = metadata->GetIterator();
19 for (; !it->IsAtEnd(); it->Advance()) {
20 if (it->GetValue().file_specific_info().has_cache_state()) {
21 iteration_callback.Run(it->GetID(),
22 it->GetValue().file_specific_info().cache_state());
25 DCHECK(!it->HasError());
28 // Runs the callback with arguments.
29 void RunGetResourceEntryCallback(const GetResourceEntryCallback& callback,
30 scoped_ptr<ResourceEntry> entry,
31 FileError error) {
32 DCHECK(!callback.is_null());
33 if (error != FILE_ERROR_OK)
34 entry.reset();
35 callback.Run(error, entry.Pass());
38 // Runs the callback with arguments.
39 void RunReadDirectoryCallback(
40 const DebugInfoCollector::ReadDirectoryCallback& callback,
41 scoped_ptr<ResourceEntryVector> entries,
42 FileError error) {
43 DCHECK(!callback.is_null());
44 if (error != FILE_ERROR_OK)
45 entries.reset();
46 callback.Run(error, entries.Pass());
49 } // namespace
51 DebugInfoCollector::DebugInfoCollector(
52 internal::ResourceMetadata* metadata,
53 FileSystemInterface* file_system,
54 base::SequencedTaskRunner* blocking_task_runner)
55 : metadata_(metadata),
56 file_system_(file_system),
57 blocking_task_runner_(blocking_task_runner) {
58 DCHECK(metadata_);
59 DCHECK(file_system_);
62 DebugInfoCollector::~DebugInfoCollector() {
65 void DebugInfoCollector::GetResourceEntry(
66 const base::FilePath& file_path,
67 const GetResourceEntryCallback& callback) {
68 DCHECK(thread_checker_.CalledOnValidThread());
69 DCHECK(!callback.is_null());
71 scoped_ptr<ResourceEntry> entry(new ResourceEntry);
72 ResourceEntry* entry_ptr = entry.get();
73 base::PostTaskAndReplyWithResult(
74 blocking_task_runner_.get(),
75 FROM_HERE,
76 base::Bind(&internal::ResourceMetadata::GetResourceEntryByPath,
77 base::Unretained(metadata_),
78 file_path,
79 entry_ptr),
80 base::Bind(&RunGetResourceEntryCallback, callback, base::Passed(&entry)));
83 void DebugInfoCollector::ReadDirectory(
84 const base::FilePath& file_path,
85 const ReadDirectoryCallback& callback) {
86 DCHECK(thread_checker_.CalledOnValidThread());
87 DCHECK(!callback.is_null());
89 scoped_ptr<ResourceEntryVector> entries(new ResourceEntryVector);
90 ResourceEntryVector* entries_ptr = entries.get();
91 base::PostTaskAndReplyWithResult(
92 blocking_task_runner_.get(),
93 FROM_HERE,
94 base::Bind(&internal::ResourceMetadata::ReadDirectoryByPath,
95 base::Unretained(metadata_),
96 file_path,
97 entries_ptr),
98 base::Bind(&RunReadDirectoryCallback, callback, base::Passed(&entries)));
101 void DebugInfoCollector::IterateFileCache(
102 const IterateFileCacheCallback& iteration_callback,
103 const base::Closure& completion_callback) {
104 DCHECK(thread_checker_.CalledOnValidThread());
105 DCHECK(!iteration_callback.is_null());
106 DCHECK(!completion_callback.is_null());
108 blocking_task_runner_->PostTaskAndReply(
109 FROM_HERE,
110 base::Bind(&IterateFileCacheInternal,
111 metadata_,
112 google_apis::CreateRelayCallback(iteration_callback)),
113 completion_callback);
116 void DebugInfoCollector::GetMetadata(
117 const GetFilesystemMetadataCallback& callback) {
118 DCHECK(thread_checker_.CalledOnValidThread());
119 DCHECK(!callback.is_null());
121 // Currently, this is just a proxy to the FileSystem.
122 // TODO(hidehiko): Move the implementation to here to simplify the
123 // FileSystem's implementation. crbug.com/237088
124 file_system_->GetMetadata(callback);
127 } // namespace drive