OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/fileapi/syncable/canned_syncable_file_system.h" | 5 #include "webkit/fileapi/syncable/canned_syncable_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/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 ASSERT_TRUE(runner2 != NULL); | 82 ASSERT_TRUE(runner2 != NULL); |
83 runner1->PostTask(FROM_HERE, | 83 runner1->PostTask(FROM_HERE, |
84 base::Bind(&EnsureRunningOn, make_scoped_refptr(runner2))); | 84 base::Bind(&EnsureRunningOn, make_scoped_refptr(runner2))); |
85 } | 85 } |
86 | 86 |
87 void OnGetMetadataAndVerifyData( | 87 void OnGetMetadataAndVerifyData( |
88 const std::string& expected_data, | 88 const std::string& expected_data, |
89 const CannedSyncableFileSystem::StatusCallback& callback, | 89 const CannedSyncableFileSystem::StatusCallback& callback, |
90 base::PlatformFileError result, | 90 base::PlatformFileError result, |
91 const base::PlatformFileInfo& file_info, | 91 const base::PlatformFileInfo& file_info, |
92 const FilePath& platform_path) { | 92 const base::FilePath& platform_path) { |
93 if (result != base::PLATFORM_FILE_OK) { | 93 if (result != base::PLATFORM_FILE_OK) { |
94 callback.Run(result); | 94 callback.Run(result); |
95 return; | 95 return; |
96 } | 96 } |
97 EXPECT_EQ(expected_data.size(), static_cast<size_t>(file_info.size)); | 97 EXPECT_EQ(expected_data.size(), static_cast<size_t>(file_info.size)); |
98 std::string data; | 98 std::string data; |
99 const bool read_status = file_util::ReadFileToString(platform_path, &data); | 99 const bool read_status = file_util::ReadFileToString(platform_path, &data); |
100 EXPECT_TRUE(read_status); | 100 EXPECT_TRUE(read_status); |
101 EXPECT_EQ(expected_data, data); | 101 EXPECT_EQ(expected_data, data); |
102 callback.Run(result); | 102 callback.Run(result); |
103 } | 103 } |
104 | 104 |
105 void OnGetMetadata( | 105 void OnGetMetadata( |
106 base::PlatformFileInfo* file_info_out, | 106 base::PlatformFileInfo* file_info_out, |
107 FilePath* platform_path_out, | 107 base::FilePath* platform_path_out, |
108 const CannedSyncableFileSystem::StatusCallback& callback, | 108 const CannedSyncableFileSystem::StatusCallback& callback, |
109 base::PlatformFileError result, | 109 base::PlatformFileError result, |
110 const base::PlatformFileInfo& file_info, | 110 const base::PlatformFileInfo& file_info, |
111 const FilePath& platform_path) { | 111 const base::FilePath& platform_path) { |
112 DCHECK(file_info_out); | 112 DCHECK(file_info_out); |
113 DCHECK(platform_path_out); | 113 DCHECK(platform_path_out); |
114 *file_info_out = file_info; | 114 *file_info_out = file_info; |
115 *platform_path_out = platform_path; | 115 *platform_path_out = platform_path; |
116 callback.Run(result); | 116 callback.Run(result); |
117 } | 117 } |
118 | 118 |
119 class WriteHelper { | 119 class WriteHelper { |
120 public: | 120 public: |
121 WriteHelper() : bytes_written_(0) {} | 121 WriteHelper() : bytes_written_(0) {} |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 return RunOnThread<PlatformFileError>( | 368 return RunOnThread<PlatformFileError>( |
369 io_task_runner_, | 369 io_task_runner_, |
370 FROM_HERE, | 370 FROM_HERE, |
371 base::Bind(&CannedSyncableFileSystem::DoVerifyFile, | 371 base::Bind(&CannedSyncableFileSystem::DoVerifyFile, |
372 base::Unretained(this), url, expected_data)); | 372 base::Unretained(this), url, expected_data)); |
373 } | 373 } |
374 | 374 |
375 PlatformFileError CannedSyncableFileSystem::GetMetadata( | 375 PlatformFileError CannedSyncableFileSystem::GetMetadata( |
376 const FileSystemURL& url, | 376 const FileSystemURL& url, |
377 base::PlatformFileInfo* info, | 377 base::PlatformFileInfo* info, |
378 FilePath* platform_path) { | 378 base::FilePath* platform_path) { |
379 return RunOnThread<PlatformFileError>( | 379 return RunOnThread<PlatformFileError>( |
380 io_task_runner_, | 380 io_task_runner_, |
381 FROM_HERE, | 381 FROM_HERE, |
382 base::Bind(&CannedSyncableFileSystem::DoGetMetadata, | 382 base::Bind(&CannedSyncableFileSystem::DoGetMetadata, |
383 base::Unretained(this), url, info, platform_path)); | 383 base::Unretained(this), url, info, platform_path)); |
384 } | 384 } |
385 | 385 |
386 int64 CannedSyncableFileSystem::Write( | 386 int64 CannedSyncableFileSystem::Write( |
387 net::URLRequestContext* url_request_context, | 387 net::URLRequestContext* url_request_context, |
388 const FileSystemURL& url, const GURL& blob_url) { | 388 const FileSystemURL& url, const GURL& blob_url) { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 const StatusCallback& callback) { | 533 const StatusCallback& callback) { |
534 EXPECT_TRUE(is_filesystem_opened_); | 534 EXPECT_TRUE(is_filesystem_opened_); |
535 NewOperation()->GetMetadata( | 535 NewOperation()->GetMetadata( |
536 url, base::Bind(&OnGetMetadataAndVerifyData, | 536 url, base::Bind(&OnGetMetadataAndVerifyData, |
537 expected_data, callback)); | 537 expected_data, callback)); |
538 } | 538 } |
539 | 539 |
540 void CannedSyncableFileSystem::DoGetMetadata( | 540 void CannedSyncableFileSystem::DoGetMetadata( |
541 const FileSystemURL& url, | 541 const FileSystemURL& url, |
542 base::PlatformFileInfo* info, | 542 base::PlatformFileInfo* info, |
543 FilePath* platform_path, | 543 base::FilePath* platform_path, |
544 const StatusCallback& callback) { | 544 const StatusCallback& callback) { |
545 EXPECT_TRUE(is_filesystem_opened_); | 545 EXPECT_TRUE(is_filesystem_opened_); |
546 NewOperation()->GetMetadata( | 546 NewOperation()->GetMetadata( |
547 url, base::Bind(&OnGetMetadata, info, platform_path, callback)); | 547 url, base::Bind(&OnGetMetadata, info, platform_path, callback)); |
548 } | 548 } |
549 | 549 |
550 void CannedSyncableFileSystem::DoWrite( | 550 void CannedSyncableFileSystem::DoWrite( |
551 net::URLRequestContext* url_request_context, | 551 net::URLRequestContext* url_request_context, |
552 const FileSystemURL& url, const GURL& blob_url, | 552 const FileSystemURL& url, const GURL& blob_url, |
553 const WriteCallback& callback) { | 553 const WriteCallback& callback) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 sync_status_ = status; | 593 sync_status_ = status; |
594 MessageLoop::current()->Quit(); | 594 MessageLoop::current()->Quit(); |
595 } | 595 } |
596 | 596 |
597 void CannedSyncableFileSystem::InitializeSyncStatusObserver() { | 597 void CannedSyncableFileSystem::InitializeSyncStatusObserver() { |
598 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); | 598 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); |
599 file_system_context_->sync_context()->sync_status()->AddObserver(this); | 599 file_system_context_->sync_context()->sync_status()->AddObserver(this); |
600 } | 600 } |
601 | 601 |
602 } // namespace fileapi | 602 } // namespace fileapi |
OLD | NEW |