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

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

Issue 440653003: [fsp] Add support for aborting running operations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed DCHECKs. Created 6 years, 4 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 #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 11
12 #include "base/callback.h"
11 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/task/cancelable_task_tracker.h"
12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h" 15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h"
13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h" 16 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h"
14 17
15 class Profile; 18 class Profile;
16 19
17 namespace base { 20 namespace base {
18 class Time; 21 class Time;
19 } // namespace base 22 } // namespace base
20 23
21 namespace net { 24 namespace net {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 base::Time modification_time, 63 base::Time modification_time,
61 std::string mime_type, 64 std::string mime_type,
62 std::string contents); 65 std::string contents);
63 66
64 // Fetches a pointer to a fake entry registered in the fake file system. If 67 // Fetches a pointer to a fake entry registered in the fake file system. If
65 // found, then the result is written to |fake_entry| and true is returned. 68 // found, then the result is written to |fake_entry| and true is returned.
66 // Otherwise, false is returned. |fake_entry| must not be NULL. 69 // Otherwise, false is returned. |fake_entry| must not be NULL.
67 bool GetEntry(const base::FilePath& entry_path, FakeEntry* fake_entry) const; 70 bool GetEntry(const base::FilePath& entry_path, FakeEntry* fake_entry) const;
68 71
69 // ProvidedFileSystemInterface overrides. 72 // ProvidedFileSystemInterface overrides.
70 virtual void RequestUnmount( 73 virtual AbortCallback RequestUnmount(
71 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE; 74 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
72 virtual void GetMetadata( 75 virtual AbortCallback GetMetadata(
73 const base::FilePath& entry_path, 76 const base::FilePath& entry_path,
74 const ProvidedFileSystemInterface::GetMetadataCallback& callback) 77 const ProvidedFileSystemInterface::GetMetadataCallback& callback)
75 OVERRIDE; 78 OVERRIDE;
76 virtual void ReadDirectory( 79 virtual AbortCallback ReadDirectory(
77 const base::FilePath& directory_path, 80 const base::FilePath& directory_path,
78 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) OVERRIDE; 81 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) OVERRIDE;
79 virtual void OpenFile(const base::FilePath& file_path, 82 virtual AbortCallback OpenFile(const base::FilePath& file_path,
80 OpenFileMode mode, 83 OpenFileMode mode,
81 const OpenFileCallback& callback) OVERRIDE; 84 const OpenFileCallback& callback) OVERRIDE;
82 virtual void CloseFile( 85 virtual AbortCallback CloseFile(
83 int file_handle, 86 int file_handle,
84 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE; 87 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
85 virtual void ReadFile(int file_handle, 88 virtual AbortCallback ReadFile(
86 net::IOBuffer* buffer, 89 int file_handle,
87 int64 offset, 90 net::IOBuffer* buffer,
88 int length, 91 int64 offset,
89 const ReadChunkReceivedCallback& callback) OVERRIDE; 92 int length,
90 virtual void CreateDirectory( 93 const ReadChunkReceivedCallback& callback) OVERRIDE;
94 virtual AbortCallback CreateDirectory(
91 const base::FilePath& directory_path, 95 const base::FilePath& directory_path,
92 bool exclusive, 96 bool exclusive,
93 bool recursive, 97 bool recursive,
94 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE; 98 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
95 virtual void DeleteEntry( 99 virtual AbortCallback DeleteEntry(
96 const base::FilePath& entry_path, 100 const base::FilePath& entry_path,
97 bool recursive, 101 bool recursive,
98 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE; 102 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
99 virtual void CreateFile( 103 virtual AbortCallback CreateFile(
100 const base::FilePath& file_path, 104 const base::FilePath& file_path,
101 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE; 105 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
102 virtual void CopyEntry( 106 virtual AbortCallback CopyEntry(
103 const base::FilePath& source_path, 107 const base::FilePath& source_path,
104 const base::FilePath& target_path, 108 const base::FilePath& target_path,
105 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE; 109 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
106 virtual void MoveEntry( 110 virtual AbortCallback MoveEntry(
107 const base::FilePath& source_path, 111 const base::FilePath& source_path,
108 const base::FilePath& target_path, 112 const base::FilePath& target_path,
109 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE; 113 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
110 virtual void Truncate( 114 virtual AbortCallback Truncate(
111 const base::FilePath& file_path, 115 const base::FilePath& file_path,
112 int64 length, 116 int64 length,
113 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE; 117 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
114 virtual void WriteFile( 118 virtual AbortCallback WriteFile(
115 int file_handle, 119 int file_handle,
116 net::IOBuffer* buffer, 120 net::IOBuffer* buffer,
117 int64 offset, 121 int64 offset,
118 int length, 122 int length,
119 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE; 123 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
120 virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const OVERRIDE; 124 virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const OVERRIDE;
121 virtual RequestManager* GetRequestManager() OVERRIDE; 125 virtual RequestManager* GetRequestManager() OVERRIDE;
122 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() OVERRIDE; 126 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() OVERRIDE;
123 127
124 // Factory callback, to be used in Service::SetFileSystemFactory(). The 128 // Factory callback, to be used in Service::SetFileSystemFactory(). The
125 // |event_router| argument can be NULL. 129 // |event_router| argument can be NULL.
126 static ProvidedFileSystemInterface* Create( 130 static ProvidedFileSystemInterface* Create(
127 Profile* profile, 131 Profile* profile,
128 const ProvidedFileSystemInfo& file_system_info); 132 const ProvidedFileSystemInfo& file_system_info);
129 133
130 private: 134 private:
131 typedef std::map<base::FilePath, FakeEntry> Entries; 135 typedef std::map<base::FilePath, FakeEntry> Entries;
132 typedef std::map<int, base::FilePath> OpenedFilesMap; 136 typedef std::map<int, base::FilePath> OpenedFilesMap;
133 137
138 // Utility function for posting a task which can be aborted by calling the
139 // returned callback.
140 AbortCallback PostAbortableTask(const base::Closure& callback);
141
142 // Aborts a request. |task_id| refers to a posted callback returning a
143 // response for the operation, which will be cancelled, hence not called.
144 void Abort(int task_id,
145 const fileapi::AsyncFileUtil::StatusCallback& callback);
146
147 // Aborts a request. |task_ids| refers to a vector of posted callbacks
148 // returning a response for the operation, which will be cancelled, hence not
149 // called.
150 void AbortMany(const std::vector<int>& task_ids,
151 const fileapi::AsyncFileUtil::StatusCallback& callback);
152
134 ProvidedFileSystemInfo file_system_info_; 153 ProvidedFileSystemInfo file_system_info_;
135 Entries entries_; 154 Entries entries_;
136 OpenedFilesMap opened_files_; 155 OpenedFilesMap opened_files_;
137 int last_file_handle_; 156 int last_file_handle_;
157 base::CancelableTaskTracker tracker_;
138 158
139 base::WeakPtrFactory<ProvidedFileSystemInterface> weak_ptr_factory_; 159 base::WeakPtrFactory<FakeProvidedFileSystem> weak_ptr_factory_;
140 DISALLOW_COPY_AND_ASSIGN(FakeProvidedFileSystem); 160 DISALLOW_COPY_AND_ASSIGN(FakeProvidedFileSystem);
141 }; 161 };
142 162
143 } // namespace file_system_provider 163 } // namespace file_system_provider
144 } // namespace chromeos 164 } // namespace chromeos
145 165
146 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FAKE_PROVIDED_FILE_SYSTE M_H_ 166 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FAKE_PROVIDED_FILE_SYSTE M_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698