#include "chrome/browser/sync_file_system/local/local_file_sync_service.h"
#include "base/stl_util.h"
-#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync_file_system/file_change.h"
#include "chrome/browser/sync_file_system/local/local_file_change_tracker.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/storage_partition.h"
+#include "extensions/browser/extension_registry.h"
+#include "extensions/common/extension_set.h"
#include "url/gurl.h"
#include "webkit/browser/fileapi/file_system_context.h"
#include "webkit/browser/fileapi/file_system_url.h"
// LocalFileSyncService -------------------------------------------------------
-LocalFileSyncService::LocalFileSyncService(Profile* profile)
- : profile_(profile),
- sync_context_(new LocalFileSyncContext(
- profile_->GetPath(),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI).get(),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)
- .get())),
- local_change_processor_(NULL) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- sync_context_->AddOriginChangeObserver(this);
+scoped_ptr<LocalFileSyncService> LocalFileSyncService::Create(
+ Profile* profile) {
+ return make_scoped_ptr(new LocalFileSyncService(profile, NULL));
+}
+
+scoped_ptr<LocalFileSyncService> LocalFileSyncService::CreateForTesting(
+ Profile* profile,
+ leveldb::Env* env) {
+ return make_scoped_ptr(new LocalFileSyncService(profile, env));
}
LocalFileSyncService::~LocalFileSyncService() {
void LocalFileSyncService::ProcessLocalChange(
const SyncFileCallback& callback) {
- DCHECK(local_change_processor_);
// Pick an origin to process next.
GURL origin;
if (!origin_change_map_.NextOriginToProcess(&origin)) {
}
void LocalFileSyncService::SetLocalChangeProcessor(
- LocalChangeProcessor* processor) {
- local_change_processor_ = processor;
+ LocalChangeProcessor* local_change_processor) {
+ local_change_processor_ = local_change_processor;
+}
+
+void LocalFileSyncService::SetLocalChangeProcessorCallback(
+ const GetLocalChangeProcessorCallback& get_local_change_processor) {
+ get_local_change_processor_ = get_local_change_processor;
}
void LocalFileSyncService::HasPendingLocalChanges(
origin_to_contexts_[url.origin()], url, callback);
}
+void LocalFileSyncService::PromoteDemotedChanges() {
+ for (OriginToContext::iterator iter = origin_to_contexts_.begin();
+ iter != origin_to_contexts_.end(); ++iter)
+ sync_context_->PromoteDemotedChanges(iter->first, iter->second);
+}
+
void LocalFileSyncService::GetLocalFileMetadata(
const FileSystemURL& url, const SyncFileMetadataCallback& callback) {
DCHECK(ContainsKey(origin_to_contexts_, url.origin()));
// been initialized in this service.
DCHECK(profile_);
// The given url.origin() must be for valid installed app.
- ExtensionService* extension_service =
- extensions::ExtensionSystem::Get(profile_)->extension_service();
- const extensions::Extension* extension = extension_service->GetInstalledApp(
- url.origin());
+ const extensions::Extension* extension =
+ extensions::ExtensionRegistry::Get(profile_)
+ ->enabled_extensions().GetAppByURL(url.origin());
if (!extension) {
util::Log(
logging::LOG_WARNING,
SyncFileMetadata(), FileChangeList());
return;
}
- GURL site_url = extension_service->GetSiteForExtensionId(extension->id());
+ GURL site_url =
+ extensions::util::GetSiteForExtensionId(extension->id(), profile_);
DCHECK(!site_url.is_empty());
scoped_refptr<fileapi::FileSystemContext> file_system_context =
content::BrowserContext::GetStoragePartitionForSite(
const FileSystemURL& url,
const SyncStatusCallback& callback) {
DCHECK(ContainsKey(origin_to_contexts_, url.origin()));
+ util::Log(logging::LOG_VERBOSE, FROM_HERE,
+ "[Remote -> Local] ApplyRemoteChange: %s on %s",
+ change.DebugString().c_str(),
+ url.DebugString().c_str());
+
sync_context_->ApplyRemoteChange(
origin_to_contexts_[url.origin()],
- change, local_path, url, callback);
+ change, local_path, url,
+ base::Bind(&LocalFileSyncService::DidApplyRemoteChange, AsWeakPtr(),
+ callback));
}
void LocalFileSyncService::FinalizeRemoteSync(
origin_change_map_.SetOriginEnabled(origin, enabled);
}
+LocalFileSyncService::LocalFileSyncService(Profile* profile,
+ leveldb::Env* env_override)
+ : profile_(profile),
+ sync_context_(new LocalFileSyncContext(
+ profile_->GetPath(),
+ env_override,
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI).get(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)
+ .get())),
+ local_change_processor_(NULL) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ sync_context_->AddOriginChangeObserver(this);
+}
+
void LocalFileSyncService::DidInitializeFileSystemContext(
const GURL& app_origin,
fileapi::FileSystemContext* file_system_context,
callback.Run(status, url);
}
+void LocalFileSyncService::DidApplyRemoteChange(
+ const SyncStatusCallback& callback,
+ SyncStatusCode status) {
+ util::Log(logging::LOG_VERBOSE, FROM_HERE,
+ "[Remote -> Local] ApplyRemoteChange finished --> %s",
+ SyncStatusCodeToString(status));
+ callback.Run(status);
+}
+
void LocalFileSyncService::DidGetFileForLocalSync(
SyncStatusCode status,
const LocalFileSyncInfo& sync_file_info,
DVLOG(1) << "ProcessLocalChange: " << sync_file_info.url.DebugString()
<< " change:" << next_change.DebugString();
- local_change_processor_->ApplyLocalChange(
+ GetLocalChangeProcessor(sync_file_info.url)->ApplyLocalChange(
next_change,
sync_file_info.local_file_path,
sync_file_info.metadata,
<< " status:" << status;
if (status == SYNC_STATUS_RETRY) {
- local_change_processor_->ApplyLocalChange(
+ GetLocalChangeProcessor(sync_file_info.url)->ApplyLocalChange(
processed_change,
sync_file_info.local_file_path,
sync_file_info.metadata,
}
FileChange next_change = changes.front();
- local_change_processor_->ApplyLocalChange(
+ GetLocalChangeProcessor(url)->ApplyLocalChange(
changes.front(),
sync_file_info.local_file_path,
sync_file_info.metadata,
next_change, changes.PopAndGetNewList()));
}
+LocalChangeProcessor* LocalFileSyncService::GetLocalChangeProcessor(
+ const FileSystemURL& url) {
+ if (!get_local_change_processor_.is_null())
+ return get_local_change_processor_.Run(url.origin());
+ DCHECK(local_change_processor_);
+ return local_change_processor_;
+}
+
} // namespace sync_file_system