OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_sync_service.h" | 5 #include "chrome/browser/extensions/extension_sync_service.h" |
6 | 6 |
7 #include <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "extensions/common/extension.h" | 32 #include "extensions/common/extension.h" |
33 #include "extensions/common/extension_icon_set.h" | 33 #include "extensions/common/extension_icon_set.h" |
34 #include "extensions/common/feature_switch.h" | 34 #include "extensions/common/feature_switch.h" |
35 #include "extensions/common/image_util.h" | 35 #include "extensions/common/image_util.h" |
36 #include "extensions/common/manifest_constants.h" | 36 #include "extensions/common/manifest_constants.h" |
37 #include "extensions/common/manifest_handlers/icons_handler.h" | 37 #include "extensions/common/manifest_handlers/icons_handler.h" |
38 #include "sync/api/sync_change.h" | 38 #include "sync/api/sync_change.h" |
39 #include "sync/api/sync_error_factory.h" | 39 #include "sync/api/sync_error_factory.h" |
40 #include "ui/gfx/image/image_family.h" | 40 #include "ui/gfx/image/image_family.h" |
41 | 41 |
| 42 using extensions::AppSyncData; |
42 using extensions::Extension; | 43 using extensions::Extension; |
43 using extensions::ExtensionPrefs; | 44 using extensions::ExtensionPrefs; |
44 using extensions::ExtensionRegistry; | 45 using extensions::ExtensionRegistry; |
45 using extensions::ExtensionSyncData; | 46 using extensions::ExtensionSyncData; |
46 using extensions::FeatureSwitch; | 47 using extensions::FeatureSwitch; |
47 | 48 |
48 namespace { | 49 namespace { |
49 | 50 |
50 void OnWebApplicationInfoLoaded( | 51 void OnWebApplicationInfoLoaded( |
51 WebApplicationInfo synced_info, | 52 WebApplicationInfo synced_info, |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 return syncer::SyncDataList(); | 254 return syncer::SyncDataList(); |
254 } | 255 } |
255 | 256 |
256 syncer::SyncError ExtensionSyncService::ProcessSyncChanges( | 257 syncer::SyncError ExtensionSyncService::ProcessSyncChanges( |
257 const tracked_objects::Location& from_here, | 258 const tracked_objects::Location& from_here, |
258 const syncer::SyncChangeList& change_list) { | 259 const syncer::SyncChangeList& change_list) { |
259 for (syncer::SyncChangeList::const_iterator i = change_list.begin(); | 260 for (syncer::SyncChangeList::const_iterator i = change_list.begin(); |
260 i != change_list.end(); | 261 i != change_list.end(); |
261 ++i) { | 262 ++i) { |
262 syncer::ModelType type = i->sync_data().GetDataType(); | 263 syncer::ModelType type = i->sync_data().GetDataType(); |
263 if (type == syncer::EXTENSIONS) | 264 if (type == syncer::EXTENSIONS) { |
264 extension_sync_bundle_.ProcessSyncChange(ExtensionSyncData(*i)); | 265 scoped_ptr<ExtensionSyncData> extension_data( |
265 else if (type == syncer::APPS) | 266 ExtensionSyncData::CreateFromSyncChange(*i)); |
266 app_sync_bundle_.ProcessSyncChange(extensions::AppSyncData(*i)); | 267 if (extension_data.get()) |
| 268 extension_sync_bundle_.ProcessSyncChange(*extension_data); |
| 269 } else if (type == syncer::APPS) { |
| 270 scoped_ptr<AppSyncData> app_data(AppSyncData::CreateFromSyncChange(*i)); |
| 271 if (app_data.get()) |
| 272 app_sync_bundle_.ProcessSyncChange(*app_data); |
| 273 } |
267 } | 274 } |
268 | 275 |
269 extension_prefs_->app_sorting()->FixNTPOrdinalCollisions(); | 276 extension_prefs_->app_sorting()->FixNTPOrdinalCollisions(); |
270 | 277 |
271 return syncer::SyncError(); | 278 return syncer::SyncError(); |
272 } | 279 } |
273 | 280 |
274 ExtensionSyncData ExtensionSyncService::GetExtensionSyncData( | 281 ExtensionSyncData ExtensionSyncService::GetExtensionSyncData( |
275 const Extension& extension) const { | 282 const Extension& extension) const { |
276 return ExtensionSyncData( | 283 return ExtensionSyncData( |
277 extension, | 284 extension, |
278 extension_service_->IsExtensionEnabled(extension.id()), | 285 extension_service_->IsExtensionEnabled(extension.id()), |
279 extensions::util::IsIncognitoEnabled(extension.id(), profile_), | 286 extensions::util::IsIncognitoEnabled(extension.id(), profile_), |
280 extension_prefs_->HasDisableReason(extension.id(), | 287 extension_prefs_->HasDisableReason(extension.id(), |
281 Extension::DISABLE_REMOTE_INSTALL), | 288 Extension::DISABLE_REMOTE_INSTALL), |
282 GetAllowedOnAllUrlsOptionalBoolean(extension.id(), profile_)); | 289 GetAllowedOnAllUrlsOptionalBoolean(extension.id(), profile_)); |
283 } | 290 } |
284 | 291 |
285 extensions::AppSyncData ExtensionSyncService::GetAppSyncData( | 292 AppSyncData ExtensionSyncService::GetAppSyncData( |
286 const Extension& extension) const { | 293 const Extension& extension) const { |
287 return extensions::AppSyncData( | 294 return AppSyncData( |
288 extension, | 295 extension, extension_service_->IsExtensionEnabled(extension.id()), |
289 extension_service_->IsExtensionEnabled(extension.id()), | |
290 extensions::util::IsIncognitoEnabled(extension.id(), profile_), | 296 extensions::util::IsIncognitoEnabled(extension.id(), profile_), |
291 extension_prefs_->HasDisableReason(extension.id(), | 297 extension_prefs_->HasDisableReason(extension.id(), |
292 Extension::DISABLE_REMOTE_INSTALL), | 298 Extension::DISABLE_REMOTE_INSTALL), |
293 GetAllowedOnAllUrlsOptionalBoolean(extension.id(), profile_), | 299 GetAllowedOnAllUrlsOptionalBoolean(extension.id(), profile_), |
294 extension_prefs_->app_sorting()->GetAppLaunchOrdinal(extension.id()), | 300 extension_prefs_->app_sorting()->GetAppLaunchOrdinal(extension.id()), |
295 extension_prefs_->app_sorting()->GetPageOrdinal(extension.id()), | 301 extension_prefs_->app_sorting()->GetPageOrdinal(extension.id()), |
296 extensions::GetLaunchTypePrefValue(extension_prefs_, extension.id())); | 302 extensions::GetLaunchTypePrefValue(extension_prefs_, extension.id())); |
297 } | 303 } |
298 | 304 |
299 std::vector<ExtensionSyncData> | 305 std::vector<ExtensionSyncData> |
300 ExtensionSyncService::GetExtensionSyncDataList() const { | 306 ExtensionSyncService::GetExtensionSyncDataList() const { |
301 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); | 307 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); |
302 std::vector<ExtensionSyncData> extension_sync_list; | 308 std::vector<ExtensionSyncData> extension_sync_list; |
303 extension_sync_bundle_.GetExtensionSyncDataListHelper( | 309 extension_sync_bundle_.GetExtensionSyncDataListHelper( |
304 registry->enabled_extensions(), &extension_sync_list); | 310 registry->enabled_extensions(), &extension_sync_list); |
305 extension_sync_bundle_.GetExtensionSyncDataListHelper( | 311 extension_sync_bundle_.GetExtensionSyncDataListHelper( |
306 registry->disabled_extensions(), &extension_sync_list); | 312 registry->disabled_extensions(), &extension_sync_list); |
307 extension_sync_bundle_.GetExtensionSyncDataListHelper( | 313 extension_sync_bundle_.GetExtensionSyncDataListHelper( |
308 registry->terminated_extensions(), &extension_sync_list); | 314 registry->terminated_extensions(), &extension_sync_list); |
309 | 315 |
310 std::vector<ExtensionSyncData> pending_extensions = | 316 std::vector<ExtensionSyncData> pending_extensions = |
311 extension_sync_bundle_.GetPendingData(); | 317 extension_sync_bundle_.GetPendingData(); |
312 extension_sync_list.insert(extension_sync_list.begin(), | 318 extension_sync_list.insert(extension_sync_list.begin(), |
313 pending_extensions.begin(), | 319 pending_extensions.begin(), |
314 pending_extensions.end()); | 320 pending_extensions.end()); |
315 | 321 |
316 return extension_sync_list; | 322 return extension_sync_list; |
317 } | 323 } |
318 | 324 |
319 std::vector<extensions::AppSyncData> ExtensionSyncService::GetAppSyncDataList() | 325 std::vector<AppSyncData> ExtensionSyncService::GetAppSyncDataList() const { |
320 const { | |
321 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); | 326 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); |
322 std::vector<extensions::AppSyncData> app_sync_list; | 327 std::vector<AppSyncData> app_sync_list; |
323 app_sync_bundle_.GetAppSyncDataListHelper( | 328 app_sync_bundle_.GetAppSyncDataListHelper( |
324 registry->enabled_extensions(), &app_sync_list); | 329 registry->enabled_extensions(), &app_sync_list); |
325 app_sync_bundle_.GetAppSyncDataListHelper( | 330 app_sync_bundle_.GetAppSyncDataListHelper( |
326 registry->disabled_extensions(), &app_sync_list); | 331 registry->disabled_extensions(), &app_sync_list); |
327 app_sync_bundle_.GetAppSyncDataListHelper( | 332 app_sync_bundle_.GetAppSyncDataListHelper( |
328 registry->terminated_extensions(), &app_sync_list); | 333 registry->terminated_extensions(), &app_sync_list); |
329 | 334 |
330 std::vector<extensions::AppSyncData> pending_apps = | 335 std::vector<AppSyncData> pending_apps = app_sync_bundle_.GetPendingData(); |
331 app_sync_bundle_.GetPendingData(); | |
332 app_sync_list.insert(app_sync_list.begin(), | 336 app_sync_list.insert(app_sync_list.begin(), |
333 pending_apps.begin(), | 337 pending_apps.begin(), |
334 pending_apps.end()); | 338 pending_apps.end()); |
335 | 339 |
336 return app_sync_list; | 340 return app_sync_list; |
337 } | 341 } |
338 | 342 |
339 bool ExtensionSyncService::ProcessExtensionSyncData( | 343 bool ExtensionSyncService::ProcessExtensionSyncData( |
340 const ExtensionSyncData& extension_sync_data) { | 344 const ExtensionSyncData& extension_sync_data) { |
341 if (!ProcessExtensionSyncDataHelper(extension_sync_data, | 345 if (!ProcessExtensionSyncDataHelper(extension_sync_data, |
342 syncer::EXTENSIONS)) { | 346 syncer::EXTENSIONS)) { |
343 extension_sync_bundle_.AddPendingExtension(extension_sync_data.id(), | 347 extension_sync_bundle_.AddPendingExtension(extension_sync_data.id(), |
344 extension_sync_data); | 348 extension_sync_data); |
345 extension_service_->CheckForUpdatesSoon(); | 349 extension_service_->CheckForUpdatesSoon(); |
346 return false; | 350 return false; |
347 } | 351 } |
348 | 352 |
349 return true; | 353 return true; |
350 } | 354 } |
351 | 355 |
352 bool ExtensionSyncService::ProcessAppSyncData( | 356 bool ExtensionSyncService::ProcessAppSyncData( |
353 const extensions::AppSyncData& app_sync_data) { | 357 const AppSyncData& app_sync_data) { |
354 const std::string& id = app_sync_data.id(); | 358 const std::string& id = app_sync_data.id(); |
355 | 359 |
356 if (app_sync_data.app_launch_ordinal().IsValid() && | 360 if (app_sync_data.app_launch_ordinal().IsValid() && |
357 app_sync_data.page_ordinal().IsValid()) { | 361 app_sync_data.page_ordinal().IsValid()) { |
358 extension_prefs_->app_sorting()->SetAppLaunchOrdinal( | 362 extension_prefs_->app_sorting()->SetAppLaunchOrdinal( |
359 id, | 363 id, |
360 app_sync_data.app_launch_ordinal()); | 364 app_sync_data.app_launch_ordinal()); |
361 extension_prefs_->app_sorting()->SetPageOrdinal( | 365 extension_prefs_->app_sorting()->SetPageOrdinal( |
362 id, | 366 id, |
363 app_sync_data.page_ordinal()); | 367 app_sync_data.page_ordinal()); |
(...skipping 13 matching lines...) Expand all Loading... |
377 syncer::APPS)) { | 381 syncer::APPS)) { |
378 app_sync_bundle_.AddPendingApp(id, app_sync_data); | 382 app_sync_bundle_.AddPendingApp(id, app_sync_data); |
379 extension_service_->CheckForUpdatesSoon(); | 383 extension_service_->CheckForUpdatesSoon(); |
380 return false; | 384 return false; |
381 } | 385 } |
382 | 386 |
383 return true; | 387 return true; |
384 } | 388 } |
385 | 389 |
386 void ExtensionSyncService::ProcessBookmarkAppSyncData( | 390 void ExtensionSyncService::ProcessBookmarkAppSyncData( |
387 const extensions::AppSyncData& app_sync_data) { | 391 const AppSyncData& app_sync_data) { |
388 // Process bookmark app sync if necessary. | 392 // Process bookmark app sync if necessary. |
389 GURL bookmark_app_url(app_sync_data.bookmark_app_url()); | 393 GURL bookmark_app_url(app_sync_data.bookmark_app_url()); |
390 if (!bookmark_app_url.is_valid() || | 394 if (!bookmark_app_url.is_valid() || |
391 app_sync_data.extension_sync_data().uninstalled()) { | 395 app_sync_data.extension_sync_data().uninstalled()) { |
392 return; | 396 return; |
393 } | 397 } |
394 | 398 |
395 const extensions::Extension* extension = | 399 const extensions::Extension* extension = |
396 extension_service_->GetInstalledExtension( | 400 extension_service_->GetInstalledExtension( |
397 app_sync_data.extension_sync_data().id()); | 401 app_sync_data.extension_sync_data().id()); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 app_sync_bundle_.SyncChangeIfNeeded(extension); | 582 app_sync_bundle_.SyncChangeIfNeeded(extension); |
579 else if (extension_service_->is_ready() && !flare_.is_null()) | 583 else if (extension_service_->is_ready() && !flare_.is_null()) |
580 flare_.Run(syncer::APPS); | 584 flare_.Run(syncer::APPS); |
581 } else if (extensions::util::ShouldSyncExtension(&extension, profile_)) { | 585 } else if (extensions::util::ShouldSyncExtension(&extension, profile_)) { |
582 if (extension_sync_bundle_.IsSyncing()) | 586 if (extension_sync_bundle_.IsSyncing()) |
583 extension_sync_bundle_.SyncChangeIfNeeded(extension); | 587 extension_sync_bundle_.SyncChangeIfNeeded(extension); |
584 else if (extension_service_->is_ready() && !flare_.is_null()) | 588 else if (extension_service_->is_ready() && !flare_.is_null()) |
585 flare_.Run(syncer::EXTENSIONS); | 589 flare_.Run(syncer::EXTENSIONS); |
586 } | 590 } |
587 } | 591 } |
OLD | NEW |