diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-02 08:23:48 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-02 08:23:48 +0000 |
commit | d2c08b7abc9d737017507034095b82528e0cef65 (patch) | |
tree | 423558de32b6ebd12061a995dad76c3c5b3bd8bd | |
parent | 91feba4d1ddde3aea8aab96d189acf3db145d0c0 (diff) | |
download | chromium_src-d2c08b7abc9d737017507034095b82528e0cef65.zip chromium_src-d2c08b7abc9d737017507034095b82528e0cef65.tar.gz chromium_src-d2c08b7abc9d737017507034095b82528e0cef65.tar.bz2 |
drive: Retry upload from SyncClient on network reconnection
BUG=229311
TEST=unit_tests
R=kinaba@chromium.org
Review URL: https://codereview.chromium.org/18182004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@209651 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/drive/sync_client.cc | 12 | ||||
-rw-r--r-- | chrome/browser/chromeos/drive/sync_client_unittest.cc | 49 |
2 files changed, 58 insertions, 3 deletions
diff --git a/chrome/browser/chromeos/drive/sync_client.cc b/chrome/browser/chromeos/drive/sync_client.cc index 4d12ff3..fca455e 100644 --- a/chrome/browser/chromeos/drive/sync_client.cc +++ b/chrome/browser/chromeos/drive/sync_client.cc @@ -322,9 +322,15 @@ void SyncClient::OnUploadFileComplete(const std::string& resource_id, if (error == FILE_ERROR_OK) { DVLOG(1) << "Uploaded " << resource_id; } else { - // TODO(satorux): We should re-queue if the error is recoverable. - LOG(WARNING) << "Failed to upload " << resource_id << ": " - << FileErrorToString(error); + switch (error) { + case FILE_ERROR_NO_CONNECTION: + // Re-queue the task so that we'll retry once the connection is back. + AddTaskToQueue(UPLOAD, resource_id); + break; + default: + LOG(WARNING) << "Failed to upload " << resource_id << ": " + << FileErrorToString(error); + } } } diff --git a/chrome/browser/chromeos/drive/sync_client_unittest.cc b/chrome/browser/chromeos/drive/sync_client_unittest.cc index 72a28c5..188a2a7 100644 --- a/chrome/browser/chromeos/drive/sync_client_unittest.cc +++ b/chrome/browser/chromeos/drive/sync_client_unittest.cc @@ -12,6 +12,7 @@ #include "base/test/test_timeouts.h" #include "chrome/browser/chromeos/drive/change_list_loader.h" #include "chrome/browser/chromeos/drive/drive.pb.h" +#include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" #include "chrome/browser/chromeos/drive/file_cache.h" #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" #include "chrome/browser/chromeos/drive/job_scheduler.h" @@ -80,6 +81,9 @@ class SyncClientTest : public testing::Test { profile_.reset(new TestingProfile); + fake_network_change_notifier_.reset( + new test_util::FakeNetworkChangeNotifier); + drive_service_.reset(new SyncClientTestDriveService); drive_service_->LoadResourceListForWapi("gdata/empty_feed.json"); drive_service_->LoadAccountMetadataForWapi( @@ -184,6 +188,8 @@ class SyncClientTest : public testing::Test { content::TestBrowserThreadBundle thread_bundle_; base::ScopedTempDir temp_dir_; scoped_ptr<TestingProfile> profile_; + scoped_ptr<test_util::FakeNetworkChangeNotifier> + fake_network_change_notifier_; scoped_ptr<SyncClientTestDriveService> drive_service_; DummyOperationObserver observer_; scoped_ptr<JobScheduler> scheduler_; @@ -289,5 +295,48 @@ TEST_F(SyncClientTest, ExistingPinnedFiles) { EXPECT_EQ(kLocalContent, content); } +TEST_F(SyncClientTest, RetryOnDisconnection) { + // Let the service go down. + drive_service_->set_offline(true); + // Change the network connection state after some delay, to test that + // FILE_ERROR_NO_CONNECTION is handled by SyncClient correctly. + // Without this delay, JobScheduler will keep the jobs unrun and SyncClient + // will receive no error. + base::MessageLoopProxy::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&test_util::FakeNetworkChangeNotifier::SetConnectionType, + base::Unretained(fake_network_change_notifier_.get()), + net::NetworkChangeNotifier::CONNECTION_NONE), + TestTimeouts::tiny_timeout()); + + // Try fetch and upload. + sync_client_->AddFetchTask(resource_ids_["foo"]); + sync_client_->AddUploadTask(resource_ids_["dirty"]); + base::RunLoop().RunUntilIdle(); + + // Not yet fetched nor uploaded. + FileCacheEntry cache_entry; + EXPECT_TRUE(cache_->GetCacheEntry(resource_ids_["foo"], std::string(), + &cache_entry)); + EXPECT_FALSE(cache_entry.is_present()); + EXPECT_TRUE(cache_->GetCacheEntry(resource_ids_["dirty"], std::string(), + &cache_entry)); + EXPECT_TRUE(cache_entry.is_dirty()); + + // Switch to online. + fake_network_change_notifier_->SetConnectionType( + net::NetworkChangeNotifier::CONNECTION_WIFI); + drive_service_->set_offline(false); + base::RunLoop().RunUntilIdle(); + + // Fetched and uploaded. + EXPECT_TRUE(cache_->GetCacheEntry(resource_ids_["foo"], std::string(), + &cache_entry)); + EXPECT_TRUE(cache_entry.is_present()); + EXPECT_TRUE(cache_->GetCacheEntry(resource_ids_["dirty"], std::string(), + &cache_entry)); + EXPECT_FALSE(cache_entry.is_dirty()); +} + } // namespace internal } // namespace drive |