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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/fake_provided_file_system.cc

Issue 246913003: [fsp] Add support for reading directories. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
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/chromeos/file_system_provider/fake_provided_file_system .h" 5 #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system .h"
6 6
7 #include <string>
8
7 #include "base/files/file.h" 9 #include "base/files/file.h"
8 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
9 #include "extensions/browser/event_router.h" 11 #include "extensions/browser/event_router.h"
10 12
11 namespace chromeos { 13 namespace chromeos {
12 namespace file_system_provider { 14 namespace file_system_provider {
15 namespace {
16
17 // Adds a fake entry to the entry list.
18 void AddDirectoryEntry(fileapi::AsyncFileUtil::EntryList* entry_list,
19 const std::string& name,
20 fileapi::DirectoryEntry::DirectoryEntryType type,
21 int64 size,
22 std::string last_modified_time_string) {
23 base::Time last_modified_time;
24 const bool result = base::Time::FromString(last_modified_time_string.c_str(),
25 &last_modified_time);
26 DCHECK(result);
27 entry_list->push_back(
28 fileapi::DirectoryEntry(name, type, size, last_modified_time));
29 }
30
31 } // namespace
13 32
14 FakeProvidedFileSystem::FakeProvidedFileSystem( 33 FakeProvidedFileSystem::FakeProvidedFileSystem(
15 const ProvidedFileSystemInfo& file_system_info) 34 const ProvidedFileSystemInfo& file_system_info)
16 : file_system_info_(file_system_info) { 35 : file_system_info_(file_system_info) {
17 } 36 }
18 37
19 FakeProvidedFileSystem::~FakeProvidedFileSystem() {} 38 FakeProvidedFileSystem::~FakeProvidedFileSystem() {}
20 39
21 void FakeProvidedFileSystem::RequestUnmount( 40 void FakeProvidedFileSystem::RequestUnmount(
22 const fileapi::AsyncFileUtil::StatusCallback& callback) { 41 const fileapi::AsyncFileUtil::StatusCallback& callback) {
(...skipping 20 matching lines...) Expand all
43 base::Time last_modified_time; 62 base::Time last_modified_time;
44 const bool result = base::Time::FromString("Thu Apr 24 00:46:52 UTC 2014", 63 const bool result = base::Time::FromString("Thu Apr 24 00:46:52 UTC 2014",
45 &last_modified_time); 64 &last_modified_time);
46 DCHECK(result); 65 DCHECK(result);
47 file_info.last_modified = last_modified_time; 66 file_info.last_modified = last_modified_time;
48 67
49 base::MessageLoopProxy::current()->PostTask( 68 base::MessageLoopProxy::current()->PostTask(
50 FROM_HERE, base::Bind(callback, base::File::FILE_OK, file_info)); 69 FROM_HERE, base::Bind(callback, base::File::FILE_OK, file_info));
51 } 70 }
52 71
72 void FakeProvidedFileSystem::ReadDirectory(
73 const base::FilePath& directory_path,
74 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) {
75 // Return fake contents for the root directory only.
76 if (directory_path.AsUTF8Unsafe() != "/") {
77 base::MessageLoopProxy::current()->PostTask(
78 FROM_HERE,
79 base::Bind(callback,
80 base::File::FILE_ERROR_NOT_FOUND,
81 fileapi::AsyncFileUtil::EntryList(),
82 false /* has_more */));
83 return;
84 }
85
86 {
87 fileapi::AsyncFileUtil::EntryList entry_list;
88 AddDirectoryEntry(&entry_list,
89 "hello.txt",
90 fileapi::DirectoryEntry::FILE,
91 1024 /* size */,
92 "Thu Apr 24 00:46:52 UTC 2014");
93
94 AddDirectoryEntry(&entry_list,
95 "world.txt",
96 fileapi::DirectoryEntry::FILE,
97 1024 /* size */,
98 "Wed Apr 23 00:20:30 UTC 2014");
99
100 base::MessageLoopProxy::current()->PostTask(
101 FROM_HERE,
102 base::Bind(
103 callback, base::File::FILE_OK, entry_list, true /* has_more */));
104 }
105
106 {
107 fileapi::AsyncFileUtil::EntryList entry_list;
108 AddDirectoryEntry(&entry_list,
109 "pictures",
110 fileapi::DirectoryEntry::DIRECTORY,
111 0 /* size */,
112 "Tue May 22 00:40:50 UTC 2014");
113
114 base::MessageLoopProxy::current()->PostTask(
115 FROM_HERE,
116 base::Bind(
117 callback, base::File::FILE_OK, entry_list, false /* has_more */));
118 }
119 }
120
53 const ProvidedFileSystemInfo& FakeProvidedFileSystem::GetFileSystemInfo() 121 const ProvidedFileSystemInfo& FakeProvidedFileSystem::GetFileSystemInfo()
54 const { 122 const {
55 return file_system_info_; 123 return file_system_info_;
56 } 124 }
57 125
58 RequestManager* FakeProvidedFileSystem::GetRequestManager() { 126 RequestManager* FakeProvidedFileSystem::GetRequestManager() {
59 NOTREACHED(); 127 NOTREACHED();
60 return NULL; 128 return NULL;
61 } 129 }
62 130
63 ProvidedFileSystemInterface* FakeProvidedFileSystem::Create( 131 ProvidedFileSystemInterface* FakeProvidedFileSystem::Create(
64 extensions::EventRouter* event_router, 132 extensions::EventRouter* event_router,
65 const ProvidedFileSystemInfo& file_system_info) { 133 const ProvidedFileSystemInfo& file_system_info) {
66 return new FakeProvidedFileSystem(file_system_info); 134 return new FakeProvidedFileSystem(file_system_info);
67 } 135 }
68 136
69 } // namespace file_system_provider 137 } // namespace file_system_provider
70 } // namespace chromeos 138 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698