Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / debug_info_collector.cc
blob6159ea194caff1f431bc2b38f6fb016832274c77
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 "content/public/browser/browser_thread.h"
10 #include "google_apis/drive/task_util.h"
12 using content::BrowserThread;
14 namespace drive {
16 namespace {
18 void IterateFileCacheInternal(
19 internal::ResourceMetadata* metadata,
20 const DebugInfoCollector::IterateFileCacheCallback& iteration_callback) {
21 scoped_ptr<internal::ResourceMetadata::Iterator> it = metadata->GetIterator();
22 for (; !it->IsAtEnd(); it->Advance()) {
23 if (it->GetValue().file_specific_info().has_cache_state()) {
24 iteration_callback.Run(it->GetID(),
25 it->GetValue().file_specific_info().cache_state());
28 DCHECK(!it->HasError());
31 // Runs the callback with arguments.
32 void RunGetResourceEntryCallback(const GetResourceEntryCallback& callback,
33 scoped_ptr<ResourceEntry> entry,
34 FileError error) {
35 DCHECK(!callback.is_null());
36 if (error != FILE_ERROR_OK)
37 entry.reset();
38 callback.Run(error, entry.Pass());
41 // Runs the callback with arguments.
42 void RunReadDirectoryCallback(
43 const DebugInfoCollector::ReadDirectoryCallback& callback,
44 scoped_ptr<ResourceEntryVector> entries,
45 FileError error) {
46 DCHECK(!callback.is_null());
47 if (error != FILE_ERROR_OK)
48 entries.reset();
49 callback.Run(error, entries.Pass());
52 } // namespace
54 DebugInfoCollector::DebugInfoCollector(
55 internal::ResourceMetadata* metadata,
56 FileSystemInterface* file_system,
57 base::SequencedTaskRunner* blocking_task_runner)
58 : metadata_(metadata),
59 file_system_(file_system),
60 blocking_task_runner_(blocking_task_runner) {
61 DCHECK(metadata_);
62 DCHECK(file_system_);
65 DebugInfoCollector::~DebugInfoCollector() {
68 void DebugInfoCollector::GetResourceEntry(
69 const base::FilePath& file_path,
70 const GetResourceEntryCallback& callback) {
71 DCHECK_CURRENTLY_ON(BrowserThread::UI);
72 DCHECK(!callback.is_null());
74 scoped_ptr<ResourceEntry> entry(new ResourceEntry);
75 ResourceEntry* entry_ptr = entry.get();
76 base::PostTaskAndReplyWithResult(
77 blocking_task_runner_.get(),
78 FROM_HERE,
79 base::Bind(&internal::ResourceMetadata::GetResourceEntryByPath,
80 base::Unretained(metadata_),
81 file_path,
82 entry_ptr),
83 base::Bind(&RunGetResourceEntryCallback, callback, base::Passed(&entry)));
86 void DebugInfoCollector::ReadDirectory(
87 const base::FilePath& file_path,
88 const ReadDirectoryCallback& callback) {
89 DCHECK_CURRENTLY_ON(BrowserThread::UI);
90 DCHECK(!callback.is_null());
92 scoped_ptr<ResourceEntryVector> entries(new ResourceEntryVector);
93 ResourceEntryVector* entries_ptr = entries.get();
94 base::PostTaskAndReplyWithResult(
95 blocking_task_runner_.get(),
96 FROM_HERE,
97 base::Bind(&internal::ResourceMetadata::ReadDirectoryByPath,
98 base::Unretained(metadata_),
99 file_path,
100 entries_ptr),
101 base::Bind(&RunReadDirectoryCallback, callback, base::Passed(&entries)));
104 void DebugInfoCollector::IterateFileCache(
105 const IterateFileCacheCallback& iteration_callback,
106 const base::Closure& completion_callback) {
107 DCHECK_CURRENTLY_ON(BrowserThread::UI);
108 DCHECK(!iteration_callback.is_null());
109 DCHECK(!completion_callback.is_null());
111 blocking_task_runner_->PostTaskAndReply(
112 FROM_HERE,
113 base::Bind(&IterateFileCacheInternal,
114 metadata_,
115 google_apis::CreateRelayCallback(iteration_callback)),
116 completion_callback);
119 void DebugInfoCollector::GetMetadata(
120 const GetFilesystemMetadataCallback& callback) {
121 DCHECK_CURRENTLY_ON(BrowserThread::UI);
122 DCHECK(!callback.is_null());
124 // Currently, this is just a proxy to the FileSystem.
125 // TODO(hidehiko): Move the implementation to here to simplify the
126 // FileSystem's implementation. crbug.com/237088
127 file_system_->GetMetadata(callback);
130 } // namespace drive