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

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

Issue 513683002: [fsp] Add support for providing thumbnails. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use scoped_ptr for EntryMetadata. Created 6 years, 3 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
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 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/memory/linked_ptr.h"
13 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
14 #include "base/task/cancelable_task_tracker.h" 15 #include "base/task/cancelable_task_tracker.h"
15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h" 16 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h"
16 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h" 17 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h"
17 18
18 class Profile; 19 class Profile;
19 20
20 namespace base { 21 namespace base {
21 class Time; 22 class Time;
22 } // namespace base 23 } // namespace base
23 24
24 namespace net { 25 namespace net {
25 class IOBuffer; 26 class IOBuffer;
26 } // namespace net 27 } // namespace net
27 28
28 namespace chromeos { 29 namespace chromeos {
29 namespace file_system_provider { 30 namespace file_system_provider {
30 31
31 class RequestManager; 32 class RequestManager;
32 33
33 // Path of a sample fake file, which is added to the fake file system by 34 // Path of a sample fake file, which is added to the fake file system by
34 // default. 35 // default.
35 extern const char kFakeFilePath[]; 36 extern const char kFakeFilePath[];
36 37
37 // Represents a file or a directory on a fake file system. 38 // Represents a file or a directory on a fake file system.
38 struct FakeEntry { 39 struct FakeEntry {
39 FakeEntry() {} 40 FakeEntry();
41 FakeEntry(scoped_ptr<EntryMetadata> metadata, const std::string& contents);
42 ~FakeEntry();
40 43
41 FakeEntry(const EntryMetadata& metadata, const std::string& contents) 44 scoped_ptr<EntryMetadata> metadata;
42 : metadata(metadata), contents(contents) {} 45 std::string contents;
43 46
44 virtual ~FakeEntry() {} 47 private:
45 48 DISALLOW_COPY_AND_ASSIGN(FakeEntry);
46 EntryMetadata metadata;
47 std::string contents;
48 }; 49 };
49 50
50 // Fake provided file system implementation. Does not communicate with target 51 // Fake provided file system implementation. Does not communicate with target
51 // extensions. Used for unit tests. 52 // extensions. Used for unit tests.
52 class FakeProvidedFileSystem : public ProvidedFileSystemInterface { 53 class FakeProvidedFileSystem : public ProvidedFileSystemInterface {
53 public: 54 public:
54 explicit FakeProvidedFileSystem( 55 explicit FakeProvidedFileSystem(
55 const ProvidedFileSystemInfo& file_system_info); 56 const ProvidedFileSystemInfo& file_system_info);
56 virtual ~FakeProvidedFileSystem(); 57 virtual ~FakeProvidedFileSystem();
57 58
58 // Adds a fake entry to the fake file system. 59 // Adds a fake entry to the fake file system.
59 void AddEntry(const base::FilePath& entry_path, 60 void AddEntry(const base::FilePath& entry_path,
60 bool is_directory, 61 bool is_directory,
61 const std::string& name, 62 const std::string& name,
62 int64 size, 63 int64 size,
63 base::Time modification_time, 64 base::Time modification_time,
64 std::string mime_type, 65 std::string mime_type,
65 std::string contents); 66 std::string contents);
66 67
67 // Fetches a pointer to a fake entry registered in the fake file system. If 68 // Fetches a pointer to a fake entry registered in the fake file system. If
68 // found, then the result is written to |fake_entry| and true is returned. 69 // not found, then returns NULL. The returned pointes is owned by
69 // Otherwise, false is returned. |fake_entry| must not be NULL. 70 // FakeProvidedFileSystem.
70 bool GetEntry(const base::FilePath& entry_path, FakeEntry* fake_entry) const; 71 const FakeEntry* GetEntry(const base::FilePath& entry_path) const;
71 72
72 // ProvidedFileSystemInterface overrides. 73 // ProvidedFileSystemInterface overrides.
73 virtual AbortCallback RequestUnmount( 74 virtual AbortCallback RequestUnmount(
74 const storage::AsyncFileUtil::StatusCallback& callback) OVERRIDE; 75 const storage::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
75 virtual AbortCallback GetMetadata( 76 virtual AbortCallback GetMetadata(
76 const base::FilePath& entry_path, 77 const base::FilePath& entry_path,
78 ProvidedFileSystemInterface::MetadataFieldMask fields,
77 const ProvidedFileSystemInterface::GetMetadataCallback& callback) 79 const ProvidedFileSystemInterface::GetMetadataCallback& callback)
78 OVERRIDE; 80 OVERRIDE;
79 virtual AbortCallback ReadDirectory( 81 virtual AbortCallback ReadDirectory(
80 const base::FilePath& directory_path, 82 const base::FilePath& directory_path,
81 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) OVERRIDE; 83 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) OVERRIDE;
82 virtual AbortCallback OpenFile(const base::FilePath& file_path, 84 virtual AbortCallback OpenFile(const base::FilePath& file_path,
83 OpenFileMode mode, 85 OpenFileMode mode,
84 const OpenFileCallback& callback) OVERRIDE; 86 const OpenFileCallback& callback) OVERRIDE;
85 virtual AbortCallback CloseFile( 87 virtual AbortCallback CloseFile(
86 int file_handle, 88 int file_handle,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 virtual RequestManager* GetRequestManager() OVERRIDE; 127 virtual RequestManager* GetRequestManager() OVERRIDE;
126 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() OVERRIDE; 128 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() OVERRIDE;
127 129
128 // Factory callback, to be used in Service::SetFileSystemFactory(). The 130 // Factory callback, to be used in Service::SetFileSystemFactory(). The
129 // |event_router| argument can be NULL. 131 // |event_router| argument can be NULL.
130 static ProvidedFileSystemInterface* Create( 132 static ProvidedFileSystemInterface* Create(
131 Profile* profile, 133 Profile* profile,
132 const ProvidedFileSystemInfo& file_system_info); 134 const ProvidedFileSystemInfo& file_system_info);
133 135
134 private: 136 private:
135 typedef std::map<base::FilePath, FakeEntry> Entries; 137 typedef std::map<base::FilePath, linked_ptr<FakeEntry> > Entries;
136 typedef std::map<int, base::FilePath> OpenedFilesMap; 138 typedef std::map<int, base::FilePath> OpenedFilesMap;
137 139
138 // Utility function for posting a task which can be aborted by calling the 140 // Utility function for posting a task which can be aborted by calling the
139 // returned callback. 141 // returned callback.
140 AbortCallback PostAbortableTask(const base::Closure& callback); 142 AbortCallback PostAbortableTask(const base::Closure& callback);
141 143
142 // Aborts a request. |task_id| refers to a posted callback returning a 144 // Aborts a request. |task_id| refers to a posted callback returning a
143 // response for the operation, which will be cancelled, hence not called. 145 // response for the operation, which will be cancelled, hence not called.
144 void Abort(int task_id, 146 void Abort(int task_id,
145 const storage::AsyncFileUtil::StatusCallback& callback); 147 const storage::AsyncFileUtil::StatusCallback& callback);
(...skipping 11 matching lines...) Expand all
157 base::CancelableTaskTracker tracker_; 159 base::CancelableTaskTracker tracker_;
158 160
159 base::WeakPtrFactory<FakeProvidedFileSystem> weak_ptr_factory_; 161 base::WeakPtrFactory<FakeProvidedFileSystem> weak_ptr_factory_;
160 DISALLOW_COPY_AND_ASSIGN(FakeProvidedFileSystem); 162 DISALLOW_COPY_AND_ASSIGN(FakeProvidedFileSystem);
161 }; 163 };
162 164
163 } // namespace file_system_provider 165 } // namespace file_system_provider
164 } // namespace chromeos 166 } // namespace chromeos
165 167
166 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FAKE_PROVIDED_FILE_SYSTE M_H_ 168 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FAKE_PROVIDED_FILE_SYSTE M_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698