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