Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3315)

Unified Diff: chrome/browser/sync_file_system/drive_backend/sync_worker.cc

Issue 246163005: [SyncFS] Make ExtensionService usage of SyncWorker asynchronous (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: buildfix Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync_file_system/drive_backend/sync_worker.cc
diff --git a/chrome/browser/sync_file_system/drive_backend/sync_worker.cc b/chrome/browser/sync_file_system/drive_backend/sync_worker.cc
index 72df95350e1092e50a170763771f2e658b03510a..928e0f0cb8b55592ace030e7efd3230a3c44fa2c 100644
--- a/chrome/browser/sync_file_system/drive_backend/sync_worker.cc
+++ b/chrome/browser/sync_file_system/drive_backend/sync_worker.cc
@@ -19,6 +19,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
+#include "chrome/browser/sync_file_system/drive_backend/callback_helper.h"
#include "chrome/browser/sync_file_system/drive_backend/conflict_resolver.h"
#include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.h"
#include "chrome/browser/sync_file_system/drive_backend/list_changes_task.h"
@@ -60,7 +61,7 @@ void EmptyStatusCallback(SyncStatusCode status) {}
scoped_ptr<SyncWorker> SyncWorker::CreateOnWorker(
const base::FilePath& base_dir,
Observer* observer,
- ExtensionServiceInterface* extension_service,
+ const base::WeakPtr<ExtensionServiceInterface>& extension_service,
scoped_ptr<SyncEngineContext> sync_engine_context,
leveldb::Env* env_override) {
scoped_ptr<SyncWorker> sync_worker(
@@ -355,7 +356,7 @@ void SyncWorker::AddObserver(Observer* observer) {
SyncWorker::SyncWorker(
const base::FilePath& base_dir,
- ExtensionServiceInterface* extension_service,
+ const base::WeakPtr<ExtensionServiceInterface>& extension_service,
scoped_ptr<SyncEngineContext> sync_engine_context,
leveldb::Env* env_override)
: base_dir_(base_dir),
@@ -433,47 +434,85 @@ void SyncWorker::DidInitialize(SyncEngineInitializer* initializer,
}
void SyncWorker::UpdateRegisteredApp() {
- if (extension_service_)
+ MetadataDatabase* metadata_db = GetMetadataDatabase();
+ DCHECK(metadata_db);
+
peria 2014/04/24 02:38:21 Could you add checking |extension_service_|'s avai
tzik 2014/04/24 06:56:55 To do that, we need to hop to UI thread, which cos
+ scoped_ptr<std::vector<std::string> > app_ids(new std::vector<std::string>);
+ metadata_db->GetRegisteredAppIDs(app_ids.get());
+
+ AppStatusMap* app_status = new AppStatusMap;
+ base::Closure callback =
+ base::Bind(&SyncWorker::DidQueryAppStatus,
+ weak_ptr_factory_.GetWeakPtr(),
+ base::Owned(app_status));
+
+ context_->GetUiTaskRunner()->PostTask(
+ FROM_HERE,
+ base::Bind(&SyncWorker::QueryAppStatusOnUIThread,
+ extension_service_,
+ base::Owned(app_ids.release()),
+ app_status,
+ CreateRelayedCallback(callback)));
+
nhiroki 2014/04/24 01:39:52 nit: an extra blank line.
tzik 2014/04/24 06:56:55 Done.
+}
+
+// static
+void SyncWorker::QueryAppStatusOnUIThread(
nhiroki 2014/04/24 01:39:52 (optional) How about moving this into anon namespa
tzik 2014/04/24 06:56:55 Done.
nhiroki 2014/04/24 07:09:07 Hmm... sorry, I missed QueryAppStatusOnUIThread()
+ const base::WeakPtr<ExtensionServiceInterface>& extension_service_ptr,
+ const std::vector<std::string>* apps,
peria 2014/04/24 02:38:21 (optional) keep its name |app_ids| for consistency
tzik 2014/04/24 06:56:55 Done.
+ AppStatusMap* status,
+ const base::Closure& callback) {
+ ExtensionServiceInterface* extension_service = extension_service_ptr.get();
+ if (!extension_service)
nhiroki 2014/04/24 01:39:52 In this case you don't need to run a callback, rig
tzik 2014/04/24 06:56:55 Ah, I completely forgot about calling the callback
return;
+ for (std::vector<std::string>::const_iterator itr = apps->begin();
+ itr != apps->end(); ++itr) {
+ const std::string& app_id = *itr;
+ if (!extension_service->GetInstalledExtension(app_id))
+ (*status)[app_id] = APP_STATUS_UNINSTALLED;
+ else if (!extension_service->IsExtensionEnabled(app_id))
+ (*status)[app_id] = APP_STATUS_DISABLED;
+ else
+ (*status)[app_id] = APP_STATUS_ENABLED;
+ }
nhiroki 2014/04/24 01:39:52 You need to run |callback| here.
tzik 2014/04/24 06:56:55 Done.
+}
+
+void SyncWorker::DidQueryAppStatus(const AppStatusMap* app_status) {
MetadataDatabase* metadata_db = GetMetadataDatabase();
DCHECK(metadata_db);
- std::vector<std::string> app_ids;
- metadata_db->GetRegisteredAppIDs(&app_ids);
// Update the status of every origin using status from ExtensionService.
- for (std::vector<std::string>::const_iterator itr = app_ids.begin();
- itr != app_ids.end(); ++itr) {
- const std::string& app_id = *itr;
- GURL origin =
- extensions::Extension::GetBaseURLFromExtensionId(app_id);
-
- // TODO(tzik): Switch |extension_service_| to a wrapper and make this
- // call async.
- if (!extension_service_->GetInstalledExtension(app_id)) {
- // Extension has been uninstalled.
- // (At this stage we can't know if it was unpacked extension or not,
- // so just purge the remote folder.)
- UninstallOrigin(origin,
- RemoteFileSyncService::UNINSTALL_AND_PURGE_REMOTE,
- base::Bind(&EmptyStatusCallback));
- continue;
- }
- FileTracker tracker;
- if (!metadata_db->FindAppRootTracker(app_id, &tracker)) {
- // App will register itself on first run.
- continue;
- }
-
- // TODO(tzik): Switch |extension_service_| to a wrapper and make this
- // call async.
- bool is_app_enabled = extension_service_->IsExtensionEnabled(app_id);
- bool is_app_root_tracker_enabled =
- tracker.tracker_kind() == TRACKER_KIND_APP_ROOT;
- if (is_app_enabled && !is_app_root_tracker_enabled)
- EnableOrigin(origin, base::Bind(&EmptyStatusCallback));
- else if (!is_app_enabled && is_app_root_tracker_enabled)
- DisableOrigin(origin, base::Bind(&EmptyStatusCallback));
+ for (AppStatusMap::const_iterator itr = app_status->begin();
+ itr != app_status->end(); ++itr) {
+ const std::string& app_id = itr->first;
+ GURL origin = extensions::Extension::GetBaseURLFromExtensionId(app_id);
+
+ if (itr->second == APP_STATUS_UNINSTALLED) {
+ // Extension has been uninstalled.
+ // (At this stage we can't know if it was unpacked extension or not,
+ // so just purge the remote folder.)
+ UninstallOrigin(origin,
+ RemoteFileSyncService::UNINSTALL_AND_PURGE_REMOTE,
+ base::Bind(&EmptyStatusCallback));
+ continue;
+ }
+
+ FileTracker tracker;
+ if (!metadata_db->FindAppRootTracker(app_id, &tracker)) {
+ // App will register itself on first run.
+ continue;
+ }
+
+ DCHECK(itr->second == APP_STATUS_ENABLED ||
+ itr->second == APP_STATUS_DISABLED);
+ bool is_app_enabled = itr->second == APP_STATUS_ENABLED;
peria 2014/04/24 02:38:21 nit: a = (b == c);
tzik 2014/04/24 06:56:55 Done.
+ bool is_app_root_tracker_enabled =
+ tracker.tracker_kind() == TRACKER_KIND_APP_ROOT;
peria 2014/04/24 02:38:21 diito
tzik 2014/04/24 06:56:55 Done.
+ if (is_app_enabled && !is_app_root_tracker_enabled)
+ EnableOrigin(origin, base::Bind(&EmptyStatusCallback));
+ else if (!is_app_enabled && is_app_root_tracker_enabled)
+ DisableOrigin(origin, base::Bind(&EmptyStatusCallback));
}
}

Powered by Google App Engine
This is Rietveld 408576698