summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chromeos/extensions/file_browser_event_router.cc22
-rw-r--r--chrome/browser/chromeos/extensions/file_browser_private_api.cc52
-rw-r--r--chrome/browser/chromeos/gdata/gdata_file_system.cc62
-rw-r--r--chrome/browser/chromeos/gdata/gdata_file_system.h52
-rw-r--r--chrome/browser/chromeos/gdata/gdata_file_system_proxy.cc7
-rw-r--r--chrome/browser/chromeos/gdata/gdata_file_system_proxy.h8
-rw-r--r--chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc17
-rw-r--r--chrome/browser/chromeos/gdata/gdata_sync_client.cc7
-rw-r--r--chrome/browser/chromeos/gdata/gdata_sync_client.h11
-rw-r--r--chrome/browser/chromeos/gdata/gdata_sync_client_unittest.cc4
-rw-r--r--chrome/browser/chromeos/gdata/gdata_system_service.cc86
-rw-r--r--chrome/browser/chromeos/gdata/gdata_system_service.h81
-rw-r--r--chrome/browser/chromeos/gdata/mock_gdata_sync_client.h2
-rw-r--r--chrome/browser/download/download_file_picker_chromeos.cc9
-rw-r--r--chrome/chrome_browser.gypi2
15 files changed, 256 insertions, 166 deletions
diff --git a/chrome/browser/chromeos/extensions/file_browser_event_router.cc b/chrome/browser/chromeos/extensions/file_browser_event_router.cc
index 9bde44c..fee371a 100644
--- a/chrome/browser/chromeos/extensions/file_browser_event_router.cc
+++ b/chrome/browser/chromeos/extensions/file_browser_event_router.cc
@@ -11,6 +11,7 @@
#include "base/values.h"
#include "chrome/browser/chromeos/extensions/file_browser_notifications.h"
#include "chrome/browser/chromeos/extensions/file_manager_util.h"
+#include "chrome/browser/chromeos/gdata/gdata_system_service.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/extensions/extension_event_names.h"
#include "chrome/browser/extensions/extension_event_router.h"
@@ -27,7 +28,8 @@ using chromeos::disks::DiskMountManager;
using chromeos::disks::DiskMountManagerEventType;
using content::BrowserThread;
using gdata::GDataFileSystem;
-using gdata::GDataFileSystemFactory;
+using gdata::GDataSystemService;
+using gdata::GDataSystemServiceFactory;
namespace {
const char kDiskAddedEventType[] = "added";
@@ -99,10 +101,10 @@ void FileBrowserEventRouter::ShutdownOnUIThread() {
}
DiskMountManager::GetInstance()->RemoveObserver(this);
- GDataFileSystem* file_system =
- GDataFileSystemFactory::FindForProfile(profile_);
- if (file_system)
- file_system->RemoveOperationObserver(this);
+ GDataSystemService* system_service =
+ GDataSystemServiceFactory::FindForProfile(profile_);
+ if (system_service)
+ system_service->file_system()->RemoveOperationObserver(this);
profile_ = NULL;
}
@@ -120,13 +122,13 @@ void FileBrowserEventRouter::ObserveFileSystemEvents() {
disk_mount_manager->AddObserver(this);
disk_mount_manager->RequestMountInfoRefresh();
- GDataFileSystem* file_system =
- GDataFileSystemFactory::GetForProfile(profile_);
- if (!file_system) {
+ GDataSystemService* system_service =
+ GDataSystemServiceFactory::GetForProfile(profile_);
+ if (!system_service) {
NOTREACHED();
return;
}
- file_system->AddOperationObserver(this);
+ system_service->file_system()->AddOperationObserver(this);
}
// File watch setup routines.
@@ -607,7 +609,7 @@ FileBrowserEventRouterFactory::GetInstance() {
FileBrowserEventRouterFactory::FileBrowserEventRouterFactory()
: RefcountedProfileKeyedServiceFactory("FileBrowserEventRouter",
ProfileDependencyManager::GetInstance()) {
- DependsOn(GDataFileSystemFactory::GetInstance());
+ DependsOn(GDataSystemServiceFactory::GetInstance());
}
FileBrowserEventRouterFactory::~FileBrowserEventRouterFactory() {
diff --git a/chrome/browser/chromeos/extensions/file_browser_private_api.cc b/chrome/browser/chromeos/extensions/file_browser_private_api.cc
index 2908b57..0db316f 100644
--- a/chrome/browser/chromeos/extensions/file_browser_private_api.cc
+++ b/chrome/browser/chromeos/extensions/file_browser_private_api.cc
@@ -19,6 +19,7 @@
#include "chrome/browser/chromeos/extensions/file_manager_util.h"
#include "chrome/browser/chromeos/gdata/gdata_file_system_proxy.h"
#include "chrome/browser/chromeos/gdata/gdata_operation_registry.h"
+#include "chrome/browser/chromeos/gdata/gdata_system_service.h"
#include "chrome/browser/chromeos/gdata/gdata_util.h"
#include "chrome/browser/extensions/extension_function_dispatcher.h"
#include "chrome/browser/extensions/extension_process_manager.h"
@@ -991,10 +992,10 @@ bool AddMountFunction::RunImpl() {
break;
}
case chromeos::MOUNT_TYPE_GDATA: {
- gdata::GDataFileSystem* file_system =
- gdata::GDataFileSystemFactory::GetForProfile(profile_);
- if (file_system) {
- file_system->Authenticate(
+ gdata::GDataSystemService* system_service =
+ gdata::GDataSystemServiceFactory::GetForProfile(profile_);
+ if (system_service) {
+ system_service->file_system()->Authenticate(
base::Bind(&AddMountFunction::OnGDataAuthentication,
this));
}
@@ -1031,8 +1032,12 @@ void AddMountFunction::AddGDataMountPoint() {
render_view_host()->GetProcess()->GetID(), mount_point,
file_handler_util::GetReadWritePermissions());
- provider->AddRemoteMountPoint(mount_point,
- new gdata::GDataFileSystemProxy(profile_));
+ gdata::GDataSystemService* system_service =
+ gdata::GDataSystemServiceFactory::GetForProfile(profile_);
+ DCHECK(system_service);
+ provider->AddRemoteMountPoint(
+ mount_point,
+ new gdata::GDataFileSystemProxy(system_service->file_system()));
}
void AddMountFunction::RaiseGDataMountEvent(gdata::GDataErrorCode error) {
@@ -1586,12 +1591,13 @@ bool GetGDataFilePropertiesFunction::RunImpl() {
}
base::ListValue* file_properties = new base::ListValue;
- gdata::GDataFileSystem* file_system =
- gdata::GDataFileSystemFactory::GetForProfile(profile_);
- DCHECK(file_system);
+ gdata::GDataSystemService* system_service =
+ gdata::GDataSystemServiceFactory::GetForProfile(profile_);
+ DCHECK(system_service);
for (std::vector<FilePath>::size_type i = 0; i < file_paths.size(); ++i) {
FilePropertiesDelegate property_delegate;
- file_system->FindFileByPathSync(file_paths[i], &property_delegate);
+ system_service->file_system()->FindFileByPathSync(file_paths[i],
+ &property_delegate);
base::DictionaryValue* property_dict = new base::DictionaryValue;
property_delegate.CopyProperties(property_dict);
property_dict->SetString("fileUrl", file_urls[i].spec());
@@ -1728,13 +1734,13 @@ void GetGDataFilesFunction::GetFileOrSendResponse() {
return;
}
- gdata::GDataFileSystem* file_system =
- gdata::GDataFileSystemFactory::GetForProfile(profile_);
- DCHECK(file_system);
+ gdata::GDataSystemService* system_service =
+ gdata::GDataSystemServiceFactory::GetForProfile(profile_);
+ DCHECK(system_service);
// Get the file on the top of the queue.
FilePath gdata_path = remaining_gdata_paths_.front();
- file_system->GetFile(
+ system_service->file_system()->GetFile(
gdata_path,
base::Bind(&GetGDataFilesFunction::OnFileReady, this));
}
@@ -1772,13 +1778,13 @@ GetFileTransfersFunction::GetFileTransfersFunction() {}
GetFileTransfersFunction::~GetFileTransfersFunction() {}
ListValue* GetFileTransfersFunction::GetFileTransfersList() {
- gdata::GDataFileSystem* file_system =
- gdata::GDataFileSystemFactory::GetForProfile(profile_);
- if (!file_system)
+ gdata::GDataSystemService* system_service =
+ gdata::GDataSystemServiceFactory::GetForProfile(profile_);
+ if (!system_service)
return NULL;
std::vector<gdata::GDataOperationRegistry::ProgressStatus>
- list = file_system->GetProgressStatusList();
+ list = system_service->file_system()->GetProgressStatusList();
return file_manager_util::ProgressStatusVectorToListValue(
profile_, source_url_.GetOrigin(), list);
}
@@ -1826,9 +1832,9 @@ bool CancelFileTransfersFunction::RunImpl() {
void CancelFileTransfersFunction::GetLocalPathsResponseOnUIThread(
const SelectedFileInfoList& files) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- gdata::GDataFileSystem* file_system =
- gdata::GDataFileSystemFactory::GetForProfile(profile_);
- if (!file_system) {
+ gdata::GDataSystemService* system_service =
+ gdata::GDataSystemServiceFactory::GetForProfile(profile_);
+ if (!system_service) {
SendResponse(false);
return;
}
@@ -1838,7 +1844,9 @@ void CancelFileTransfersFunction::GetLocalPathsResponseOnUIThread(
DCHECK(gdata::util::IsUnderGDataMountPoint(files[i].path));
FilePath file_path = gdata::util::ExtractGDataPath(files[i].path);
scoped_ptr<DictionaryValue> result(new DictionaryValue());
- result->SetBoolean("canceled", file_system->CancelOperation(file_path));
+ result->SetBoolean(
+ "canceled",
+ system_service->file_system()->CancelOperation(file_path));
GURL file_url;
if (file_manager_util::ConvertFileToFileSystemUrl(profile_,
FilePath("gdata").Append(file_path),
diff --git a/chrome/browser/chromeos/gdata/gdata_file_system.cc b/chrome/browser/chromeos/gdata/gdata_file_system.cc
index c8c454d..0e153e9 100644
--- a/chrome/browser/chromeos/gdata/gdata_file_system.cc
+++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc
@@ -18,14 +18,10 @@
#include "base/platform_file.h"
#include "base/synchronization/waitable_event.h"
#include "base/values.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/gdata/gdata_documents_service.h"
#include "chrome/browser/chromeos/gdata/gdata_download_observer.h"
#include "chrome/browser/chromeos/gdata/gdata_sync_client.h"
-#include "chrome/browser/download/download_service.h"
-#include "chrome/browser/download/download_service_factory.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/profiles/profile_dependency_manager.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths_internal.h"
#include "content/public/browser/browser_thread.h"
@@ -575,17 +571,13 @@ GDataFileSystem::GetFileFromCacheParams::~GetFileFromCacheParams() {
// GDataFileSystem class implementatsion.
GDataFileSystem::GDataFileSystem(Profile* profile,
- DocumentsServiceInterface* documents_service,
- GDataSyncClientInterface* sync_client)
+ DocumentsServiceInterface* documents_service)
: profile_(profile),
documents_service_(documents_service),
- gdata_uploader_(new GDataUploader(ALLOW_THIS_IN_INITIALIZER_LIST(this))),
- gdata_download_observer_(new GDataDownloadObserver()),
on_cache_initialized_(new base::WaitableEvent(
true /* manual reset*/, false /* initially not signaled*/)),
cache_initialization_started_(false),
- weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
- sync_client_(sync_client) {
+ weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
// Should be created from the file browser extension API on UI thread.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
@@ -605,16 +597,7 @@ void GDataFileSystem::Initialize() {
cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDownloadsDir));
documents_service_->Initialize(profile_);
- sync_client_->Initialize(this);
-
- // download_manager will be NULL for unit tests.
- content::DownloadManager* download_manager =
- g_browser_process->download_status_updater() ?
- DownloadServiceFactory::GetForProfile(profile_)->GetDownloadManager() :
- NULL;
- gdata_download_observer_->Initialize(
- GetGDataTempDownloadFolderPath(),
- gdata_uploader_.get(), download_manager);
+
root_.reset(new GDataRootDirectory(this));
root_->set_file_name(kGDataRootDirectory);
}
@@ -2524,43 +2507,4 @@ void GDataFileSystem::GetFromCacheInternal(
base::MessageLoopProxy::current()));
}
-//========================= GDataFileSystemFactory =============================
-
-// static
-GDataFileSystem* GDataFileSystemFactory::GetForProfile(
- Profile* profile) {
- return static_cast<GDataFileSystem*>(
- GetInstance()->GetServiceForProfile(profile, true));
-}
-
-// static
-GDataFileSystem* GDataFileSystemFactory::FindForProfile(
- Profile* profile) {
- return static_cast<GDataFileSystem*>(
- GetInstance()->GetServiceForProfile(profile, false));
-}
-
-// static
-GDataFileSystemFactory* GDataFileSystemFactory::GetInstance() {
- return Singleton<GDataFileSystemFactory>::get();
-}
-
-GDataFileSystemFactory::GDataFileSystemFactory()
- : ProfileKeyedServiceFactory("GDataFileSystem",
- ProfileDependencyManager::GetInstance()) {
- DependsOn(DownloadServiceFactory::GetInstance());
-}
-
-GDataFileSystemFactory::~GDataFileSystemFactory() {
-}
-
-ProfileKeyedService* GDataFileSystemFactory::BuildServiceInstanceFor(
- Profile* profile) const {
- GDataFileSystem* file_system = new GDataFileSystem(profile,
- new DocumentsService,
- new GDataSyncClient);
- file_system->Initialize();
- return file_system;
-}
-
} // namespace gdata
diff --git a/chrome/browser/chromeos/gdata/gdata_file_system.h b/chrome/browser/chromeos/gdata/gdata_file_system.h
index b02565b..2c70bf4 100644
--- a/chrome/browser/chromeos/gdata/gdata_file_system.h
+++ b/chrome/browser/chromeos/gdata/gdata_file_system.h
@@ -33,8 +33,6 @@ class WaitableEvent;
namespace gdata {
class DocumentsServiceInterface;
-class GDataDownloadObserver;
-class GDataSyncClientInterface;
// Callback for completion of cache operation.
typedef base::Callback<void(base::PlatformFileError error,
@@ -341,11 +339,14 @@ class GDataFileSystemInterface {
};
// The production implementation of GDataFileSystemInterface.
-class GDataFileSystem : public GDataFileSystemInterface,
- public ProfileKeyedService {
+class GDataFileSystem : public GDataFileSystemInterface {
public:
- // ProfileKeyedService override:
- virtual void Shutdown() OVERRIDE;
+ GDataFileSystem(Profile* profile,
+ DocumentsServiceInterface* documents_service);
+ virtual ~GDataFileSystem();
+
+ // Shuts down the file system. All pending operations are canceled.
+ void Shutdown();
// GDataFileSystem overrides.
virtual void Initialize() OVERRIDE;
@@ -397,7 +398,6 @@ class GDataFileSystem : public GDataFileSystemInterface,
private:
friend class GDataUploader;
- friend class GDataFileSystemFactory;
friend class GDataFileSystemTest;
FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest,
FindFirstMissingParentDirectory);
@@ -460,11 +460,6 @@ class GDataFileSystem : public GDataFileSystemInterface,
const FilePath& file_path)>
FilePathUpdateCallback;
- GDataFileSystem(Profile* profile,
- DocumentsServiceInterface* documents_service,
- GDataSyncClientInterface* sync_client);
- virtual ~GDataFileSystem();
-
// Finds file object by |file_path| and returns the file info.
// Returns NULL if it does not find the file.
GDataFileBase* GetGDataFileInfoFromPath(const FilePath& file_path);
@@ -876,17 +871,12 @@ class GDataFileSystem : public GDataFileSystemInterface,
base::Lock lock_;
- // The profile hosts the GDataFileSystem.
+ // The profile hosts the GDataFileSystem via GDataSystemService.
Profile* profile_;
// The document service for the GDataFileSystem.
scoped_ptr<DocumentsServiceInterface> documents_service_;
- // File content uploader.
- scoped_ptr<GDataUploader> gdata_uploader_;
- // Downloads observer.
- scoped_ptr<GDataDownloadObserver> gdata_download_observer_;
-
// Base path for GData cache, e.g. <user_profile_dir>/user/GCache/v1.
FilePath gdata_cache_path_;
@@ -903,32 +893,6 @@ class GDataFileSystem : public GDataFileSystemInterface,
base::WeakPtrFactory<GDataFileSystem> weak_ptr_factory_;
ObserverList<Observer> observers_;
- scoped_ptr<GDataSyncClientInterface> sync_client_;
-};
-
-// Singleton that owns all GDataFileSystems and associates them with
-// Profiles.
-class GDataFileSystemFactory : public ProfileKeyedServiceFactory {
- public:
- // Returns the GDataFileSystem for |profile|, creating it if it is not
- // yet created.
- static GDataFileSystem* GetForProfile(Profile* profile);
- // Returns the GDataFileSystem that is already associated with |profile|,
- // if it is not yet created it will return NULL.
- static GDataFileSystem* FindForProfile(Profile* profile);
-
- // Returns the GDataFileSystemFactory instance.
- static GDataFileSystemFactory* GetInstance();
-
- private:
- friend struct DefaultSingletonTraits<GDataFileSystemFactory>;
-
- GDataFileSystemFactory();
- virtual ~GDataFileSystemFactory();
-
- // ProfileKeyedServiceFactory:
- virtual ProfileKeyedService* BuildServiceInstanceFor(
- Profile* profile) const OVERRIDE;
};
} // namespace gdata
diff --git a/chrome/browser/chromeos/gdata/gdata_file_system_proxy.cc b/chrome/browser/chromeos/gdata/gdata_file_system_proxy.cc
index 62a1b4d..a3a6417 100644
--- a/chrome/browser/chromeos/gdata/gdata_file_system_proxy.cc
+++ b/chrome/browser/chromeos/gdata/gdata_file_system_proxy.cc
@@ -11,6 +11,8 @@
#include "base/string_util.h"
#include "base/values.h"
#include "content/public/browser/browser_thread.h"
+#include "chrome/browser/chromeos/gdata/gdata_system_service.h"
+#include "chrome/browser/chromeos/gdata/gdata_file_system.h"
#include "webkit/blob/shareable_file_reference.h"
#include "webkit/fileapi/file_system_file_util_proxy.h"
#include "webkit/fileapi/file_system_types.h"
@@ -68,8 +70,9 @@ base::FileUtilProxy::Entry GDataFileToFileUtilProxyEntry(
// GDataFileSystemProxy class implementation.
-GDataFileSystemProxy::GDataFileSystemProxy(Profile* profile)
- : file_system_(GDataFileSystemFactory::GetForProfile(profile)) {
+GDataFileSystemProxy::GDataFileSystemProxy(
+ GDataFileSystemInterface* file_system)
+ : file_system_(file_system) {
// Should be created from the file browser extension API (AddMountFunction)
// on UI thread.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
diff --git a/chrome/browser/chromeos/gdata/gdata_file_system_proxy.h b/chrome/browser/chromeos/gdata/gdata_file_system_proxy.h
index 6a23fdd..049a20b 100644
--- a/chrome/browser/chromeos/gdata/gdata_file_system_proxy.h
+++ b/chrome/browser/chromeos/gdata/gdata_file_system_proxy.h
@@ -5,19 +5,21 @@
#ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_PROXY_H_
#define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_PROXY_H_
-#include "chrome/browser/chromeos/gdata/gdata_file_system.h"
#include "webkit/chromeos/fileapi/remote_file_system_proxy.h"
class Profile;
namespace gdata {
+class GDataFileBase;
+class GDataFileSystemInterface;
+
// The interface class for remote file system proxy.
class GDataFileSystemProxy : public fileapi::RemoteFileSystemProxyInterface {
public:
// |profile| is used to create GDataFileSystem, which is a per-profile
// instance.
- explicit GDataFileSystemProxy(Profile* profile);
+ explicit GDataFileSystemProxy(GDataFileSystemInterface* file_system);
virtual ~GDataFileSystemProxy();
// fileapi::RemoteFileSystemProxyInterface overrides.
@@ -83,7 +85,7 @@ class GDataFileSystemProxy : public fileapi::RemoteFileSystemProxyInterface {
// GDataFileSystemProxy, which is owned by CrosMountPointProvider (i.e. by
// the time Profile is removed, the file manager is already gone). Hence
// it's safe to use this as a raw pointer.
- GDataFileSystem* file_system_;
+ GDataFileSystemInterface* file_system_;
};
} // namespace chromeos
diff --git a/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc b/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc
index 519d4da..d5d8ed8 100644
--- a/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc
+++ b/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc
@@ -91,22 +91,19 @@ class GDataFileSystemTest : public testing::Test {
callback_helper_ = new CallbackHelper;
- // Allocate and keep pointers to the mocks, and inject them into the
- // GDataFileSystem object, which will own the mock objects.
+ // Allocate and keep a pointer to the mock, and inject it into the
+ // GDataFileSystem object, which will own the mock object.
mock_doc_service_ = new MockDocumentsService;
- mock_sync_client_ = new MockGDataSyncClient;
EXPECT_CALL(*mock_doc_service_, Initialize(profile_.get())).Times(1);
ASSERT_FALSE(file_system_);
file_system_ = new GDataFileSystem(profile_.get(),
- mock_doc_service_,
- mock_sync_client_);
-
- // Initialize() is called inside file_system_->Initialize().
- EXPECT_CALL(*mock_sync_client_, Initialize(file_system_)).Times(1);
+ mock_doc_service_);
file_system_->Initialize();
- file_system_->AddObserver(mock_sync_client_);
+
+ mock_sync_client_.reset(new MockGDataSyncClient);
+ file_system_->AddObserver(mock_sync_client_.get());
RunAllPendingForCache();
}
@@ -570,7 +567,7 @@ class GDataFileSystemTest : public testing::Test {
scoped_refptr<CallbackHelper> callback_helper_;
GDataFileSystem* file_system_;
MockDocumentsService* mock_doc_service_;
- MockGDataSyncClient* mock_sync_client_;
+ scoped_ptr<MockGDataSyncClient> mock_sync_client_;
int num_callback_invocations_;
base::PlatformFileError expected_error_;
diff --git a/chrome/browser/chromeos/gdata/gdata_sync_client.cc b/chrome/browser/chromeos/gdata/gdata_sync_client.cc
index a28b790..6b961c6 100644
--- a/chrome/browser/chromeos/gdata/gdata_sync_client.cc
+++ b/chrome/browser/chromeos/gdata/gdata_sync_client.cc
@@ -65,8 +65,8 @@ void ScanPinnedDirectory(const FilePath& directory,
} // namespace
-GDataSyncClient::GDataSyncClient()
- : file_system_(NULL),
+GDataSyncClient::GDataSyncClient(GDataFileSystemInterface* file_system)
+ : file_system_(file_system),
weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
@@ -77,10 +77,9 @@ GDataSyncClient::~GDataSyncClient() {
file_system_->RemoveObserver(this);
}
-void GDataSyncClient::Initialize(GDataFileSystemInterface* file_system) {
+void GDataSyncClient::Initialize() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- file_system_ = file_system;
file_system_->AddObserver(this);
}
diff --git a/chrome/browser/chromeos/gdata/gdata_sync_client.h b/chrome/browser/chromeos/gdata/gdata_sync_client.h
index 0f5111b..b40e355 100644
--- a/chrome/browser/chromeos/gdata/gdata_sync_client.h
+++ b/chrome/browser/chromeos/gdata/gdata_sync_client.h
@@ -37,9 +37,8 @@ namespace gdata {
// The interface class is defined to make GDataSyncClient mockable.
class GDataSyncClientInterface : public GDataFileSystem::Observer {
public:
- // Initializes the GDataSyncClient. |file_system| is used to access to the
- // cache (ex. store a file to the cache when the file is downloaded).
- virtual void Initialize(GDataFileSystemInterface* file_system) = 0;
+ // Initializes the GDataSyncClient.
+ virtual void Initialize() = 0;
virtual ~GDataSyncClientInterface() {}
};
@@ -47,11 +46,13 @@ class GDataSyncClientInterface : public GDataFileSystem::Observer {
// The production implementation of GDataSyncClientInterface.
class GDataSyncClient : public GDataSyncClientInterface {
public:
- GDataSyncClient();
+ // |file_system| is used to access to the
+ // cache (ex. store a file to the cache when the file is downloaded).
+ explicit GDataSyncClient(GDataFileSystemInterface* file_system);
virtual ~GDataSyncClient();
// GDataSyncClientInterface overrides.
- virtual void Initialize(GDataFileSystemInterface* file_system) OVERRIDE;
+ virtual void Initialize() OVERRIDE;
// GDataFileSystem::Observer overrides.
virtual void OnCacheInitialized() OVERRIDE;
diff --git a/chrome/browser/chromeos/gdata/gdata_sync_client_unittest.cc b/chrome/browser/chromeos/gdata/gdata_sync_client_unittest.cc
index 1bb872d..bd4a5e9 100644
--- a/chrome/browser/chromeos/gdata/gdata_sync_client_unittest.cc
+++ b/chrome/browser/chromeos/gdata/gdata_sync_client_unittest.cc
@@ -26,7 +26,7 @@ class GDataSyncClientTest : public testing::Test {
GDataSyncClientTest()
: ui_thread_(content::BrowserThread::UI, &message_loop_),
mock_file_system_(new MockGDataFileSystem),
- sync_client_(new GDataSyncClient) {
+ sync_client_(new GDataSyncClient(mock_file_system_.get())) {
}
virtual void SetUp() OVERRIDE {
@@ -40,7 +40,7 @@ class GDataSyncClientTest : public testing::Test {
EXPECT_CALL(*mock_file_system_, RemoveObserver(sync_client_.get()))
.Times(1);
- sync_client_->Initialize(mock_file_system_.get());
+ sync_client_->Initialize();
}
MessageLoopForUI message_loop_;
diff --git a/chrome/browser/chromeos/gdata/gdata_system_service.cc b/chrome/browser/chromeos/gdata/gdata_system_service.cc
new file mode 100644
index 0000000..c95aa76
--- /dev/null
+++ b/chrome/browser/chromeos/gdata/gdata_system_service.cc
@@ -0,0 +1,86 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/gdata/gdata_system_service.h"
+
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/download/download_service.h"
+#include "chrome/browser/download/download_service_factory.h"
+#include "chrome/browser/chromeos/gdata/gdata_documents_service.h"
+#include "chrome/browser/chromeos/gdata/gdata_download_observer.h"
+#include "chrome/browser/chromeos/gdata/gdata_file_system.h"
+#include "chrome/browser/chromeos/gdata/gdata_sync_client.h"
+#include "chrome/browser/chromeos/gdata/gdata_uploader.h"
+#include "chrome/browser/profiles/profile_dependency_manager.h"
+
+namespace gdata {
+
+//===================== GDataSystemService ====================================
+GDataSystemService::GDataSystemService(Profile* profile)
+ : profile_(profile),
+ file_system_(new GDataFileSystem(profile, new DocumentsService)),
+ uploader_(new GDataUploader(file_system_.get())),
+ download_observer_(new GDataDownloadObserver),
+ sync_client_(new GDataSyncClient(file_system_.get())) {
+}
+
+GDataSystemService::~GDataSystemService() {
+}
+
+void GDataSystemService::Initialize() {
+ file_system_->Initialize();
+
+ content::DownloadManager* download_manager =
+ g_browser_process->download_status_updater() ?
+ DownloadServiceFactory::GetForProfile(profile_)->GetDownloadManager() :
+ NULL;
+ download_observer_->Initialize(
+ file_system_->GetGDataTempDownloadFolderPath(),
+ uploader_.get(), download_manager);
+
+ sync_client_->Initialize();
+}
+
+void GDataSystemService::Shutdown() {
+ file_system_->Shutdown();
+}
+
+//===================== GDataSystemServiceFactory =============================
+
+// static
+GDataSystemService* GDataSystemServiceFactory::GetForProfile(
+ Profile* profile) {
+ return static_cast<GDataSystemService*>(
+ GetInstance()->GetServiceForProfile(profile, true));
+}
+
+// static
+GDataSystemService* GDataSystemServiceFactory::FindForProfile(
+ Profile* profile) {
+ return static_cast<GDataSystemService*>(
+ GetInstance()->GetServiceForProfile(profile, false));
+}
+
+// static
+GDataSystemServiceFactory* GDataSystemServiceFactory::GetInstance() {
+ return Singleton<GDataSystemServiceFactory>::get();
+}
+
+GDataSystemServiceFactory::GDataSystemServiceFactory()
+ : ProfileKeyedServiceFactory("GDataSystemService",
+ ProfileDependencyManager::GetInstance()) {
+ DependsOn(DownloadServiceFactory::GetInstance());
+}
+
+GDataSystemServiceFactory::~GDataSystemServiceFactory() {
+}
+
+ProfileKeyedService* GDataSystemServiceFactory::BuildServiceInstanceFor(
+ Profile* profile) const {
+ GDataSystemService* service = new GDataSystemService(profile);
+ service->Initialize();
+ return service;
+}
+
+} // namespace gdata
diff --git a/chrome/browser/chromeos/gdata/gdata_system_service.h b/chrome/browser/chromeos/gdata/gdata_system_service.h
new file mode 100644
index 0000000..86754bb
--- /dev/null
+++ b/chrome/browser/chromeos/gdata/gdata_system_service.h
@@ -0,0 +1,81 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_SYSTEM_SERVICE_H_
+#define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_SYSTEM_SERVICE_H_
+#pragma once
+
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/chromeos/gdata/gdata_file_system.h"
+#include "chrome/browser/profiles/profile_keyed_service.h"
+#include "chrome/browser/profiles/profile_keyed_service_factory.h"
+
+namespace gdata {
+
+class GDataDownloadObserver;
+class GDataFileSystem;
+class GDataSyncClient;
+class GDataUploader;
+
+// GDataSystemService runs the GData system, including the GData file system
+// implementation for the file manager, and some other sub systems.
+//
+// The class is essentially a container that manages lifetime of the objects
+// that are used to run the GData system. The GDataSystemService object is
+// created per-profile.
+class GDataSystemService : public ProfileKeyedService {
+ public:
+ // Returns the file system instance.
+ GDataFileSystem* file_system() { return file_system_.get(); }
+
+ // ProfileKeyedService override:
+ virtual void Shutdown() OVERRIDE;
+
+ private:
+ explicit GDataSystemService(Profile* profile);
+ virtual ~GDataSystemService();
+
+ // Initializes the object. This function should be called before any
+ // other functions.
+ void Initialize();
+
+ friend class GDataSystemServiceFactory;
+
+ Profile* profile_;
+ scoped_ptr<GDataFileSystem> file_system_;
+ scoped_ptr<GDataUploader> uploader_;
+ scoped_ptr<GDataDownloadObserver> download_observer_;
+ scoped_ptr<GDataSyncClient> sync_client_;
+
+ DISALLOW_COPY_AND_ASSIGN(GDataSystemService);
+};
+
+// Singleton that owns all GDataSystemServices and associates them with
+// Profiles.
+class GDataSystemServiceFactory : public ProfileKeyedServiceFactory {
+ public:
+ // Returns the GDataSystemService for |profile|, creating it if it is not
+ // yet created.
+ static GDataSystemService* GetForProfile(Profile* profile);
+ // Returns the GDataSystemService that is already associated with |profile|,
+ // if it is not yet created it will return NULL.
+ static GDataSystemService* FindForProfile(Profile* profile);
+
+ // Returns the GDataSystemServiceFactory instance.
+ static GDataSystemServiceFactory* GetInstance();
+
+ private:
+ friend struct DefaultSingletonTraits<GDataSystemServiceFactory>;
+
+ GDataSystemServiceFactory();
+ virtual ~GDataSystemServiceFactory();
+
+ // ProfileKeyedServiceFactory:
+ virtual ProfileKeyedService* BuildServiceInstanceFor(
+ Profile* profile) const OVERRIDE;
+};
+
+} // namespace gdata
+
+#endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_SYSTEM_SERVICE_H_
diff --git a/chrome/browser/chromeos/gdata/mock_gdata_sync_client.h b/chrome/browser/chromeos/gdata/mock_gdata_sync_client.h
index e870ff2..bc0bfd4 100644
--- a/chrome/browser/chromeos/gdata/mock_gdata_sync_client.h
+++ b/chrome/browser/chromeos/gdata/mock_gdata_sync_client.h
@@ -18,7 +18,7 @@ class MockGDataSyncClient : public GDataSyncClientInterface {
MockGDataSyncClient();
virtual ~MockGDataSyncClient();
- MOCK_METHOD1(Initialize, void(GDataFileSystemInterface* file_system));
+ MOCK_METHOD0(Initialize, void());
MOCK_METHOD0(OnCacheInitialized, void());
MOCK_METHOD2(OnFilePinned, void(const std::string& resource_id,
const std::string& md5));
diff --git a/chrome/browser/download/download_file_picker_chromeos.cc b/chrome/browser/download/download_file_picker_chromeos.cc
index 560b2b5..a538301 100644
--- a/chrome/browser/download/download_file_picker_chromeos.cc
+++ b/chrome/browser/download/download_file_picker_chromeos.cc
@@ -13,6 +13,7 @@
#include "content/public/browser/download_manager.h"
#include "chrome/browser/chromeos/gdata/gdata_download_observer.h"
#include "chrome/browser/chromeos/gdata/gdata_file_system.h"
+#include "chrome/browser/chromeos/gdata/gdata_system_service.h"
#include "chrome/browser/chromeos/gdata/gdata_util.h"
#include "chrome/browser/profiles/profile_manager.h"
@@ -68,10 +69,10 @@ void DownloadFilePickerChromeOS::FileSelected(const FilePath& path,
RecordFileSelected(path);
if (download_manager_) {
- gdata::GDataFileSystem* file_system =
- gdata::GDataFileSystemFactory::GetForProfile(
+ gdata::GDataSystemService* system_service =
+ gdata::GDataSystemServiceFactory::GetForProfile(
ProfileManager::GetDefaultProfile());
- if (file_system && gdata::util::IsUnderGDataMountPoint(path)) {
+ if (system_service && gdata::util::IsUnderGDataMountPoint(path)) {
// If we're trying to download a file into gdata, save path in external
// data.
content::DownloadItem* download =
@@ -81,7 +82,7 @@ void DownloadFilePickerChromeOS::FileSelected(const FilePath& path,
download->SetDisplayName(path.BaseName());
const FilePath download_cache_path =
- file_system->GetGDataTempDownloadFolderPath();
+ system_service->file_system()->GetGDataTempDownloadFolderPath();
// Swap the gdata path with a local path. Local path must be created
// on the IO thread pool.
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index fb6e534..a6ae242 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -552,6 +552,8 @@
'browser/chromeos/gdata/gdata_parser.h',
'browser/chromeos/gdata/gdata_sync_client.cc',
'browser/chromeos/gdata/gdata_sync_client.h',
+ 'browser/chromeos/gdata/gdata_system_service.cc',
+ 'browser/chromeos/gdata/gdata_system_service.h',
'browser/chromeos/gdata/gdata_uploader.cc',
'browser/chromeos/gdata/gdata_uploader.h',
'browser/chromeos/gdata/gdata_upload_file_info.cc',