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

Side by Side Diff: chrome/browser/chromeos/drive/fake_file_system.cc

Issue 14755002: drive: Drop "Drive" from FakeDriveFileSystem and MockDriveFileSystem (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: some more cleanup Created 7 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/drive/fake_drive_file_system.h" 5 #include "chrome/browser/chromeos/drive/fake_file_system.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "chrome/browser/chromeos/drive/drive.pb.h" 13 #include "chrome/browser/chromeos/drive/drive.pb.h"
14 #include "chrome/browser/chromeos/drive/file_errors.h" 14 #include "chrome/browser/chromeos/drive/file_errors.h"
15 #include "chrome/browser/chromeos/drive/file_system_util.h" 15 #include "chrome/browser/chromeos/drive/file_system_util.h"
16 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" 16 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h"
17 #include "chrome/browser/google_apis/drive_api_parser.h" 17 #include "chrome/browser/google_apis/drive_api_parser.h"
18 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 18 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 20
21 namespace drive { 21 namespace drive {
22 namespace test_util { 22 namespace test_util {
23 23
24 using content::BrowserThread; 24 using content::BrowserThread;
25 25
26 FakeDriveFileSystem::FakeDriveFileSystem( 26 FakeFileSystem::FakeFileSystem(
27 google_apis::DriveServiceInterface* drive_service) 27 google_apis::DriveServiceInterface* drive_service)
28 : drive_service_(drive_service), 28 : drive_service_(drive_service),
29 weak_ptr_factory_(this) { 29 weak_ptr_factory_(this) {
30 } 30 }
31 31
32 FakeDriveFileSystem::~FakeDriveFileSystem() { 32 FakeFileSystem::~FakeFileSystem() {
33 } 33 }
34 34
35 bool FakeDriveFileSystem::InitializeForTesting() { 35 bool FakeFileSystem::InitializeForTesting() {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
37 return cache_dir_.CreateUniqueTempDir(); 37 return cache_dir_.CreateUniqueTempDir();
38 } 38 }
39 39
40 void FakeDriveFileSystem::Initialize() { 40 void FakeFileSystem::Initialize() {
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
42 InitializeForTesting(); 42 InitializeForTesting();
43 } 43 }
44 44
45 void FakeDriveFileSystem::AddObserver(FileSystemObserver* observer) { 45 void FakeFileSystem::AddObserver(FileSystemObserver* observer) {
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
47 } 47 }
48 48
49 void FakeDriveFileSystem::RemoveObserver(FileSystemObserver* observer) { 49 void FakeFileSystem::RemoveObserver(FileSystemObserver* observer) {
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
51 } 51 }
52 52
53 void FakeDriveFileSystem::CheckForUpdates() { 53 void FakeFileSystem::CheckForUpdates() {
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
55 } 55 }
56 56
57 void FakeDriveFileSystem::GetEntryInfoByResourceId( 57 void FakeFileSystem::GetEntryInfoByResourceId(
58 const std::string& resource_id, 58 const std::string& resource_id,
59 const GetEntryInfoWithFilePathCallback& callback) { 59 const GetEntryInfoWithFilePathCallback& callback) {
60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
61 61
62 drive_service_->GetResourceEntry( 62 drive_service_->GetResourceEntry(
63 resource_id, 63 resource_id,
64 base::Bind( 64 base::Bind(
65 &FakeDriveFileSystem::GetEntryInfoByResourceIdAfterGetResourceEntry, 65 &FakeFileSystem::GetEntryInfoByResourceIdAfterGetResourceEntry,
66 weak_ptr_factory_.GetWeakPtr(), callback)); 66 weak_ptr_factory_.GetWeakPtr(), callback));
67 } 67 }
68 68
69 void FakeDriveFileSystem::TransferFileFromRemoteToLocal( 69 void FakeFileSystem::TransferFileFromRemoteToLocal(
70 const base::FilePath& remote_src_file_path, 70 const base::FilePath& remote_src_file_path,
71 const base::FilePath& local_dest_file_path, 71 const base::FilePath& local_dest_file_path,
72 const FileOperationCallback& callback) { 72 const FileOperationCallback& callback) {
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
74 } 74 }
75 75
76 void FakeDriveFileSystem::TransferFileFromLocalToRemote( 76 void FakeFileSystem::TransferFileFromLocalToRemote(
77 const base::FilePath& local_src_file_path, 77 const base::FilePath& local_src_file_path,
78 const base::FilePath& remote_dest_file_path, 78 const base::FilePath& remote_dest_file_path,
79 const FileOperationCallback& callback) { 79 const FileOperationCallback& callback) {
80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
81 } 81 }
82 82
83 void FakeDriveFileSystem::OpenFile(const base::FilePath& file_path, 83 void FakeFileSystem::OpenFile(const base::FilePath& file_path,
84 const OpenFileCallback& callback) { 84 const OpenFileCallback& callback) {
85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
86 } 86 }
87 87
88 void FakeDriveFileSystem::CloseFile(const base::FilePath& file_path, 88 void FakeFileSystem::CloseFile(const base::FilePath& file_path,
89 const FileOperationCallback& callback) {
90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
91 }
92
93 void FakeDriveFileSystem::Copy(const base::FilePath& src_file_path,
94 const base::FilePath& dest_file_path,
95 const FileOperationCallback& callback) { 89 const FileOperationCallback& callback) {
96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
97 } 91 }
98 92
99 void FakeDriveFileSystem::Move(const base::FilePath& src_file_path, 93 void FakeFileSystem::Copy(const base::FilePath& src_file_path,
100 const base::FilePath& dest_file_path, 94 const base::FilePath& dest_file_path,
101 const FileOperationCallback& callback) { 95 const FileOperationCallback& callback) {
102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
103 } 97 }
104 98
105 void FakeDriveFileSystem::Remove(const base::FilePath& file_path, 99 void FakeFileSystem::Move(const base::FilePath& src_file_path,
106 bool is_recursive, 100 const base::FilePath& dest_file_path,
107 const FileOperationCallback& callback) { 101 const FileOperationCallback& callback) {
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
109 } 103 }
110 104
111 void FakeDriveFileSystem::CreateDirectory( 105 void FakeFileSystem::Remove(const base::FilePath& file_path,
106 bool is_recursive,
107 const FileOperationCallback& callback) {
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
109 }
110
111 void FakeFileSystem::CreateDirectory(
112 const base::FilePath& directory_path, 112 const base::FilePath& directory_path,
113 bool is_exclusive, 113 bool is_exclusive,
114 bool is_recursive, 114 bool is_recursive,
115 const FileOperationCallback& callback) { 115 const FileOperationCallback& callback) {
116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
117 } 117 }
118 118
119 void FakeDriveFileSystem::CreateFile(const base::FilePath& file_path, 119 void FakeFileSystem::CreateFile(const base::FilePath& file_path,
120 bool is_exclusive, 120 bool is_exclusive,
121 const FileOperationCallback& callback) {
122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
123 }
124
125 void FakeDriveFileSystem::Pin(const base::FilePath& file_path,
126 const FileOperationCallback& callback) {
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
128 }
129
130 void FakeDriveFileSystem::Unpin(const base::FilePath& file_path,
131 const FileOperationCallback& callback) { 121 const FileOperationCallback& callback) {
132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
133 } 123 }
134 124
135 void FakeDriveFileSystem::GetFileByPath(const base::FilePath& file_path, 125 void FakeFileSystem::Pin(const base::FilePath& file_path,
136 const GetFileCallback& callback) { 126 const FileOperationCallback& callback) {
137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
138 } 128 }
139 129
140 void FakeDriveFileSystem::GetFileByResourceId( 130 void FakeFileSystem::Unpin(const base::FilePath& file_path,
131 const FileOperationCallback& callback) {
132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
133 }
134
135 void FakeFileSystem::GetFileByPath(const base::FilePath& file_path,
136 const GetFileCallback& callback) {
137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
138 }
139
140 void FakeFileSystem::GetFileByResourceId(
141 const std::string& resource_id, 141 const std::string& resource_id,
142 const DriveClientContext& context, 142 const DriveClientContext& context,
143 const GetFileCallback& get_file_callback, 143 const GetFileCallback& get_file_callback,
144 const google_apis::GetContentCallback& get_content_callback) { 144 const google_apis::GetContentCallback& get_content_callback) {
145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
146 } 146 }
147 147
148 void FakeDriveFileSystem::GetFileContentByPath( 148 void FakeFileSystem::GetFileContentByPath(
149 const base::FilePath& file_path, 149 const base::FilePath& file_path,
150 const GetFileContentInitializedCallback& initialized_callback, 150 const GetFileContentInitializedCallback& initialized_callback,
151 const google_apis::GetContentCallback& get_content_callback, 151 const google_apis::GetContentCallback& get_content_callback,
152 const FileOperationCallback& completion_callback) { 152 const FileOperationCallback& completion_callback) {
153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
154 154
155 GetEntryInfoByPath( 155 GetEntryInfoByPath(
156 file_path, 156 file_path,
157 base::Bind(&FakeDriveFileSystem::GetFileContentByPathAfterGetEntryInfo, 157 base::Bind(&FakeFileSystem::GetFileContentByPathAfterGetEntryInfo,
158 weak_ptr_factory_.GetWeakPtr(), 158 weak_ptr_factory_.GetWeakPtr(),
159 file_path, initialized_callback, get_content_callback, 159 file_path, initialized_callback, get_content_callback,
160 completion_callback)); 160 completion_callback));
161 } 161 }
162 162
163 void FakeDriveFileSystem::UpdateFileByResourceId( 163 void FakeFileSystem::UpdateFileByResourceId(
164 const std::string& resource_id, 164 const std::string& resource_id,
165 const DriveClientContext& context, 165 const DriveClientContext& context,
166 const FileOperationCallback& callback) { 166 const FileOperationCallback& callback) {
167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
168 } 168 }
169 169
170 void FakeDriveFileSystem::GetEntryInfoByPath( 170 void FakeFileSystem::GetEntryInfoByPath(
171 const base::FilePath& file_path, 171 const base::FilePath& file_path,
172 const GetEntryInfoCallback& callback) { 172 const GetEntryInfoCallback& callback) {
173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
174 174
175 // Now, we only support files under my drive. 175 // Now, we only support files under my drive.
176 DCHECK(!util::IsUnderDriveMountPoint(file_path)); 176 DCHECK(!util::IsUnderDriveMountPoint(file_path));
177 177
178 if (file_path == util::GetDriveMyDriveRootPath()) { 178 if (file_path == util::GetDriveMyDriveRootPath()) {
179 // Specialized for the root entry. 179 // Specialized for the root entry.
180 drive_service_->GetAboutResource( 180 drive_service_->GetAboutResource(
181 base::Bind( 181 base::Bind(
182 &FakeDriveFileSystem::GetEntryInfoByPathAfterGetAboutResource, 182 &FakeFileSystem::GetEntryInfoByPathAfterGetAboutResource,
183 weak_ptr_factory_.GetWeakPtr(), callback)); 183 weak_ptr_factory_.GetWeakPtr(), callback));
184 return; 184 return;
185 } 185 }
186 186
187 GetEntryInfoByPath( 187 GetEntryInfoByPath(
188 file_path.DirName(), 188 file_path.DirName(),
189 base::Bind( 189 base::Bind(
190 &FakeDriveFileSystem::GetEntryInfoByPathAfterGetParentEntryInfo, 190 &FakeFileSystem::GetEntryInfoByPathAfterGetParentEntryInfo,
191 weak_ptr_factory_.GetWeakPtr(), file_path.BaseName(), callback)); 191 weak_ptr_factory_.GetWeakPtr(), file_path.BaseName(), callback));
192 } 192 }
193 193
194 void FakeDriveFileSystem::ReadDirectoryByPath( 194 void FakeFileSystem::ReadDirectoryByPath(
195 const base::FilePath& file_path, 195 const base::FilePath& file_path,
196 const ReadDirectoryWithSettingCallback& callback) { 196 const ReadDirectoryWithSettingCallback& callback) {
197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
198 } 198 }
199 199
200 void FakeDriveFileSystem::RefreshDirectory( 200 void FakeFileSystem::RefreshDirectory(
201 const base::FilePath& file_path, 201 const base::FilePath& file_path,
202 const FileOperationCallback& callback) { 202 const FileOperationCallback& callback) {
203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
204 } 204 }
205 205
206 void FakeDriveFileSystem::Search(const std::string& search_query, 206 void FakeFileSystem::Search(const std::string& search_query,
207 const GURL& next_feed, 207 const GURL& next_feed,
208 const SearchCallback& callback) { 208 const SearchCallback& callback) {
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
210 } 210 }
211 211
212 void FakeDriveFileSystem::SearchMetadata( 212 void FakeFileSystem::SearchMetadata(
213 const std::string& query, 213 const std::string& query,
214 int options, 214 int options,
215 int at_most_num_matches, 215 int at_most_num_matches,
216 const SearchMetadataCallback& callback) { 216 const SearchMetadataCallback& callback) {
217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
218 } 218 }
219 219
220 void FakeDriveFileSystem::GetAvailableSpace( 220 void FakeFileSystem::GetAvailableSpace(
221 const GetAvailableSpaceCallback& callback) { 221 const GetAvailableSpaceCallback& callback) {
222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
223 } 223 }
224 224
225 void FakeDriveFileSystem::AddUploadedFile( 225 void FakeFileSystem::AddUploadedFile(
226 scoped_ptr<google_apis::ResourceEntry> doc_entry, 226 scoped_ptr<google_apis::ResourceEntry> doc_entry,
227 const base::FilePath& file_content_path, 227 const base::FilePath& file_content_path,
228 const FileOperationCallback& callback) { 228 const FileOperationCallback& callback) {
229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
230 } 230 }
231 231
232 void FakeDriveFileSystem::GetMetadata( 232 void FakeFileSystem::GetMetadata(
233 const GetFilesystemMetadataCallback& callback) { 233 const GetFilesystemMetadataCallback& callback) {
234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
235 } 235 }
236 236
237 void FakeDriveFileSystem::MarkCacheFileAsMounted( 237 void FakeFileSystem::MarkCacheFileAsMounted(
238 const base::FilePath& drive_file_path, 238 const base::FilePath& drive_file_path,
239 const OpenFileCallback& callback) { 239 const OpenFileCallback& callback) {
240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
241 } 241 }
242 242
243 void FakeDriveFileSystem::MarkCacheFileAsUnmounted( 243 void FakeFileSystem::MarkCacheFileAsUnmounted(
244 const base::FilePath& cache_file_path, 244 const base::FilePath& cache_file_path,
245 const FileOperationCallback& callback) { 245 const FileOperationCallback& callback) {
246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
247 } 247 }
248 248
249 void FakeDriveFileSystem::GetCacheEntryByResourceId( 249 void FakeFileSystem::GetCacheEntryByResourceId(
250 const std::string& resource_id, 250 const std::string& resource_id,
251 const std::string& md5, 251 const std::string& md5,
252 const GetCacheEntryCallback& callback) { 252 const GetCacheEntryCallback& callback) {
253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
254 } 254 }
255 255
256 void FakeDriveFileSystem::IterateCache( 256 void FakeFileSystem::IterateCache(
257 const CacheIterateCallback& iteration_callback, 257 const CacheIterateCallback& iteration_callback,
258 const base::Closure& completion_callback) { 258 const base::Closure& completion_callback) {
259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
260 } 260 }
261 261
262 void FakeDriveFileSystem::Reload() { 262 void FakeFileSystem::Reload() {
263 } 263 }
264 264
265 // Implementation of GetFilePath. 265 // Implementation of GetFilePath.
266 void FakeDriveFileSystem::GetFilePath(const std::string& resource_id, 266 void FakeFileSystem::GetFilePath(const std::string& resource_id,
267 const GetFilePathCallback& callback) { 267 const GetFilePathCallback& callback) {
268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
269 269
270 drive_service_->GetAboutResource( 270 drive_service_->GetAboutResource(
271 base::Bind( 271 base::Bind(
272 &FakeDriveFileSystem::GetFilePathAfterGetAboutResource, 272 &FakeFileSystem::GetFilePathAfterGetAboutResource,
273 weak_ptr_factory_.GetWeakPtr(), resource_id, callback)); 273 weak_ptr_factory_.GetWeakPtr(), resource_id, callback));
274 } 274 }
275 275
276 void FakeDriveFileSystem::GetFilePathAfterGetAboutResource( 276 void FakeFileSystem::GetFilePathAfterGetAboutResource(
277 const std::string& resource_id, 277 const std::string& resource_id,
278 const GetFilePathCallback& callback, 278 const GetFilePathCallback& callback,
279 google_apis::GDataErrorCode error, 279 google_apis::GDataErrorCode error,
280 scoped_ptr<google_apis::AboutResource> about_resource) { 280 scoped_ptr<google_apis::AboutResource> about_resource) {
281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
282 282
283 // We assume the call always success for test. 283 // We assume the call always success for test.
284 DCHECK_EQ(util::GDataToFileError(error), FILE_ERROR_OK); 284 DCHECK_EQ(util::GDataToFileError(error), FILE_ERROR_OK);
285 DCHECK(about_resource); 285 DCHECK(about_resource);
286 286
287 GetFilePathInternal(about_resource->root_folder_id(), resource_id, 287 GetFilePathInternal(about_resource->root_folder_id(), resource_id,
288 base::FilePath(), callback); 288 base::FilePath(), callback);
289 } 289 }
290 290
291 void FakeDriveFileSystem::GetFilePathInternal( 291 void FakeFileSystem::GetFilePathInternal(
292 const std::string& root_resource_id, 292 const std::string& root_resource_id,
293 const std::string& resource_id, 293 const std::string& resource_id,
294 const base::FilePath& file_path, 294 const base::FilePath& file_path,
295 const GetFilePathCallback& callback) { 295 const GetFilePathCallback& callback) {
296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
297 297
298 if (resource_id == root_resource_id) { 298 if (resource_id == root_resource_id) {
299 // Reached to the root. Append the drive root path, and run |callback|. 299 // Reached to the root. Append the drive root path, and run |callback|.
300 callback.Run(util::GetDriveMyDriveRootPath().Append(file_path)); 300 callback.Run(util::GetDriveMyDriveRootPath().Append(file_path));
301 return; 301 return;
302 } 302 }
303 303
304 drive_service_->GetResourceEntry( 304 drive_service_->GetResourceEntry(
305 resource_id, 305 resource_id,
306 base::Bind( 306 base::Bind(
307 &FakeDriveFileSystem::GetFilePathAfterGetResourceEntry, 307 &FakeFileSystem::GetFilePathAfterGetResourceEntry,
308 weak_ptr_factory_.GetWeakPtr(), 308 weak_ptr_factory_.GetWeakPtr(),
309 root_resource_id, file_path, callback)); 309 root_resource_id, file_path, callback));
310 } 310 }
311 311
312 void FakeDriveFileSystem::GetFilePathAfterGetResourceEntry( 312 void FakeFileSystem::GetFilePathAfterGetResourceEntry(
313 const std::string& root_resource_id, 313 const std::string& root_resource_id,
314 const base::FilePath& remaining_file_path, 314 const base::FilePath& remaining_file_path,
315 const GetFilePathCallback& callback, 315 const GetFilePathCallback& callback,
316 google_apis::GDataErrorCode error_in, 316 google_apis::GDataErrorCode error_in,
317 scoped_ptr<google_apis::ResourceEntry> resource_entry) { 317 scoped_ptr<google_apis::ResourceEntry> resource_entry) {
318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
319 319
320 // We assume the call always success for test. 320 // We assume the call always success for test.
321 DCHECK_EQ(util::GDataToFileError(error_in), FILE_ERROR_OK); 321 DCHECK_EQ(util::GDataToFileError(error_in), FILE_ERROR_OK);
322 DCHECK(resource_entry); 322 DCHECK(resource_entry);
323 323
324 DriveEntryProto entry_proto = 324 DriveEntryProto entry_proto =
325 ConvertResourceEntryToDriveEntryProto(*resource_entry); 325 ConvertResourceEntryToDriveEntryProto(*resource_entry);
326 base::FilePath file_path = 326 base::FilePath file_path =
327 base::FilePath::FromUTF8Unsafe(entry_proto.base_name()).Append( 327 base::FilePath::FromUTF8Unsafe(entry_proto.base_name()).Append(
328 remaining_file_path); 328 remaining_file_path);
329 329
330 GetFilePathInternal(root_resource_id, entry_proto.parent_resource_id(), 330 GetFilePathInternal(root_resource_id, entry_proto.parent_resource_id(),
331 file_path, callback); 331 file_path, callback);
332 } 332 }
333 333
334 // Implementation of GetEntryInfoByResourceId. 334 // Implementation of GetEntryInfoByResourceId.
335 void FakeDriveFileSystem::GetEntryInfoByResourceIdAfterGetResourceEntry( 335 void FakeFileSystem::GetEntryInfoByResourceIdAfterGetResourceEntry(
336 const GetEntryInfoWithFilePathCallback& callback, 336 const GetEntryInfoWithFilePathCallback& callback,
337 google_apis::GDataErrorCode error_in, 337 google_apis::GDataErrorCode error_in,
338 scoped_ptr<google_apis::ResourceEntry> resource_entry) { 338 scoped_ptr<google_apis::ResourceEntry> resource_entry) {
339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
340 340
341 FileError error = util::GDataToFileError(error_in); 341 FileError error = util::GDataToFileError(error_in);
342 if (error != FILE_ERROR_OK) { 342 if (error != FILE_ERROR_OK) {
343 callback.Run(error, base::FilePath(), scoped_ptr<DriveEntryProto>()); 343 callback.Run(error, base::FilePath(), scoped_ptr<DriveEntryProto>());
344 return; 344 return;
345 } 345 }
346 346
347 DCHECK(resource_entry); 347 DCHECK(resource_entry);
348 scoped_ptr<DriveEntryProto> entry_proto(new DriveEntryProto( 348 scoped_ptr<DriveEntryProto> entry_proto(new DriveEntryProto(
349 ConvertResourceEntryToDriveEntryProto(*resource_entry))); 349 ConvertResourceEntryToDriveEntryProto(*resource_entry)));
350 350
351 const std::string parent_resource_id = entry_proto->parent_resource_id(); 351 const std::string parent_resource_id = entry_proto->parent_resource_id();
352 GetFilePath( 352 GetFilePath(
353 parent_resource_id, 353 parent_resource_id,
354 base::Bind( 354 base::Bind(
355 &FakeDriveFileSystem::GetEntryInfoByResourceIdAfterGetFilePath, 355 &FakeFileSystem::GetEntryInfoByResourceIdAfterGetFilePath,
356 weak_ptr_factory_.GetWeakPtr(), 356 weak_ptr_factory_.GetWeakPtr(),
357 callback, error, base::Passed(&entry_proto))); 357 callback, error, base::Passed(&entry_proto)));
358 } 358 }
359 359
360 void FakeDriveFileSystem::GetEntryInfoByResourceIdAfterGetFilePath( 360 void FakeFileSystem::GetEntryInfoByResourceIdAfterGetFilePath(
361 const GetEntryInfoWithFilePathCallback& callback, 361 const GetEntryInfoWithFilePathCallback& callback,
362 FileError error, 362 FileError error,
363 scoped_ptr<DriveEntryProto> entry_proto, 363 scoped_ptr<DriveEntryProto> entry_proto,
364 const base::FilePath& parent_file_path) { 364 const base::FilePath& parent_file_path) {
365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
366 base::FilePath file_path = parent_file_path.Append( 366 base::FilePath file_path = parent_file_path.Append(
367 base::FilePath::FromUTF8Unsafe(entry_proto->base_name())); 367 base::FilePath::FromUTF8Unsafe(entry_proto->base_name()));
368 callback.Run(error, file_path, entry_proto.Pass()); 368 callback.Run(error, file_path, entry_proto.Pass());
369 } 369 }
370 370
371 // Implementation of GetFileContentByPath. 371 // Implementation of GetFileContentByPath.
372 void FakeDriveFileSystem::GetFileContentByPathAfterGetEntryInfo( 372 void FakeFileSystem::GetFileContentByPathAfterGetEntryInfo(
373 const base::FilePath& file_path, 373 const base::FilePath& file_path,
374 const GetFileContentInitializedCallback& initialized_callback, 374 const GetFileContentInitializedCallback& initialized_callback,
375 const google_apis::GetContentCallback& get_content_callback, 375 const google_apis::GetContentCallback& get_content_callback,
376 const FileOperationCallback& completion_callback, 376 const FileOperationCallback& completion_callback,
377 FileError error, 377 FileError error,
378 scoped_ptr<DriveEntryProto> entry_proto) { 378 scoped_ptr<DriveEntryProto> entry_proto) {
379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
380 380
381 if (error != FILE_ERROR_OK) { 381 if (error != FILE_ERROR_OK) {
382 completion_callback.Run(error); 382 completion_callback.Run(error);
(...skipping 18 matching lines...) Expand all
401 } 401 }
402 402
403 // Copy the URL here before passing |entry_proto| to the callback. 403 // Copy the URL here before passing |entry_proto| to the callback.
404 const GURL download_url(entry_proto->download_url()); 404 const GURL download_url(entry_proto->download_url());
405 initialized_callback.Run(FILE_ERROR_OK, entry_proto.Pass(), base::FilePath(), 405 initialized_callback.Run(FILE_ERROR_OK, entry_proto.Pass(), base::FilePath(),
406 base::Bind(&base::DoNothing)); 406 base::Bind(&base::DoNothing));
407 drive_service_->DownloadFile( 407 drive_service_->DownloadFile(
408 file_path, 408 file_path,
409 cache_path, 409 cache_path,
410 download_url, 410 download_url,
411 base::Bind(&FakeDriveFileSystem::GetFileContentByPathAfterDownloadFile, 411 base::Bind(&FakeFileSystem::GetFileContentByPathAfterDownloadFile,
412 weak_ptr_factory_.GetWeakPtr(), 412 weak_ptr_factory_.GetWeakPtr(),
413 completion_callback), 413 completion_callback),
414 get_content_callback, 414 get_content_callback,
415 google_apis::ProgressCallback()); 415 google_apis::ProgressCallback());
416 } 416 }
417 417
418 void FakeDriveFileSystem::GetFileContentByPathAfterDownloadFile( 418 void FakeFileSystem::GetFileContentByPathAfterDownloadFile(
419 const FileOperationCallback& completion_callback, 419 const FileOperationCallback& completion_callback,
420 google_apis::GDataErrorCode gdata_error, 420 google_apis::GDataErrorCode gdata_error,
421 const base::FilePath& temp_file) { 421 const base::FilePath& temp_file) {
422 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 422 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
423 completion_callback.Run(util::GDataToFileError(gdata_error)); 423 completion_callback.Run(util::GDataToFileError(gdata_error));
424 } 424 }
425 425
426 // Implementation of GetEntryInfoByPath. 426 // Implementation of GetEntryInfoByPath.
427 void FakeDriveFileSystem::GetEntryInfoByPathAfterGetAboutResource( 427 void FakeFileSystem::GetEntryInfoByPathAfterGetAboutResource(
428 const GetEntryInfoCallback& callback, 428 const GetEntryInfoCallback& callback,
429 google_apis::GDataErrorCode gdata_error, 429 google_apis::GDataErrorCode gdata_error,
430 scoped_ptr<google_apis::AboutResource> about_resource) { 430 scoped_ptr<google_apis::AboutResource> about_resource) {
431 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 431 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
432 432
433 FileError error = util::GDataToFileError(gdata_error); 433 FileError error = util::GDataToFileError(gdata_error);
434 if (error != FILE_ERROR_OK) { 434 if (error != FILE_ERROR_OK) {
435 callback.Run(error, scoped_ptr<DriveEntryProto>()); 435 callback.Run(error, scoped_ptr<DriveEntryProto>());
436 return; 436 return;
437 } 437 }
438 438
439 DCHECK(about_resource); 439 DCHECK(about_resource);
440 scoped_ptr<DriveEntryProto> root(new DriveEntryProto); 440 scoped_ptr<DriveEntryProto> root(new DriveEntryProto);
441 root->mutable_file_info()->set_is_directory(true); 441 root->mutable_file_info()->set_is_directory(true);
442 root->set_resource_id(about_resource->root_folder_id()); 442 root->set_resource_id(about_resource->root_folder_id());
443 root->set_title(util::kDriveMyDriveRootDirName); 443 root->set_title(util::kDriveMyDriveRootDirName);
444 callback.Run(error, root.Pass()); 444 callback.Run(error, root.Pass());
445 } 445 }
446 446
447 void FakeDriveFileSystem::GetEntryInfoByPathAfterGetParentEntryInfo( 447 void FakeFileSystem::GetEntryInfoByPathAfterGetParentEntryInfo(
448 const base::FilePath& base_name, 448 const base::FilePath& base_name,
449 const GetEntryInfoCallback& callback, 449 const GetEntryInfoCallback& callback,
450 FileError error, 450 FileError error,
451 scoped_ptr<DriveEntryProto> parent_entry_proto) { 451 scoped_ptr<DriveEntryProto> parent_entry_proto) {
452 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 452 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
453 453
454 if (error != FILE_ERROR_OK) { 454 if (error != FILE_ERROR_OK) {
455 callback.Run(error, scoped_ptr<DriveEntryProto>()); 455 callback.Run(error, scoped_ptr<DriveEntryProto>());
456 return; 456 return;
457 } 457 }
458 458
459 DCHECK(parent_entry_proto); 459 DCHECK(parent_entry_proto);
460 drive_service_->GetResourceListInDirectory( 460 drive_service_->GetResourceListInDirectory(
461 parent_entry_proto->resource_id(), 461 parent_entry_proto->resource_id(),
462 base::Bind( 462 base::Bind(
463 &FakeDriveFileSystem::GetEntryInfoByPathAfterGetResourceList, 463 &FakeFileSystem::GetEntryInfoByPathAfterGetResourceList,
464 weak_ptr_factory_.GetWeakPtr(), base_name, callback)); 464 weak_ptr_factory_.GetWeakPtr(), base_name, callback));
465 } 465 }
466 466
467 void FakeDriveFileSystem::GetEntryInfoByPathAfterGetResourceList( 467 void FakeFileSystem::GetEntryInfoByPathAfterGetResourceList(
468 const base::FilePath& base_name, 468 const base::FilePath& base_name,
469 const GetEntryInfoCallback& callback, 469 const GetEntryInfoCallback& callback,
470 google_apis::GDataErrorCode gdata_error, 470 google_apis::GDataErrorCode gdata_error,
471 scoped_ptr<google_apis::ResourceList> resource_list) { 471 scoped_ptr<google_apis::ResourceList> resource_list) {
472 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 472 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
473 473
474 FileError error = util::GDataToFileError(gdata_error); 474 FileError error = util::GDataToFileError(gdata_error);
475 if (error != FILE_ERROR_OK) { 475 if (error != FILE_ERROR_OK) {
476 callback.Run(error, scoped_ptr<DriveEntryProto>()); 476 callback.Run(error, scoped_ptr<DriveEntryProto>());
477 return; 477 return;
(...skipping 10 matching lines...) Expand all
488 callback.Run(FILE_ERROR_OK, entry.Pass()); 488 callback.Run(FILE_ERROR_OK, entry.Pass());
489 return; 489 return;
490 } 490 }
491 } 491 }
492 492
493 callback.Run(FILE_ERROR_NOT_FOUND, scoped_ptr<DriveEntryProto>()); 493 callback.Run(FILE_ERROR_NOT_FOUND, scoped_ptr<DriveEntryProto>());
494 } 494 }
495 495
496 } // namespace test_util 496 } // namespace test_util
497 } // namespace drive 497 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/fake_file_system.h ('k') | chrome/browser/chromeos/drive/fake_file_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698