#include "base/stl_util.h"
#include "chrome/browser/apps/drive/drive_app_converter.h"
#include "chrome/browser/apps/drive/drive_app_mapping.h"
+#include "chrome/browser/apps/drive/drive_app_uninstall_sync_service.h"
#include "chrome/browser/apps/drive/drive_service_bridge.h"
#include "chrome/browser/drive/drive_app_registry.h"
#include "chrome/browser/extensions/extension_service.h"
} // namespace
-DriveAppProvider::DriveAppProvider(Profile* profile)
+DriveAppProvider::DriveAppProvider(
+ Profile* profile,
+ DriveAppUninstallSyncService* uninstall_sync_service)
: profile_(profile),
+ uninstall_sync_service_(uninstall_sync_service),
service_bridge_(DriveServiceBridge::Create(profile).Pass()),
mapping_(new DriveAppMapping(profile->GetPrefs())),
weak_ptr_factory_(this) {
service_bridge_->GetAppRegistry()->AddObserver(this);
}
+void DriveAppProvider::AddUninstalledDriveAppFromSync(
+ const std::string& drive_app_id) {
+ mapping_->AddUninstalledDriveApp(drive_app_id);
+
+ // Decouple the operation because this function could be called during
+ // sync processing and UpdateDriveApps could trigger another sync change.
+ // See http://crbug.com/429205
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&DriveAppProvider::UpdateDriveApps,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void DriveAppProvider::RemoveUninstalledDriveAppFromSync(
+ const std::string& drive_app_id) {
+ mapping_->RemoveUninstalledDriveApp(drive_app_id);
+
+ // Decouple the operation because this function could be called during
+ // sync processing and UpdateDriveApps could trigger another sync change.
+ // See http://crbug.com/429205
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&DriveAppProvider::UpdateDriveApps,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
void DriveAppProvider::UpdateMappingAndExtensionSystem(
const std::string& drive_app_id,
const Extension* new_app,
if (!app)
return;
+ // Remove uninstall tracking for user installed app.
+ mapping_->RemoveUninstalledDriveApp(drive_app_id);
+ uninstall_sync_service_->UntrackUninstalledDriveApp(drive_app_id);
+
UpdateMappingAndExtensionSystem(drive_app_id, app, false);
}
NULL);
}
-void DriveAppProvider::OnDriveAppRegistryUpdated() {
+void DriveAppProvider::UpdateDriveApps() {
service_bridge_->GetAppRegistry()->GetAppList(&drive_apps_);
IdSet current_ids;
- for (size_t i = 0; i < drive_apps_.size(); ++i)
- current_ids.insert(drive_apps_[i].app_id);
+ for (size_t i = 0; i < drive_apps_.size(); ++i) {
+ const std::string& drive_app_id = drive_apps_[i].app_id;
+ if (!mapping_->IsUninstalledDriveApp(drive_app_id))
+ current_ids.insert(drive_app_id);
+ }
const IdSet existing_ids = mapping_->GetDriveAppIds();
const IdSet ids_to_remove =
}
for (size_t i = 0; i < drive_apps_.size(); ++i) {
- AddOrUpdateDriveApp(drive_apps_[i]);
+ if (!mapping_->IsUninstalledDriveApp(drive_apps_[i].app_id))
+ AddOrUpdateDriveApp(drive_apps_[i]);
}
SchedulePendingConverters();
}
+void DriveAppProvider::OnDriveAppRegistryUpdated() {
+ UpdateDriveApps();
+}
+
void DriveAppProvider::OnExtensionInstalled(
content::BrowserContext* browser_context,
const Extension* extension,
if (drive_app_id.empty())
return;
- service_bridge_->GetAppRegistry()->UninstallApp(
- drive_app_id, base::Bind(&IgnoreUninstallResult));
+ for (size_t i = 0; i < drive_apps_.size(); ++i) {
+ if (drive_apps_[i].app_id != drive_app_id)
+ continue;
+
+ if (drive_apps_[i].is_removable) {
+ service_bridge_->GetAppRegistry()->UninstallApp(
+ drive_app_id, base::Bind(&IgnoreUninstallResult));
+ } else {
+ mapping_->AddUninstalledDriveApp(drive_app_id);
+ uninstall_sync_service_->TrackUninstalledDriveApp(drive_app_id);
+ }
+
+ return;
+ }
}