Commit 70e1665c authored by kinaba@chromium.org's avatar kinaba@chromium.org

Remove legacy in DriveSyncClient.

The feature using Profile or Preferences has been moved to DriveScheduler,
so we don't need them here anymore.

BUG=none

Review URL: https://chromiumcodereview.appspot.com/14348013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195234 0039d316-1c4b-4281-b951-d872f2087c98
parent 4f716172
......@@ -4,17 +4,13 @@
#include "chrome/browser/chromeos/drive/drive_sync_client.h"
#include <algorithm>
#include <vector>
#include "base/bind.h"
#include "base/message_loop_proxy.h"
#include "base/prefs/pref_change_registrar.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/chromeos/drive/drive.pb.h"
#include "chrome/browser/chromeos/drive/drive_cache.h"
#include "chrome/browser/chromeos/drive/drive_file_system_interface.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
using content::BrowserThread;
......@@ -58,30 +54,25 @@ void CollectBacklog(std::vector<std::string>* to_fetch,
} // namespace
DriveSyncClient::DriveSyncClient(Profile* profile,
DriveFileSystemInterface* file_system,
DriveSyncClient::DriveSyncClient(DriveFileSystemInterface* file_system,
DriveCache* cache)
: profile_(profile),
file_system_(file_system),
: file_system_(file_system),
cache_(cache),
delay_(base::TimeDelta::FromSeconds(kDelaySeconds)),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
DCHECK(file_system);
DCHECK(cache);
DriveSyncClient::~DriveSyncClient() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (file_system_)
file_system_->RemoveObserver(this);
if (cache_)
cache_->RemoveObserver(this);
file_system_->AddObserver(this);
cache_->AddObserver(this);
}
void DriveSyncClient::Initialize() {
DriveSyncClient::~DriveSyncClient() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
file_system_->AddObserver(this);
cache_->AddObserver(this);
file_system_->RemoveObserver(this);
cache_->RemoveObserver(this);
}
void DriveSyncClient::StartProcessingBacklog() {
......
......@@ -5,27 +5,22 @@
#ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SYNC_CLIENT_H_
#define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SYNC_CLIENT_H_
#include <deque>
#include <set>
#include <string>
#include <vector>
#include "base/callback_forward.h"
#include "base/memory/weak_ptr.h"
#include "base/time.h"
#include "chrome/browser/chromeos/drive/drive_cache.h"
#include "chrome/browser/chromeos/drive/drive_cache_observer.h"
#include "chrome/browser/chromeos/drive/drive_file_system_observer.h"
#include "chrome/browser/chromeos/drive/drive_resource_metadata.h"
#include "net/base/network_change_notifier.h"
class Profile;
class PrefChangeRegistrar;
namespace drive {
class DriveCache;
class DriveCacheEntry;
class DriveEntryProto;
class DriveFileSystemInterface;
class DrivePrefetcher;
// The DriveSyncClient is used to synchronize pinned files on Drive and the
// cache on the local drive. The sync client works as follows.
......@@ -40,9 +35,8 @@ class DrivePrefetcher;
// If the user logs out before fetching of the pinned files is complete, this
// client resumes fetching operations next time the user logs in, based on
// the states left in the cache.
class DriveSyncClient
: public DriveFileSystemObserver,
public DriveCacheObserver {
class DriveSyncClient : public DriveFileSystemObserver,
public DriveCacheObserver {
public:
// Types of sync tasks.
enum SyncType {
......@@ -50,17 +44,9 @@ class DriveSyncClient
UPLOAD, // Upload a file to the Drive server.
};
// |profile| is used to access user preferences.
// |file_system| is used access the
// cache (ex. store a file to the cache when the file is downloaded).
DriveSyncClient(Profile* profile,
DriveFileSystemInterface* file_system,
DriveCache* cache);
DriveSyncClient(DriveFileSystemInterface* file_system, DriveCache* cache);
virtual ~DriveSyncClient();
// Initializes the DriveSyncClient.
void Initialize();
// DriveFileSystemInterface::Observer overrides.
virtual void OnInitialLoadFinished() OVERRIDE;
virtual void OnFeedFromServerLoaded() OVERRIDE;
......@@ -150,7 +136,6 @@ class DriveSyncClient
void OnUploadFileComplete(const std::string& resource_id,
DriveFileError error);
Profile* profile_;
DriveFileSystemInterface* file_system_; // Owned by DriveSystemService.
DriveCache* cache_; // Owned by DriveSystemService.
......
......@@ -4,34 +4,25 @@
#include "chrome/browser/chromeos/drive/drive_sync_client.h"
#include <algorithm>
#include <vector>
#include "base/bind.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/prefs/pref_service.h"
#include "base/test/test_timeouts.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/chromeos/drive/drive.pb.h"
#include "chrome/browser/chromeos/drive/drive_cache.h"
#include "chrome/browser/chromeos/drive/drive_file_system_util.h"
#include "chrome/browser/chromeos/drive/drive_test_util.h"
#include "chrome/browser/chromeos/drive/mock_drive_file_system.h"
#include "chrome/browser/google_apis/test_util.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/test_browser_thread.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::AnyNumber;
using ::testing::DoAll;
using ::testing::Return;
using ::testing::StrictMock;
using ::testing::_;
......@@ -56,25 +47,16 @@ ACTION_P2(MockUpdateFileByResourceId, error, md5) {
arg1.Run(error, base::FilePath(), entry_proto.Pass());
}
class MockNetworkChangeNotifier : public net::NetworkChangeNotifier {
public:
MOCK_CONST_METHOD0(GetCurrentConnectionType,
net::NetworkChangeNotifier::ConnectionType());
};
} // namespace
class DriveSyncClientTest : public testing::Test {
public:
DriveSyncClientTest()
: ui_thread_(content::BrowserThread::UI, &message_loop_),
profile_(new TestingProfile),
mock_file_system_(new StrictMock<MockDriveFileSystem>) {
}
virtual void SetUp() OVERRIDE {
mock_network_change_notifier_.reset(new MockNetworkChangeNotifier);
// Create a temporary directory.
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
......@@ -93,25 +75,18 @@ class DriveSyncClientTest : public testing::Test {
SetUpCache();
// Initialize the sync client.
sync_client_.reset(new DriveSyncClient(profile_.get(),
mock_file_system_.get(),
EXPECT_CALL(*mock_file_system_, AddObserver(_)).Times(1);
EXPECT_CALL(*mock_file_system_, RemoveObserver(_)).Times(1);
sync_client_.reset(new DriveSyncClient(mock_file_system_.get(),
cache_.get()));
EXPECT_CALL(*mock_file_system_, AddObserver(sync_client_.get())).Times(1);
EXPECT_CALL(*mock_file_system_,
RemoveObserver(sync_client_.get())).Times(1);
// Disable delaying so that DoSyncLoop() starts immediately.
sync_client_->set_delay_for_testing(base::TimeDelta::FromSeconds(0));
sync_client_->Initialize();
}
virtual void TearDown() OVERRIDE {
// The sync client should be deleted before NetworkLibrary, as the sync
// client registers itself as observer of NetworkLibrary.
sync_client_.reset();
cache_.reset();
mock_network_change_notifier_.reset();
}
// Sets up cache for tests.
......@@ -244,11 +219,9 @@ class DriveSyncClientTest : public testing::Test {
MessageLoopForUI message_loop_;
content::TestBrowserThread ui_thread_;
base::ScopedTempDir temp_dir_;
scoped_ptr<TestingProfile> profile_;
scoped_ptr<StrictMock<MockDriveFileSystem> > mock_file_system_;
scoped_ptr<DriveCache, test_util::DestroyHelperForTests> cache_;
scoped_ptr<DriveSyncClient> sync_client_;
scoped_ptr<MockNetworkChangeNotifier> mock_network_change_notifier_;
};
TEST_F(DriveSyncClientTest, StartInitialScan) {
......
......@@ -8,6 +8,7 @@
#include "base/command_line.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/drive/drive_cache.h"
#include "chrome/browser/chromeos/drive/drive_download_handler.h"
#include "chrome/browser/chromeos/drive/drive_file_system.h"
#include "chrome/browser/chromeos/drive/drive_file_system_proxy.h"
......@@ -151,7 +152,7 @@ DriveSystemService::DriveSystemService(
file_write_helper_.reset(new FileWriteHelper(file_system()));
download_handler_.reset(new DriveDownloadHandler(file_write_helper(),
file_system()));
sync_client_.reset(new DriveSyncClient(profile_, file_system(), cache()));
sync_client_.reset(new DriveSyncClient(file_system(), cache()));
prefetcher_.reset(new DrivePrefetcher(file_system(),
event_logger(),
DrivePrefetcherOptions()));
......@@ -165,7 +166,6 @@ DriveSystemService::~DriveSystemService() {
void DriveSystemService::Initialize() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
sync_client_->Initialize();
drive_service_->Initialize(profile_);
file_system_->Initialize();
cache_->RequestInitialize(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment