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

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

Issue 393233002: [fsp] Refactor FakeProvidedFileSystem to be more flexible. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/file_system_provider/fake_provided_file_system.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FAKE_PROVIDED_FILE_SYSTEM_H _ 5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FAKE_PROVIDED_FILE_SYSTEM_H _
6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FAKE_PROVIDED_FILE_SYSTEM_H _ 6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FAKE_PROVIDED_FILE_SYSTEM_H _
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h" 11 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h"
12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h" 12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h"
13 13
14 class Profile; 14 class Profile;
15 15
16 namespace base {
17 class Time;
18 } // namespace base
19
16 namespace net { 20 namespace net {
17 class IOBuffer; 21 class IOBuffer;
18 } // namespace net 22 } // namespace net
19 23
20 namespace chromeos { 24 namespace chromeos {
21 namespace file_system_provider { 25 namespace file_system_provider {
22 26
23 class RequestManager; 27 class RequestManager;
24 28
25 extern const char kFakeFileName[]; 29 // Path of a sample fake file, which is added to the fake file system by
30 // default.
26 extern const char kFakeFilePath[]; 31 extern const char kFakeFilePath[];
27 extern const char kFakeFileText[]; 32
28 extern const size_t kFakeFileSize; 33 // Represents a file or a directory on a fake file system.
29 extern const char kFakeFileModificationTime[]; 34 struct FakeEntry {
35 FakeEntry() {}
36
37 FakeEntry(EntryMetadata& metadata, const std::string& contents)
38 : metadata(metadata), contents(contents) {}
39
40 virtual ~FakeEntry() {}
41
42 EntryMetadata metadata;
43 std::string contents;
44 };
30 45
31 // Fake provided file system implementation. Does not communicate with target 46 // Fake provided file system implementation. Does not communicate with target
32 // extensions. Used for unit tests. 47 // extensions. Used for unit tests.
33 class FakeProvidedFileSystem : public ProvidedFileSystemInterface { 48 class FakeProvidedFileSystem : public ProvidedFileSystemInterface {
34 public: 49 public:
35 explicit FakeProvidedFileSystem( 50 explicit FakeProvidedFileSystem(
36 const ProvidedFileSystemInfo& file_system_info); 51 const ProvidedFileSystemInfo& file_system_info);
37 virtual ~FakeProvidedFileSystem(); 52 virtual ~FakeProvidedFileSystem();
38 53
54 // Adds a fake entry to the fake file system.
55 void AddEntry(const base::FilePath& entry_path,
56 bool is_directory,
57 const std::string& name,
58 int64 size,
59 base::Time modification_time,
60 std::string mime_type,
61 std::string contents);
62
63 // Fetches a pointer to a fake entry registered in the fake file system. If
64 // found, then the result is written to |fake_entry| and true is returned.
65 // Otherwise, false is returned. |fake_entry| must not be NULL.
66 bool GetEntry(const base::FilePath& entry_path, FakeEntry* fake_entry) const;
67
39 // ProvidedFileSystemInterface overrides. 68 // ProvidedFileSystemInterface overrides.
40 virtual void RequestUnmount( 69 virtual void RequestUnmount(
41 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE; 70 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
42 virtual void GetMetadata( 71 virtual void GetMetadata(
43 const base::FilePath& entry_path, 72 const base::FilePath& entry_path,
44 const ProvidedFileSystemInterface::GetMetadataCallback& callback) 73 const ProvidedFileSystemInterface::GetMetadataCallback& callback)
45 OVERRIDE; 74 OVERRIDE;
46 virtual void ReadDirectory( 75 virtual void ReadDirectory(
47 const base::FilePath& directory_path, 76 const base::FilePath& directory_path,
48 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) OVERRIDE; 77 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) OVERRIDE;
(...skipping 21 matching lines...) Expand all
70 virtual RequestManager* GetRequestManager() OVERRIDE; 99 virtual RequestManager* GetRequestManager() OVERRIDE;
71 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() OVERRIDE; 100 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() OVERRIDE;
72 101
73 // Factory callback, to be used in Service::SetFileSystemFactory(). The 102 // Factory callback, to be used in Service::SetFileSystemFactory(). The
74 // |event_router| argument can be NULL. 103 // |event_router| argument can be NULL.
75 static ProvidedFileSystemInterface* Create( 104 static ProvidedFileSystemInterface* Create(
76 Profile* profile, 105 Profile* profile,
77 const ProvidedFileSystemInfo& file_system_info); 106 const ProvidedFileSystemInfo& file_system_info);
78 107
79 private: 108 private:
109 typedef std::map<base::FilePath, FakeEntry> Entries;
80 typedef std::map<int, base::FilePath> OpenedFilesMap; 110 typedef std::map<int, base::FilePath> OpenedFilesMap;
81 111
82 ProvidedFileSystemInfo file_system_info_; 112 ProvidedFileSystemInfo file_system_info_;
113 Entries entries_;
83 OpenedFilesMap opened_files_; 114 OpenedFilesMap opened_files_;
84 int last_file_handle_; 115 int last_file_handle_;
85 116
86 base::WeakPtrFactory<ProvidedFileSystemInterface> weak_ptr_factory_; 117 base::WeakPtrFactory<ProvidedFileSystemInterface> weak_ptr_factory_;
87 DISALLOW_COPY_AND_ASSIGN(FakeProvidedFileSystem); 118 DISALLOW_COPY_AND_ASSIGN(FakeProvidedFileSystem);
88 }; 119 };
89 120
90 } // namespace file_system_provider 121 } // namespace file_system_provider
91 } // namespace chromeos 122 } // namespace chromeos
92 123
93 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FAKE_PROVIDED_FILE_SYSTE M_H_ 124 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FAKE_PROVIDED_FILE_SYSTE M_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/file_system_provider/fake_provided_file_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698