| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/sync_file_system/local/local_file_sync_context.h" | 5 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" |
| 6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 7 #include <vector> | 9 #include <vector> |
| 8 | 10 |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 11 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 13 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/macros.h" |
| 14 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 15 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 16 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 17 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" | 20 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" |
| 18 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" | 21 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" |
| 19 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" | 22 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
| 20 #include "chrome/browser/sync_file_system/sync_file_metadata.h" | 23 #include "chrome/browser/sync_file_system/sync_file_metadata.h" |
| 21 #include "chrome/browser/sync_file_system/sync_status_code.h" | 24 #include "chrome/browser/sync_file_system/sync_status_code.h" |
| 22 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" | 25 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" |
| 23 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 file_system.SetUp(CannedSyncableFileSystem::QUOTA_ENABLED); | 606 file_system.SetUp(CannedSyncableFileSystem::QUOTA_ENABLED); |
| 604 | 607 |
| 605 sync_context_ = new LocalFileSyncContext( | 608 sync_context_ = new LocalFileSyncContext( |
| 606 dir_.path(), in_memory_env_.get(), | 609 dir_.path(), in_memory_env_.get(), |
| 607 ui_task_runner_.get(), io_task_runner_.get()); | 610 ui_task_runner_.get(), io_task_runner_.get()); |
| 608 ASSERT_EQ(SYNC_STATUS_OK, | 611 ASSERT_EQ(SYNC_STATUS_OK, |
| 609 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); | 612 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); |
| 610 ASSERT_EQ(base::File::FILE_OK, file_system.OpenFileSystem()); | 613 ASSERT_EQ(base::File::FILE_OK, file_system.OpenFileSystem()); |
| 611 | 614 |
| 612 // Record the initial usage (likely 0). | 615 // Record the initial usage (likely 0). |
| 613 int64 initial_usage = -1; | 616 int64_t initial_usage = -1; |
| 614 int64 quota = -1; | 617 int64_t quota = -1; |
| 615 EXPECT_EQ(storage::kQuotaStatusOk, | 618 EXPECT_EQ(storage::kQuotaStatusOk, |
| 616 file_system.GetUsageAndQuota(&initial_usage, "a)); | 619 file_system.GetUsageAndQuota(&initial_usage, "a)); |
| 617 | 620 |
| 618 // Create a file and directory in the file_system. | 621 // Create a file and directory in the file_system. |
| 619 const FileSystemURL kFile(file_system.URL("file")); | 622 const FileSystemURL kFile(file_system.URL("file")); |
| 620 const FileSystemURL kDir(file_system.URL("dir")); | 623 const FileSystemURL kDir(file_system.URL("dir")); |
| 621 const FileSystemURL kChild(file_system.URL("dir/child")); | 624 const FileSystemURL kChild(file_system.URL("dir/child")); |
| 622 | 625 |
| 623 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile)); | 626 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile)); |
| 624 EXPECT_EQ(base::File::FILE_OK, file_system.CreateDirectory(kDir)); | 627 EXPECT_EQ(base::File::FILE_OK, file_system.CreateDirectory(kDir)); |
| 625 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kChild)); | 628 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kChild)); |
| 626 | 629 |
| 627 // file_system's change tracker must have recorded the creation. | 630 // file_system's change tracker must have recorded the creation. |
| 628 FileSystemURLSet urls; | 631 FileSystemURLSet urls; |
| 629 file_system.GetChangedURLsInTracker(&urls); | 632 file_system.GetChangedURLsInTracker(&urls); |
| 630 ASSERT_EQ(3U, urls.size()); | 633 ASSERT_EQ(3U, urls.size()); |
| 631 ASSERT_TRUE(ContainsKey(urls, kFile)); | 634 ASSERT_TRUE(ContainsKey(urls, kFile)); |
| 632 ASSERT_TRUE(ContainsKey(urls, kDir)); | 635 ASSERT_TRUE(ContainsKey(urls, kDir)); |
| 633 ASSERT_TRUE(ContainsKey(urls, kChild)); | 636 ASSERT_TRUE(ContainsKey(urls, kChild)); |
| 634 for (FileSystemURLSet::iterator iter = urls.begin(); | 637 for (FileSystemURLSet::iterator iter = urls.begin(); |
| 635 iter != urls.end(); ++iter) { | 638 iter != urls.end(); ++iter) { |
| 636 file_system.ClearChangeForURLInTracker(*iter); | 639 file_system.ClearChangeForURLInTracker(*iter); |
| 637 } | 640 } |
| 638 | 641 |
| 639 // At this point the usage must be greater than the initial usage. | 642 // At this point the usage must be greater than the initial usage. |
| 640 int64 new_usage = -1; | 643 int64_t new_usage = -1; |
| 641 EXPECT_EQ(storage::kQuotaStatusOk, | 644 EXPECT_EQ(storage::kQuotaStatusOk, |
| 642 file_system.GetUsageAndQuota(&new_usage, "a)); | 645 file_system.GetUsageAndQuota(&new_usage, "a)); |
| 643 EXPECT_GT(new_usage, initial_usage); | 646 EXPECT_GT(new_usage, initial_usage); |
| 644 | 647 |
| 645 // Now let's apply remote deletion changes. | 648 // Now let's apply remote deletion changes. |
| 646 FileChange change(FileChange::FILE_CHANGE_DELETE, | 649 FileChange change(FileChange::FILE_CHANGE_DELETE, |
| 647 SYNC_FILE_TYPE_FILE); | 650 SYNC_FILE_TYPE_FILE); |
| 648 EXPECT_EQ(SYNC_STATUS_OK, | 651 EXPECT_EQ(SYNC_STATUS_OK, |
| 649 ApplyRemoteChange(file_system.file_system_context(), | 652 ApplyRemoteChange(file_system.file_system_context(), |
| 650 change, base::FilePath(), kFile, | 653 change, base::FilePath(), kFile, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 file_system.SetUp(CannedSyncableFileSystem::QUOTA_ENABLED); | 694 file_system.SetUp(CannedSyncableFileSystem::QUOTA_ENABLED); |
| 692 | 695 |
| 693 sync_context_ = new LocalFileSyncContext( | 696 sync_context_ = new LocalFileSyncContext( |
| 694 dir_.path(), in_memory_env_.get(), | 697 dir_.path(), in_memory_env_.get(), |
| 695 ui_task_runner_.get(), io_task_runner_.get()); | 698 ui_task_runner_.get(), io_task_runner_.get()); |
| 696 ASSERT_EQ(SYNC_STATUS_OK, | 699 ASSERT_EQ(SYNC_STATUS_OK, |
| 697 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); | 700 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); |
| 698 ASSERT_EQ(base::File::FILE_OK, file_system.OpenFileSystem()); | 701 ASSERT_EQ(base::File::FILE_OK, file_system.OpenFileSystem()); |
| 699 | 702 |
| 700 // Record the initial usage (likely 0). | 703 // Record the initial usage (likely 0). |
| 701 int64 initial_usage = -1; | 704 int64_t initial_usage = -1; |
| 702 int64 quota = -1; | 705 int64_t quota = -1; |
| 703 EXPECT_EQ(storage::kQuotaStatusOk, | 706 EXPECT_EQ(storage::kQuotaStatusOk, |
| 704 file_system.GetUsageAndQuota(&initial_usage, "a)); | 707 file_system.GetUsageAndQuota(&initial_usage, "a)); |
| 705 | 708 |
| 706 // Create a file and directory in the file_system. | 709 // Create a file and directory in the file_system. |
| 707 const FileSystemURL kFile(file_system.URL("file")); | 710 const FileSystemURL kFile(file_system.URL("file")); |
| 708 const FileSystemURL kDir(file_system.URL("dir")); | 711 const FileSystemURL kDir(file_system.URL("dir")); |
| 709 const FileSystemURL kChild(file_system.URL("dir/child")); | 712 const FileSystemURL kChild(file_system.URL("dir/child")); |
| 710 | 713 |
| 711 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile)); | 714 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile)); |
| 712 EXPECT_EQ(base::File::FILE_OK, file_system.CreateDirectory(kDir)); | 715 EXPECT_EQ(base::File::FILE_OK, file_system.CreateDirectory(kDir)); |
| 713 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kChild)); | 716 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kChild)); |
| 714 | 717 |
| 715 // At this point the usage must be greater than the initial usage. | 718 // At this point the usage must be greater than the initial usage. |
| 716 int64 new_usage = -1; | 719 int64_t new_usage = -1; |
| 717 EXPECT_EQ(storage::kQuotaStatusOk, | 720 EXPECT_EQ(storage::kQuotaStatusOk, |
| 718 file_system.GetUsageAndQuota(&new_usage, "a)); | 721 file_system.GetUsageAndQuota(&new_usage, "a)); |
| 719 EXPECT_GT(new_usage, initial_usage); | 722 EXPECT_GT(new_usage, initial_usage); |
| 720 | 723 |
| 721 const FileSystemURL kRoot(file_system.URL("")); | 724 const FileSystemURL kRoot(file_system.URL("")); |
| 722 | 725 |
| 723 // Now let's apply remote deletion changes for the root. | 726 // Now let's apply remote deletion changes for the root. |
| 724 FileChange change(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_DIRECTORY); | 727 FileChange change(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_DIRECTORY); |
| 725 EXPECT_EQ(SYNC_STATUS_OK, | 728 EXPECT_EQ(SYNC_STATUS_OK, |
| 726 ApplyRemoteChange(file_system.file_system_context(), | 729 ApplyRemoteChange(file_system.file_system_context(), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 const FileSystemURL kFile1(file_system.URL("file1")); | 773 const FileSystemURL kFile1(file_system.URL("file1")); |
| 771 const FileSystemURL kFile2(file_system.URL("file2")); | 774 const FileSystemURL kFile2(file_system.URL("file2")); |
| 772 const FileSystemURL kDir(file_system.URL("dir")); | 775 const FileSystemURL kDir(file_system.URL("dir")); |
| 773 | 776 |
| 774 const char kTestFileData0[] = "0123456789"; | 777 const char kTestFileData0[] = "0123456789"; |
| 775 const char kTestFileData1[] = "Lorem ipsum!"; | 778 const char kTestFileData1[] = "Lorem ipsum!"; |
| 776 const char kTestFileData2[] = "This is sample test data."; | 779 const char kTestFileData2[] = "This is sample test data."; |
| 777 | 780 |
| 778 // Create kFile1 and populate it with kTestFileData0. | 781 // Create kFile1 and populate it with kTestFileData0. |
| 779 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile1)); | 782 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile1)); |
| 780 EXPECT_EQ(static_cast<int64>(arraysize(kTestFileData0) - 1), | 783 EXPECT_EQ(static_cast<int64_t>(arraysize(kTestFileData0) - 1), |
| 781 file_system.WriteString(kFile1, kTestFileData0)); | 784 file_system.WriteString(kFile1, kTestFileData0)); |
| 782 | 785 |
| 783 // kFile2 and kDir are not there yet. | 786 // kFile2 and kDir are not there yet. |
| 784 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, | 787 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, |
| 785 file_system.FileExists(kFile2)); | 788 file_system.FileExists(kFile2)); |
| 786 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, | 789 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, |
| 787 file_system.DirectoryExists(kDir)); | 790 file_system.DirectoryExists(kDir)); |
| 788 | 791 |
| 789 // file_system's change tracker must have recorded the creation. | 792 // file_system's change tracker must have recorded the creation. |
| 790 FileSystemURLSet urls; | 793 FileSystemURLSet urls; |
| 791 file_system.GetChangedURLsInTracker(&urls); | 794 file_system.GetChangedURLsInTracker(&urls); |
| 792 ASSERT_EQ(1U, urls.size()); | 795 ASSERT_EQ(1U, urls.size()); |
| 793 EXPECT_TRUE(ContainsKey(urls, kFile1)); | 796 EXPECT_TRUE(ContainsKey(urls, kFile1)); |
| 794 file_system.ClearChangeForURLInTracker(*urls.begin()); | 797 file_system.ClearChangeForURLInTracker(*urls.begin()); |
| 795 | 798 |
| 796 // Prepare temporary files which represent the remote file data. | 799 // Prepare temporary files which represent the remote file data. |
| 797 const base::FilePath kFilePath1(temp_dir.path().Append(FPL("file1"))); | 800 const base::FilePath kFilePath1(temp_dir.path().Append(FPL("file1"))); |
| 798 const base::FilePath kFilePath2(temp_dir.path().Append(FPL("file2"))); | 801 const base::FilePath kFilePath2(temp_dir.path().Append(FPL("file2"))); |
| 799 | 802 |
| 800 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData1) - 1), | 803 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData1) - 1), |
| 801 base::WriteFile(kFilePath1, kTestFileData1, | 804 base::WriteFile(kFilePath1, kTestFileData1, |
| 802 arraysize(kTestFileData1) - 1)); | 805 arraysize(kTestFileData1) - 1)); |
| 803 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData2) - 1), | 806 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData2) - 1), |
| 804 base::WriteFile(kFilePath2, kTestFileData2, | 807 base::WriteFile(kFilePath2, kTestFileData2, |
| 805 arraysize(kTestFileData2) - 1)); | 808 arraysize(kTestFileData2) - 1)); |
| 806 | 809 |
| 807 // Record the usage. | 810 // Record the usage. |
| 808 int64 usage = -1, new_usage = -1; | 811 int64_t usage = -1, new_usage = -1; |
| 809 int64 quota = -1; | 812 int64_t quota = -1; |
| 810 EXPECT_EQ(storage::kQuotaStatusOk, | 813 EXPECT_EQ(storage::kQuotaStatusOk, |
| 811 file_system.GetUsageAndQuota(&usage, "a)); | 814 file_system.GetUsageAndQuota(&usage, "a)); |
| 812 | 815 |
| 813 // Here in the local filesystem we have: | 816 // Here in the local filesystem we have: |
| 814 // * kFile1 with kTestFileData0 | 817 // * kFile1 with kTestFileData0 |
| 815 // | 818 // |
| 816 // In the remote side let's assume we have: | 819 // In the remote side let's assume we have: |
| 817 // * kFile1 with kTestFileData1 | 820 // * kFile1 with kTestFileData1 |
| 818 // * kFile2 with kTestFileData2 | 821 // * kFile2 with kTestFileData2 |
| 819 // * kDir | 822 // * kDir |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 kFilePath1, | 880 kFilePath1, |
| 878 kDir, | 881 kDir, |
| 879 SYNC_FILE_TYPE_FILE)); | 882 SYNC_FILE_TYPE_FILE)); |
| 880 | 883 |
| 881 // Creating a file/directory must have increased the usage more than | 884 // Creating a file/directory must have increased the usage more than |
| 882 // the size of kTestFileData2. | 885 // the size of kTestFileData2. |
| 883 new_usage = usage; | 886 new_usage = usage; |
| 884 EXPECT_EQ(storage::kQuotaStatusOk, | 887 EXPECT_EQ(storage::kQuotaStatusOk, |
| 885 file_system.GetUsageAndQuota(&new_usage, "a)); | 888 file_system.GetUsageAndQuota(&new_usage, "a)); |
| 886 EXPECT_GT(new_usage, | 889 EXPECT_GT(new_usage, |
| 887 static_cast<int64>(usage + arraysize(kTestFileData2) - 1)); | 890 static_cast<int64_t>(usage + arraysize(kTestFileData2) - 1)); |
| 888 | 891 |
| 889 // The changes applied by ApplyRemoteChange should not be recorded in | 892 // The changes applied by ApplyRemoteChange should not be recorded in |
| 890 // the change tracker. | 893 // the change tracker. |
| 891 urls.clear(); | 894 urls.clear(); |
| 892 file_system.GetChangedURLsInTracker(&urls); | 895 file_system.GetChangedURLsInTracker(&urls); |
| 893 EXPECT_TRUE(urls.empty()); | 896 EXPECT_TRUE(urls.empty()); |
| 894 | 897 |
| 895 // Make sure all three files/directory exist. | 898 // Make sure all three files/directory exist. |
| 896 EXPECT_EQ(base::File::FILE_OK, file_system.FileExists(kFile1)); | 899 EXPECT_EQ(base::File::FILE_OK, file_system.FileExists(kFile1)); |
| 897 EXPECT_EQ(base::File::FILE_OK, file_system.FileExists(kFile2)); | 900 EXPECT_EQ(base::File::FILE_OK, file_system.FileExists(kFile2)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 | 953 |
| 951 // Make sure kDir and kFile are created by ApplyRemoteChange. | 954 // Make sure kDir and kFile are created by ApplyRemoteChange. |
| 952 EXPECT_EQ(base::File::FILE_OK, file_system.FileExists(kFile)); | 955 EXPECT_EQ(base::File::FILE_OK, file_system.FileExists(kFile)); |
| 953 EXPECT_EQ(base::File::FILE_OK, file_system.DirectoryExists(kDir)); | 956 EXPECT_EQ(base::File::FILE_OK, file_system.DirectoryExists(kDir)); |
| 954 | 957 |
| 955 sync_context_->ShutdownOnUIThread(); | 958 sync_context_->ShutdownOnUIThread(); |
| 956 file_system.TearDown(); | 959 file_system.TearDown(); |
| 957 } | 960 } |
| 958 | 961 |
| 959 } // namespace sync_file_system | 962 } // namespace sync_file_system |
| OLD | NEW |