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" |
11 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
12 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
13 #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" | 14 #include "chrome/browser/extensions/bookmark_app_helper.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/extensions/extension_sync_data.h" | 16 #include "chrome/browser/extensions/extension_sync_data.h" |
17 #include "chrome/browser/extensions/extension_sync_service_factory.h" | 17 #include "chrome/browser/extensions/extension_sync_service_factory.h" |
18 #include "chrome/browser/extensions/extension_util.h" | 18 #include "chrome/browser/extensions/extension_util.h" |
19 #include "chrome/browser/extensions/launch_util.h" | 19 #include "chrome/browser/extensions/launch_util.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #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" | 22 #include "chrome/common/extensions/extension_constants.h" |
23 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 23 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
24 #include "chrome/common/extensions/sync_helper.h" | 24 #include "chrome/common/extensions/sync_helper.h" |
25 #include "chrome/common/web_application_info.h" | 25 #include "chrome/common/web_application_info.h" |
26 #include "components/sync_driver/sync_prefs.h" | 26 #include "components/sync_driver/sync_prefs.h" |
27 #include "extensions/browser/app_sorting.h" | 27 #include "extensions/browser/app_sorting.h" |
28 #include "extensions/browser/extension_prefs.h" | 28 #include "extensions/browser/extension_prefs.h" |
29 #include "extensions/browser/extension_registry.h" | 29 #include "extensions/browser/extension_registry.h" |
| 30 #include "extensions/browser/extension_util.h" |
30 #include "extensions/common/extension.h" | 31 #include "extensions/common/extension.h" |
31 #include "extensions/common/extension_icon_set.h" | 32 #include "extensions/common/extension_icon_set.h" |
32 #include "extensions/common/feature_switch.h" | 33 #include "extensions/common/feature_switch.h" |
33 #include "extensions/common/manifest_constants.h" | 34 #include "extensions/common/manifest_constants.h" |
34 #include "extensions/common/manifest_handlers/icons_handler.h" | 35 #include "extensions/common/manifest_handlers/icons_handler.h" |
35 #include "sync/api/sync_change.h" | 36 #include "sync/api/sync_change.h" |
36 #include "sync/api/sync_error_factory.h" | 37 #include "sync/api/sync_error_factory.h" |
37 #include "ui/gfx/image/image_family.h" | 38 #include "ui/gfx/image/image_family.h" |
38 | 39 |
39 using extensions::Extension; | 40 using extensions::Extension; |
(...skipping 10 matching lines...) Expand all Loading... |
50 DCHECK_EQ(synced_info.app_url, loaded_info.app_url); | 51 DCHECK_EQ(synced_info.app_url, loaded_info.app_url); |
51 | 52 |
52 if (!extension_service) | 53 if (!extension_service) |
53 return; | 54 return; |
54 | 55 |
55 // Use the old icons if they exist. | 56 // Use the old icons if they exist. |
56 synced_info.icons = loaded_info.icons; | 57 synced_info.icons = loaded_info.icons; |
57 CreateOrUpdateBookmarkApp(extension_service.get(), synced_info); | 58 CreateOrUpdateBookmarkApp(extension_service.get(), synced_info); |
58 } | 59 } |
59 | 60 |
| 61 bool ShouldSyncApp(const Extension* extension, Profile* profile) { |
| 62 return extensions::sync_helper::IsSyncableApp(extension) && |
| 63 !extensions::util::IsEphemeralApp(extension->id(), profile); |
| 64 } |
| 65 |
60 } // namespace | 66 } // namespace |
61 | 67 |
62 ExtensionSyncService::ExtensionSyncService(Profile* profile, | 68 ExtensionSyncService::ExtensionSyncService(Profile* profile, |
63 ExtensionPrefs* extension_prefs, | 69 ExtensionPrefs* extension_prefs, |
64 ExtensionService* extension_service) | 70 ExtensionService* extension_service) |
65 : profile_(profile), | 71 : profile_(profile), |
66 extension_prefs_(extension_prefs), | 72 extension_prefs_(extension_prefs), |
67 extension_service_(extension_service), | 73 extension_service_(extension_service), |
68 app_sync_bundle_(this), | 74 app_sync_bundle_(this), |
69 extension_sync_bundle_(this), | 75 extension_sync_bundle_(this), |
(...skipping 20 matching lines...) Expand all Loading... |
90 } | 96 } |
91 | 97 |
92 syncer::SyncChange ExtensionSyncService::PrepareToSyncUninstallExtension( | 98 syncer::SyncChange ExtensionSyncService::PrepareToSyncUninstallExtension( |
93 const extensions::Extension* extension, bool extensions_ready) { | 99 const extensions::Extension* extension, bool extensions_ready) { |
94 // Extract the data we need for sync now, but don't actually sync until we've | 100 // Extract the data we need for sync now, but don't actually sync until we've |
95 // completed the uninstallation. | 101 // completed the uninstallation. |
96 // TODO(tim): If we get here and IsSyncing is false, this will cause | 102 // TODO(tim): If we get here and IsSyncing is false, this will cause |
97 // "back from the dead" style bugs, because sync will add-back the extension | 103 // "back from the dead" style bugs, because sync will add-back the extension |
98 // that was uninstalled here when MergeDataAndStartSyncing is called. | 104 // that was uninstalled here when MergeDataAndStartSyncing is called. |
99 // See crbug.com/256795. | 105 // See crbug.com/256795. |
100 if (extensions::sync_helper::IsSyncableApp(extension)) { | 106 if (ShouldSyncApp(extension, profile_)) { |
101 if (app_sync_bundle_.IsSyncing()) | 107 if (app_sync_bundle_.IsSyncing()) |
102 return app_sync_bundle_.CreateSyncChangeToDelete(extension); | 108 return app_sync_bundle_.CreateSyncChangeToDelete(extension); |
103 else if (extensions_ready && !flare_.is_null()) | 109 else if (extensions_ready && !flare_.is_null()) |
104 flare_.Run(syncer::APPS); // Tell sync to start ASAP. | 110 flare_.Run(syncer::APPS); // Tell sync to start ASAP. |
105 } else if (extensions::sync_helper::IsSyncableExtension(extension)) { | 111 } else if (extensions::sync_helper::IsSyncableExtension(extension)) { |
106 if (extension_sync_bundle_.IsSyncing()) | 112 if (extension_sync_bundle_.IsSyncing()) |
107 return extension_sync_bundle_.CreateSyncChangeToDelete(extension); | 113 return extension_sync_bundle_.CreateSyncChangeToDelete(extension); |
108 else if (extensions_ready && !flare_.is_null()) | 114 else if (extensions_ready && !flare_.is_null()) |
109 flare_.Run(syncer::EXTENSIONS); // Tell sync to start ASAP. | 115 flare_.Run(syncer::EXTENSIONS); // Tell sync to start ASAP. |
110 } | 116 } |
(...skipping 10 matching lines...) Expand all Loading... |
121 } else if (extension_sync_bundle_.HasExtensionId(extension_id) && | 127 } else if (extension_sync_bundle_.HasExtensionId(extension_id) && |
122 sync_change.sync_data().GetDataType() == syncer::EXTENSIONS) { | 128 sync_change.sync_data().GetDataType() == syncer::EXTENSIONS) { |
123 extension_sync_bundle_.ProcessDeletion(extension_id, sync_change); | 129 extension_sync_bundle_.ProcessDeletion(extension_id, sync_change); |
124 } | 130 } |
125 } | 131 } |
126 | 132 |
127 void ExtensionSyncService::SyncEnableExtension( | 133 void ExtensionSyncService::SyncEnableExtension( |
128 const extensions::Extension& extension) { | 134 const extensions::Extension& extension) { |
129 | 135 |
130 // Syncing may not have started yet, so handle pending enables. | 136 // Syncing may not have started yet, so handle pending enables. |
131 if (extensions::sync_helper::IsSyncableApp(&extension)) | 137 if (ShouldSyncApp(&extension, profile_)) |
132 pending_app_enables_.OnExtensionEnabled(extension.id()); | 138 pending_app_enables_.OnExtensionEnabled(extension.id()); |
133 | 139 |
134 if (extensions::sync_helper::IsSyncableExtension(&extension)) | 140 if (extensions::sync_helper::IsSyncableExtension(&extension)) |
135 pending_extension_enables_.OnExtensionEnabled(extension.id()); | 141 pending_extension_enables_.OnExtensionEnabled(extension.id()); |
136 | 142 |
137 SyncExtensionChangeIfNeeded(extension); | 143 SyncExtensionChangeIfNeeded(extension); |
138 } | 144 } |
139 | 145 |
140 void ExtensionSyncService::SyncDisableExtension( | 146 void ExtensionSyncService::SyncDisableExtension( |
141 const extensions::Extension& extension) { | 147 const extensions::Extension& extension) { |
142 | 148 |
143 // Syncing may not have started yet, so handle pending enables. | 149 // Syncing may not have started yet, so handle pending enables. |
144 if (extensions::sync_helper::IsSyncableApp(&extension)) | 150 if (ShouldSyncApp(&extension, profile_)) |
145 pending_app_enables_.OnExtensionDisabled(extension.id()); | 151 pending_app_enables_.OnExtensionDisabled(extension.id()); |
146 | 152 |
147 if (extensions::sync_helper::IsSyncableExtension(&extension)) | 153 if (extensions::sync_helper::IsSyncableExtension(&extension)) |
148 pending_extension_enables_.OnExtensionDisabled(extension.id()); | 154 pending_extension_enables_.OnExtensionDisabled(extension.id()); |
149 | 155 |
150 SyncExtensionChangeIfNeeded(extension); | 156 SyncExtensionChangeIfNeeded(extension); |
151 } | 157 } |
152 | 158 |
153 syncer::SyncMergeResult ExtensionSyncService::MergeDataAndStartSyncing( | 159 syncer::SyncMergeResult ExtensionSyncService::MergeDataAndStartSyncing( |
154 syncer::ModelType type, | 160 syncer::ModelType type, |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 } | 531 } |
526 // Track pending extensions so that we can return them in GetAllSyncData(). | 532 // Track pending extensions so that we can return them in GetAllSyncData(). |
527 return false; | 533 return false; |
528 } | 534 } |
529 | 535 |
530 return true; | 536 return true; |
531 } | 537 } |
532 | 538 |
533 void ExtensionSyncService::SyncExtensionChangeIfNeeded( | 539 void ExtensionSyncService::SyncExtensionChangeIfNeeded( |
534 const Extension& extension) { | 540 const Extension& extension) { |
535 if (extensions::sync_helper::IsSyncableApp(&extension)) { | 541 if (ShouldSyncApp(&extension, profile_)) { |
536 if (app_sync_bundle_.IsSyncing()) | 542 if (app_sync_bundle_.IsSyncing()) |
537 app_sync_bundle_.SyncChangeIfNeeded(extension); | 543 app_sync_bundle_.SyncChangeIfNeeded(extension); |
538 else if (extension_service_->is_ready() && !flare_.is_null()) | 544 else if (extension_service_->is_ready() && !flare_.is_null()) |
539 flare_.Run(syncer::APPS); | 545 flare_.Run(syncer::APPS); |
540 } else if (extensions::sync_helper::IsSyncableExtension(&extension)) { | 546 } else if (extensions::sync_helper::IsSyncableExtension(&extension)) { |
541 if (extension_sync_bundle_.IsSyncing()) | 547 if (extension_sync_bundle_.IsSyncing()) |
542 extension_sync_bundle_.SyncChangeIfNeeded(extension); | 548 extension_sync_bundle_.SyncChangeIfNeeded(extension); |
543 else if (extension_service_->is_ready() && !flare_.is_null()) | 549 else if (extension_service_->is_ready() && !flare_.is_null()) |
544 flare_.Run(syncer::EXTENSIONS); | 550 flare_.Run(syncer::EXTENSIONS); |
545 } | 551 } |
546 } | 552 } |
OLD | NEW |