| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/extension_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 | 756 |
| 757 UntrackTerminatedExtension(extension_id); | 757 UntrackTerminatedExtension(extension_id); |
| 758 | 758 |
| 759 // Notify interested parties that we've uninstalled this extension. | 759 // Notify interested parties that we've uninstalled this extension. |
| 760 content::NotificationService::current()->Notify( | 760 content::NotificationService::current()->Notify( |
| 761 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 761 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
| 762 content::Source<Profile>(profile_), | 762 content::Source<Profile>(profile_), |
| 763 content::Details<const std::string>(&extension_id)); | 763 content::Details<const std::string>(&extension_id)); |
| 764 | 764 |
| 765 if (app_sync_bundle_.HasExtensionId(extension_id) && | 765 if (app_sync_bundle_.HasExtensionId(extension_id) && |
| 766 sync_change.sync_data().GetDataType() == syncable::APPS) { | 766 sync_change.sync_data().GetDataType() == syncer::APPS) { |
| 767 app_sync_bundle_.ProcessDeletion(extension_id, sync_change); | 767 app_sync_bundle_.ProcessDeletion(extension_id, sync_change); |
| 768 } else if (extension_sync_bundle_.HasExtensionId(extension_id) && | 768 } else if (extension_sync_bundle_.HasExtensionId(extension_id) && |
| 769 sync_change.sync_data().GetDataType() == syncable::EXTENSIONS) { | 769 sync_change.sync_data().GetDataType() == syncer::EXTENSIONS) { |
| 770 extension_sync_bundle_.ProcessDeletion(extension_id, sync_change); | 770 extension_sync_bundle_.ProcessDeletion(extension_id, sync_change); |
| 771 } | 771 } |
| 772 | 772 |
| 773 // Track the uninstallation. | 773 // Track the uninstallation. |
| 774 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2); | 774 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2); |
| 775 | 775 |
| 776 static bool default_apps_trial_exists = | 776 static bool default_apps_trial_exists = |
| 777 base::FieldTrialList::TrialExists(kDefaultAppsTrialName); | 777 base::FieldTrialList::TrialExists(kDefaultAppsTrialName); |
| 778 if (default_apps_trial_exists) { | 778 if (default_apps_trial_exists) { |
| 779 UMA_HISTOGRAM_ENUMERATION( | 779 UMA_HISTOGRAM_ENUMERATION( |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 // during startup. Start the update as soon as those providers are ready, | 1185 // during startup. Start the update as soon as those providers are ready, |
| 1186 // but not before. | 1186 // but not before. |
| 1187 update_once_all_providers_are_ready_ = true; | 1187 update_once_all_providers_are_ready_ = true; |
| 1188 } | 1188 } |
| 1189 } else { | 1189 } else { |
| 1190 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off"; | 1190 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off"; |
| 1191 } | 1191 } |
| 1192 } | 1192 } |
| 1193 | 1193 |
| 1194 syncer::SyncError ExtensionService::MergeDataAndStartSyncing( | 1194 syncer::SyncError ExtensionService::MergeDataAndStartSyncing( |
| 1195 syncable::ModelType type, | 1195 syncer::ModelType type, |
| 1196 const syncer::SyncDataList& initial_sync_data, | 1196 const syncer::SyncDataList& initial_sync_data, |
| 1197 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 1197 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 1198 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) { | 1198 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) { |
| 1199 CHECK(sync_processor.get()); | 1199 CHECK(sync_processor.get()); |
| 1200 CHECK(sync_error_factory.get()); | 1200 CHECK(sync_error_factory.get()); |
| 1201 | 1201 |
| 1202 switch (type) { | 1202 switch (type) { |
| 1203 case syncable::EXTENSIONS: | 1203 case syncer::EXTENSIONS: |
| 1204 extension_sync_bundle_.SetupSync(sync_processor.release(), | 1204 extension_sync_bundle_.SetupSync(sync_processor.release(), |
| 1205 sync_error_factory.release(), | 1205 sync_error_factory.release(), |
| 1206 initial_sync_data); | 1206 initial_sync_data); |
| 1207 break; | 1207 break; |
| 1208 | 1208 |
| 1209 case syncable::APPS: | 1209 case syncer::APPS: |
| 1210 app_sync_bundle_.SetupSync(sync_processor.release(), | 1210 app_sync_bundle_.SetupSync(sync_processor.release(), |
| 1211 sync_error_factory.release(), | 1211 sync_error_factory.release(), |
| 1212 initial_sync_data); | 1212 initial_sync_data); |
| 1213 break; | 1213 break; |
| 1214 | 1214 |
| 1215 default: | 1215 default: |
| 1216 LOG(FATAL) << "Got " << type << " ModelType"; | 1216 LOG(FATAL) << "Got " << type << " ModelType"; |
| 1217 } | 1217 } |
| 1218 | 1218 |
| 1219 // Process local extensions. | 1219 // Process local extensions. |
| 1220 // TODO(yoz): Determine whether pending extensions should be considered too. | 1220 // TODO(yoz): Determine whether pending extensions should be considered too. |
| 1221 // See crbug.com/104399. | 1221 // See crbug.com/104399. |
| 1222 syncer::SyncDataList sync_data_list = GetAllSyncData(type); | 1222 syncer::SyncDataList sync_data_list = GetAllSyncData(type); |
| 1223 syncer::SyncChangeList sync_change_list; | 1223 syncer::SyncChangeList sync_change_list; |
| 1224 for (syncer::SyncDataList::const_iterator i = sync_data_list.begin(); | 1224 for (syncer::SyncDataList::const_iterator i = sync_data_list.begin(); |
| 1225 i != sync_data_list.end(); | 1225 i != sync_data_list.end(); |
| 1226 ++i) { | 1226 ++i) { |
| 1227 switch (type) { | 1227 switch (type) { |
| 1228 case syncable::EXTENSIONS: | 1228 case syncer::EXTENSIONS: |
| 1229 sync_change_list.push_back( | 1229 sync_change_list.push_back( |
| 1230 extension_sync_bundle_.CreateSyncChange(*i)); | 1230 extension_sync_bundle_.CreateSyncChange(*i)); |
| 1231 break; | 1231 break; |
| 1232 case syncable::APPS: | 1232 case syncer::APPS: |
| 1233 sync_change_list.push_back(app_sync_bundle_.CreateSyncChange(*i)); | 1233 sync_change_list.push_back(app_sync_bundle_.CreateSyncChange(*i)); |
| 1234 break; | 1234 break; |
| 1235 default: | 1235 default: |
| 1236 LOG(FATAL) << "Got " << type << " ModelType"; | 1236 LOG(FATAL) << "Got " << type << " ModelType"; |
| 1237 } | 1237 } |
| 1238 } | 1238 } |
| 1239 | 1239 |
| 1240 | 1240 |
| 1241 if (type == syncable::EXTENSIONS) { | 1241 if (type == syncer::EXTENSIONS) { |
| 1242 extension_sync_bundle_.ProcessSyncChangeList(sync_change_list); | 1242 extension_sync_bundle_.ProcessSyncChangeList(sync_change_list); |
| 1243 } else if (type == syncable::APPS) { | 1243 } else if (type == syncer::APPS) { |
| 1244 app_sync_bundle_.ProcessSyncChangeList(sync_change_list); | 1244 app_sync_bundle_.ProcessSyncChangeList(sync_change_list); |
| 1245 } | 1245 } |
| 1246 | 1246 |
| 1247 return syncer::SyncError(); | 1247 return syncer::SyncError(); |
| 1248 } | 1248 } |
| 1249 | 1249 |
| 1250 void ExtensionService::StopSyncing(syncable::ModelType type) { | 1250 void ExtensionService::StopSyncing(syncer::ModelType type) { |
| 1251 if (type == syncable::APPS) { | 1251 if (type == syncer::APPS) { |
| 1252 app_sync_bundle_.Reset(); | 1252 app_sync_bundle_.Reset(); |
| 1253 } else if (type == syncable::EXTENSIONS) { | 1253 } else if (type == syncer::EXTENSIONS) { |
| 1254 extension_sync_bundle_.Reset(); | 1254 extension_sync_bundle_.Reset(); |
| 1255 } | 1255 } |
| 1256 } | 1256 } |
| 1257 | 1257 |
| 1258 syncer::SyncDataList ExtensionService::GetAllSyncData( | 1258 syncer::SyncDataList ExtensionService::GetAllSyncData( |
| 1259 syncable::ModelType type) const { | 1259 syncer::ModelType type) const { |
| 1260 if (type == syncable::EXTENSIONS) { | 1260 if (type == syncer::EXTENSIONS) { |
| 1261 return extension_sync_bundle_.GetAllSyncData(); | 1261 return extension_sync_bundle_.GetAllSyncData(); |
| 1262 | 1262 |
| 1263 } else if (type == syncable::APPS) { | 1263 } else if (type == syncer::APPS) { |
| 1264 return app_sync_bundle_.GetAllSyncData(); | 1264 return app_sync_bundle_.GetAllSyncData(); |
| 1265 } | 1265 } |
| 1266 | 1266 |
| 1267 // We should only get sync data for extensions and apps. | 1267 // We should only get sync data for extensions and apps. |
| 1268 NOTREACHED(); | 1268 NOTREACHED(); |
| 1269 | 1269 |
| 1270 return syncer::SyncDataList(); | 1270 return syncer::SyncDataList(); |
| 1271 } | 1271 } |
| 1272 | 1272 |
| 1273 syncer::SyncError ExtensionService::ProcessSyncChanges( | 1273 syncer::SyncError ExtensionService::ProcessSyncChanges( |
| 1274 const tracked_objects::Location& from_here, | 1274 const tracked_objects::Location& from_here, |
| 1275 const syncer::SyncChangeList& change_list) { | 1275 const syncer::SyncChangeList& change_list) { |
| 1276 for (syncer::SyncChangeList::const_iterator i = change_list.begin(); | 1276 for (syncer::SyncChangeList::const_iterator i = change_list.begin(); |
| 1277 i != change_list.end(); | 1277 i != change_list.end(); |
| 1278 ++i) { | 1278 ++i) { |
| 1279 syncable::ModelType type = i->sync_data().GetDataType(); | 1279 syncer::ModelType type = i->sync_data().GetDataType(); |
| 1280 if (type == syncable::EXTENSIONS) { | 1280 if (type == syncer::EXTENSIONS) { |
| 1281 extension_sync_bundle_.ProcessSyncChange( | 1281 extension_sync_bundle_.ProcessSyncChange( |
| 1282 extensions::ExtensionSyncData(*i)); | 1282 extensions::ExtensionSyncData(*i)); |
| 1283 } else if (type == syncable::APPS) { | 1283 } else if (type == syncer::APPS) { |
| 1284 app_sync_bundle_.ProcessSyncChange(extensions::AppSyncData(*i)); | 1284 app_sync_bundle_.ProcessSyncChange(extensions::AppSyncData(*i)); |
| 1285 } | 1285 } |
| 1286 } | 1286 } |
| 1287 | 1287 |
| 1288 extension_prefs()->extension_sorting()->FixNTPOrdinalCollisions(); | 1288 extension_prefs()->extension_sorting()->FixNTPOrdinalCollisions(); |
| 1289 | 1289 |
| 1290 return syncer::SyncError(); | 1290 return syncer::SyncError(); |
| 1291 } | 1291 } |
| 1292 | 1292 |
| 1293 extensions::ExtensionSyncData ExtensionService::GetExtensionSyncData( | 1293 extensions::ExtensionSyncData ExtensionService::GetExtensionSyncData( |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 app_sync_list.insert(app_sync_list.begin(), | 1343 app_sync_list.insert(app_sync_list.begin(), |
| 1344 pending_apps.begin(), | 1344 pending_apps.begin(), |
| 1345 pending_apps.end()); | 1345 pending_apps.end()); |
| 1346 | 1346 |
| 1347 return app_sync_list; | 1347 return app_sync_list; |
| 1348 } | 1348 } |
| 1349 | 1349 |
| 1350 bool ExtensionService::ProcessExtensionSyncData( | 1350 bool ExtensionService::ProcessExtensionSyncData( |
| 1351 const extensions::ExtensionSyncData& extension_sync_data) { | 1351 const extensions::ExtensionSyncData& extension_sync_data) { |
| 1352 if (!ProcessExtensionSyncDataHelper(extension_sync_data, | 1352 if (!ProcessExtensionSyncDataHelper(extension_sync_data, |
| 1353 syncable::EXTENSIONS)) { | 1353 syncer::EXTENSIONS)) { |
| 1354 extension_sync_bundle_.AddPendingExtension(extension_sync_data.id(), | 1354 extension_sync_bundle_.AddPendingExtension(extension_sync_data.id(), |
| 1355 extension_sync_data); | 1355 extension_sync_data); |
| 1356 CheckForUpdatesSoon(); | 1356 CheckForUpdatesSoon(); |
| 1357 return false; | 1357 return false; |
| 1358 } | 1358 } |
| 1359 | 1359 |
| 1360 return true; | 1360 return true; |
| 1361 } | 1361 } |
| 1362 | 1362 |
| 1363 bool ExtensionService::ProcessAppSyncData( | 1363 bool ExtensionService::ProcessAppSyncData( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1378 | 1378 |
| 1379 if (extension_installed) { | 1379 if (extension_installed) { |
| 1380 if (app_sync_data.notifications_disabled() != | 1380 if (app_sync_data.notifications_disabled() != |
| 1381 extension_prefs_->IsAppNotificationDisabled(id)) { | 1381 extension_prefs_->IsAppNotificationDisabled(id)) { |
| 1382 extension_prefs_->SetAppNotificationDisabled( | 1382 extension_prefs_->SetAppNotificationDisabled( |
| 1383 id, app_sync_data.notifications_disabled()); | 1383 id, app_sync_data.notifications_disabled()); |
| 1384 } | 1384 } |
| 1385 } | 1385 } |
| 1386 | 1386 |
| 1387 if (!ProcessExtensionSyncDataHelper(app_sync_data.extension_sync_data(), | 1387 if (!ProcessExtensionSyncDataHelper(app_sync_data.extension_sync_data(), |
| 1388 syncable::APPS)) { | 1388 syncer::APPS)) { |
| 1389 app_sync_bundle_.AddPendingApp(id, app_sync_data); | 1389 app_sync_bundle_.AddPendingApp(id, app_sync_data); |
| 1390 CheckForUpdatesSoon(); | 1390 CheckForUpdatesSoon(); |
| 1391 return false; | 1391 return false; |
| 1392 } | 1392 } |
| 1393 | 1393 |
| 1394 return true; | 1394 return true; |
| 1395 } | 1395 } |
| 1396 | 1396 |
| 1397 bool ExtensionService::IsCorrectSyncType(const Extension& extension, | 1397 bool ExtensionService::IsCorrectSyncType(const Extension& extension, |
| 1398 syncable::ModelType type) const { | 1398 syncer::ModelType type) const { |
| 1399 if (type == syncable::EXTENSIONS && | 1399 if (type == syncer::EXTENSIONS && |
| 1400 extension.GetSyncType() == Extension::SYNC_TYPE_EXTENSION) | 1400 extension.GetSyncType() == Extension::SYNC_TYPE_EXTENSION) |
| 1401 return true; | 1401 return true; |
| 1402 | 1402 |
| 1403 if (type == syncable::APPS && | 1403 if (type == syncer::APPS && |
| 1404 extension.GetSyncType() == Extension::SYNC_TYPE_APP) | 1404 extension.GetSyncType() == Extension::SYNC_TYPE_APP) |
| 1405 return true; | 1405 return true; |
| 1406 | 1406 |
| 1407 return false; | 1407 return false; |
| 1408 } | 1408 } |
| 1409 | 1409 |
| 1410 bool ExtensionService::ProcessExtensionSyncDataHelper( | 1410 bool ExtensionService::ProcessExtensionSyncDataHelper( |
| 1411 const extensions::ExtensionSyncData& extension_sync_data, | 1411 const extensions::ExtensionSyncData& extension_sync_data, |
| 1412 syncable::ModelType type) { | 1412 syncer::ModelType type) { |
| 1413 const std::string& id = extension_sync_data.id(); | 1413 const std::string& id = extension_sync_data.id(); |
| 1414 const Extension* extension = GetInstalledExtension(id); | 1414 const Extension* extension = GetInstalledExtension(id); |
| 1415 | 1415 |
| 1416 // TODO(bolms): we should really handle this better. The particularly bad | 1416 // TODO(bolms): we should really handle this better. The particularly bad |
| 1417 // case is where an app becomes an extension or vice versa, and we end up with | 1417 // case is where an app becomes an extension or vice versa, and we end up with |
| 1418 // a zombie extension that won't go away. | 1418 // a zombie extension that won't go away. |
| 1419 if (extension && !IsCorrectSyncType(*extension, type)) | 1419 if (extension && !IsCorrectSyncType(*extension, type)) |
| 1420 return true; | 1420 return true; |
| 1421 | 1421 |
| 1422 // Handle uninstalls first. | 1422 // Handle uninstalls first. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 // If the extension is already installed, check if it's outdated. | 1457 // If the extension is already installed, check if it's outdated. |
| 1458 if (result < 0) { | 1458 if (result < 0) { |
| 1459 // Extension is outdated. | 1459 // Extension is outdated. |
| 1460 return false; | 1460 return false; |
| 1461 } | 1461 } |
| 1462 } else { | 1462 } else { |
| 1463 // TODO(akalin): Replace silent update with a list of enabled | 1463 // TODO(akalin): Replace silent update with a list of enabled |
| 1464 // permissions. | 1464 // permissions. |
| 1465 const bool kInstallSilently = true; | 1465 const bool kInstallSilently = true; |
| 1466 | 1466 |
| 1467 CHECK(type == syncable::EXTENSIONS || type == syncable::APPS); | 1467 CHECK(type == syncer::EXTENSIONS || type == syncer::APPS); |
| 1468 ExtensionFilter filter = | 1468 ExtensionFilter filter = |
| 1469 (type == syncable::APPS) ? IsSyncableApp : IsSyncableExtension; | 1469 (type == syncer::APPS) ? IsSyncableApp : IsSyncableExtension; |
| 1470 | 1470 |
| 1471 if (!pending_extension_manager()->AddFromSync( | 1471 if (!pending_extension_manager()->AddFromSync( |
| 1472 id, | 1472 id, |
| 1473 extension_sync_data.update_url(), | 1473 extension_sync_data.update_url(), |
| 1474 filter, | 1474 filter, |
| 1475 kInstallSilently)) { | 1475 kInstallSilently)) { |
| 1476 LOG(WARNING) << "Could not add pending extension for " << id; | 1476 LOG(WARNING) << "Could not add pending extension for " << id; |
| 1477 // This means that the extension is already pending installation, with a | 1477 // This means that the extension is already pending installation, with a |
| 1478 // non-INTERNAL location. Add to pending_sync_data, even though it will | 1478 // non-INTERNAL location. Add to pending_sync_data, even though it will |
| 1479 // never be removed (we'll never install a syncable version of the | 1479 // never be removed (we'll never install a syncable version of the |
| (...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2560 | 2560 |
| 2561 // To coexist with certain unit tests that don't have a work-thread message | 2561 // To coexist with certain unit tests that don't have a work-thread message |
| 2562 // loop available at ExtensionService shutdown, we lazy-initialize this | 2562 // loop available at ExtensionService shutdown, we lazy-initialize this |
| 2563 // object so that those cases neither create nor destroy an | 2563 // object so that those cases neither create nor destroy an |
| 2564 // APIResourceController. | 2564 // APIResourceController. |
| 2565 if (!api_resource_controller_.get()) { | 2565 if (!api_resource_controller_.get()) { |
| 2566 api_resource_controller_.reset(new extensions::APIResourceController()); | 2566 api_resource_controller_.reset(new extensions::APIResourceController()); |
| 2567 } | 2567 } |
| 2568 return api_resource_controller_.get(); | 2568 return api_resource_controller_.get(); |
| 2569 } | 2569 } |
| OLD | NEW |