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/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
11 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
12 #include "chrome/browser/extensions/app_sync_data.h" | 13 #include "chrome/browser/extensions/app_sync_data.h" |
| 14 #include "chrome/browser/extensions/bookmark_app_helper.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extension_sync_data.h" | 16 #include "chrome/browser/extensions/extension_sync_data.h" |
15 #include "chrome/browser/extensions/extension_sync_service_factory.h" | 17 #include "chrome/browser/extensions/extension_sync_service_factory.h" |
16 #include "chrome/browser/extensions/extension_util.h" | 18 #include "chrome/browser/extensions/extension_util.h" |
17 #include "chrome/browser/extensions/launch_util.h" | 19 #include "chrome/browser/extensions/launch_util.h" |
18 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/sync/glue/sync_start_util.h" | 21 #include "chrome/browser/sync/glue/sync_start_util.h" |
| 22 #include "chrome/common/extensions/extension_constants.h" |
| 23 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
20 #include "chrome/common/extensions/sync_helper.h" | 24 #include "chrome/common/extensions/sync_helper.h" |
| 25 #include "chrome/common/web_application_info.h" |
21 #include "components/sync_driver/sync_prefs.h" | 26 #include "components/sync_driver/sync_prefs.h" |
22 #include "extensions/browser/app_sorting.h" | 27 #include "extensions/browser/app_sorting.h" |
23 #include "extensions/browser/extension_prefs.h" | 28 #include "extensions/browser/extension_prefs.h" |
24 #include "extensions/browser/extension_registry.h" | 29 #include "extensions/browser/extension_registry.h" |
25 #include "extensions/common/extension.h" | 30 #include "extensions/common/extension.h" |
| 31 #include "extensions/common/extension_icon_set.h" |
26 #include "extensions/common/feature_switch.h" | 32 #include "extensions/common/feature_switch.h" |
27 #include "extensions/common/manifest_constants.h" | 33 #include "extensions/common/manifest_constants.h" |
| 34 #include "extensions/common/manifest_handlers/icons_handler.h" |
28 #include "sync/api/sync_change.h" | 35 #include "sync/api/sync_change.h" |
29 #include "sync/api/sync_error_factory.h" | 36 #include "sync/api/sync_error_factory.h" |
| 37 #include "ui/gfx/image/image_family.h" |
30 | 38 |
31 using extensions::Extension; | 39 using extensions::Extension; |
32 using extensions::ExtensionPrefs; | 40 using extensions::ExtensionPrefs; |
33 using extensions::ExtensionRegistry; | 41 using extensions::ExtensionRegistry; |
34 using extensions::FeatureSwitch; | 42 using extensions::FeatureSwitch; |
35 | 43 |
| 44 namespace { |
| 45 |
| 46 void OnWebApplicationInfoLoaded( |
| 47 WebApplicationInfo synced_info, |
| 48 base::WeakPtr<ExtensionService> extension_service, |
| 49 const WebApplicationInfo& loaded_info) { |
| 50 DCHECK_EQ(synced_info.app_url, loaded_info.app_url); |
| 51 |
| 52 if (!extension_service) |
| 53 return; |
| 54 |
| 55 // Use the old icons if they exist. |
| 56 synced_info.icons = loaded_info.icons; |
| 57 CreateOrUpdateBookmarkApp(extension_service.get(), synced_info); |
| 58 } |
| 59 |
| 60 } // namespace |
| 61 |
36 ExtensionSyncService::ExtensionSyncService(Profile* profile, | 62 ExtensionSyncService::ExtensionSyncService(Profile* profile, |
37 ExtensionPrefs* extension_prefs, | 63 ExtensionPrefs* extension_prefs, |
38 ExtensionService* extension_service) | 64 ExtensionService* extension_service) |
39 : profile_(profile), | 65 : profile_(profile), |
40 extension_prefs_(extension_prefs), | 66 extension_prefs_(extension_prefs), |
41 extension_service_(extension_service), | 67 extension_service_(extension_service), |
42 app_sync_bundle_(this), | 68 app_sync_bundle_(this), |
43 extension_sync_bundle_(this), | 69 extension_sync_bundle_(this), |
44 pending_app_enables_(make_scoped_ptr(new sync_driver::SyncPrefs( | 70 pending_app_enables_(make_scoped_ptr(new sync_driver::SyncPrefs( |
45 extension_prefs_->pref_service())), | 71 extension_prefs_->pref_service())), |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 } | 336 } |
311 | 337 |
312 // The corresponding validation of this value during AppSyncData population | 338 // The corresponding validation of this value during AppSyncData population |
313 // is in AppSyncData::PopulateAppSpecifics. | 339 // is in AppSyncData::PopulateAppSpecifics. |
314 if (app_sync_data.launch_type() >= extensions::LAUNCH_TYPE_FIRST && | 340 if (app_sync_data.launch_type() >= extensions::LAUNCH_TYPE_FIRST && |
315 app_sync_data.launch_type() < extensions::NUM_LAUNCH_TYPES) { | 341 app_sync_data.launch_type() < extensions::NUM_LAUNCH_TYPES) { |
316 extensions::SetLaunchType(extension_service_, id, | 342 extensions::SetLaunchType(extension_service_, id, |
317 app_sync_data.launch_type()); | 343 app_sync_data.launch_type()); |
318 } | 344 } |
319 | 345 |
| 346 if (!app_sync_data.bookmark_app_url().empty()) |
| 347 ProcessBookmarkAppSyncData(app_sync_data); |
| 348 |
320 if (!ProcessExtensionSyncDataHelper(app_sync_data.extension_sync_data(), | 349 if (!ProcessExtensionSyncDataHelper(app_sync_data.extension_sync_data(), |
321 syncer::APPS)) { | 350 syncer::APPS)) { |
322 app_sync_bundle_.AddPendingApp(id, app_sync_data); | 351 app_sync_bundle_.AddPendingApp(id, app_sync_data); |
323 extension_service_->CheckForUpdatesSoon(); | 352 extension_service_->CheckForUpdatesSoon(); |
324 return false; | 353 return false; |
325 } | 354 } |
326 | 355 |
327 return true; | 356 return true; |
328 } | 357 } |
329 | 358 |
| 359 void ExtensionSyncService::ProcessBookmarkAppSyncData( |
| 360 const extensions::AppSyncData& app_sync_data) { |
| 361 // Process bookmark app sync if necessary. |
| 362 GURL bookmark_app_url(app_sync_data.bookmark_app_url()); |
| 363 if (!bookmark_app_url.is_valid() || |
| 364 app_sync_data.extension_sync_data().uninstalled()) { |
| 365 return; |
| 366 } |
| 367 |
| 368 const extensions::Extension* extension = |
| 369 extension_service_->GetInstalledExtension( |
| 370 app_sync_data.extension_sync_data().id()); |
| 371 |
| 372 // Return if there are no bookmark app details that need updating. |
| 373 if (extension && extension->non_localized_name() == |
| 374 app_sync_data.extension_sync_data().name() && |
| 375 extension->description() == app_sync_data.bookmark_app_description()) { |
| 376 return; |
| 377 } |
| 378 |
| 379 WebApplicationInfo web_app_info; |
| 380 web_app_info.app_url = bookmark_app_url; |
| 381 web_app_info.title = |
| 382 base::UTF8ToUTF16(app_sync_data.extension_sync_data().name()); |
| 383 web_app_info.description = |
| 384 base::UTF8ToUTF16(app_sync_data.bookmark_app_description()); |
| 385 |
| 386 // If the bookmark app already exists, keep the old icons. |
| 387 if (!extension) { |
| 388 CreateOrUpdateBookmarkApp(extension_service_, web_app_info); |
| 389 } else { |
| 390 app_sync_data.extension_sync_data().name(); |
| 391 GetWebApplicationInfoFromApp(profile_, |
| 392 extension, |
| 393 base::Bind(&OnWebApplicationInfoLoaded, |
| 394 web_app_info, |
| 395 extension_service_->AsWeakPtr())); |
| 396 } |
| 397 } |
| 398 |
330 void ExtensionSyncService::SyncOrderingChange(const std::string& extension_id) { | 399 void ExtensionSyncService::SyncOrderingChange(const std::string& extension_id) { |
331 const extensions::Extension* ext = extension_service_->GetInstalledExtension( | 400 const extensions::Extension* ext = extension_service_->GetInstalledExtension( |
332 extension_id); | 401 extension_id); |
333 | 402 |
334 if (ext) | 403 if (ext) |
335 SyncExtensionChangeIfNeeded(*ext); | 404 SyncExtensionChangeIfNeeded(*ext); |
336 } | 405 } |
337 | 406 |
338 void ExtensionSyncService::SetSyncStartFlare( | 407 void ExtensionSyncService::SetSyncStartFlare( |
339 const syncer::SyncableService::StartSyncFlare& flare) { | 408 const syncer::SyncableService::StartSyncFlare& flare) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 app_sync_bundle_.SyncChangeIfNeeded(extension); | 522 app_sync_bundle_.SyncChangeIfNeeded(extension); |
454 else if (extension_service_->is_ready() && !flare_.is_null()) | 523 else if (extension_service_->is_ready() && !flare_.is_null()) |
455 flare_.Run(syncer::APPS); | 524 flare_.Run(syncer::APPS); |
456 } else if (extensions::sync_helper::IsSyncableExtension(&extension)) { | 525 } else if (extensions::sync_helper::IsSyncableExtension(&extension)) { |
457 if (extension_sync_bundle_.IsSyncing()) | 526 if (extension_sync_bundle_.IsSyncing()) |
458 extension_sync_bundle_.SyncChangeIfNeeded(extension); | 527 extension_sync_bundle_.SyncChangeIfNeeded(extension); |
459 else if (extension_service_->is_ready() && !flare_.is_null()) | 528 else if (extension_service_->is_ready() && !flare_.is_null()) |
460 flare_.Run(syncer::EXTENSIONS); | 529 flare_.Run(syncer::EXTENSIONS); |
461 } | 530 } |
462 } | 531 } |
OLD | NEW |