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/app_sync_bundle.h" | 5 #include "chrome/browser/extensions/app_sync_bundle.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/extensions/extension_sorting.h" | 9 #include "chrome/browser/extensions/extension_sorting.h" |
10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
11 #include "chrome/common/extensions/extension_set.h" | 11 #include "chrome/common/extensions/extension_set.h" |
12 #include "sync/api/sync_change_processor.h" | 12 #include "sync/api/sync_change_processor.h" |
13 #include "sync/api/sync_error_factory.h" | 13 #include "sync/api/sync_error_factory.h" |
14 | 14 |
15 namespace extensions { | 15 namespace extensions { |
16 | 16 |
17 AppSyncBundle::AppSyncBundle(ExtensionService* extension_service) | 17 AppSyncBundle::AppSyncBundle(ExtensionService* extension_service) |
18 : extension_service_(extension_service), | 18 : extension_service_(extension_service), |
19 sync_processor_(NULL) {} | 19 sync_processor_(NULL) {} |
20 | 20 |
21 AppSyncBundle::~AppSyncBundle() {} | 21 AppSyncBundle::~AppSyncBundle() {} |
22 | 22 |
23 void AppSyncBundle::SetupSync(SyncChangeProcessor* sync_change_processor, | 23 void AppSyncBundle::SetupSync(csync::SyncChangeProcessor* sync_change_processor, |
24 SyncErrorFactory* sync_error_factory, | 24 csync::SyncErrorFactory* sync_error_factory, |
25 const SyncDataList& initial_sync_data) { | 25 const csync::SyncDataList& initial_sync_data) { |
26 sync_processor_.reset(sync_change_processor); | 26 sync_processor_.reset(sync_change_processor); |
27 sync_error_factory_.reset(sync_error_factory); | 27 sync_error_factory_.reset(sync_error_factory); |
28 | 28 |
29 for (SyncDataList::const_iterator i = initial_sync_data.begin(); | 29 for (csync::SyncDataList::const_iterator i = initial_sync_data.begin(); |
30 i != initial_sync_data.end(); | 30 i != initial_sync_data.end(); |
31 ++i) { | 31 ++i) { |
32 AppSyncData app_sync_data(*i); | 32 AppSyncData app_sync_data(*i); |
33 AddApp(app_sync_data.id()); | 33 AddApp(app_sync_data.id()); |
34 extension_service_->ProcessAppSyncData(app_sync_data); | 34 extension_service_->ProcessAppSyncData(app_sync_data); |
35 } | 35 } |
36 } | 36 } |
37 | 37 |
38 void AppSyncBundle::Reset() { | 38 void AppSyncBundle::Reset() { |
39 sync_processor_.reset(); | 39 sync_processor_.reset(); |
40 sync_error_factory_.reset(); | 40 sync_error_factory_.reset(); |
41 synced_apps_.clear(); | 41 synced_apps_.clear(); |
42 pending_sync_data_.clear(); | 42 pending_sync_data_.clear(); |
43 } | 43 } |
44 | 44 |
45 SyncChange AppSyncBundle::CreateSyncChangeToDelete(const Extension* extension) | 45 csync::SyncChange AppSyncBundle::CreateSyncChangeToDelete( |
| 46 const Extension* extension) |
46 const { | 47 const { |
47 AppSyncData sync_data = extension_service_->GetAppSyncData(*extension); | 48 AppSyncData sync_data = extension_service_->GetAppSyncData(*extension); |
48 return sync_data.GetSyncChange(SyncChange::ACTION_DELETE); | 49 return sync_data.GetSyncChange(csync::SyncChange::ACTION_DELETE); |
49 } | 50 } |
50 | 51 |
51 void AppSyncBundle::ProcessDeletion(std::string extension_id, | 52 void AppSyncBundle::ProcessDeletion(std::string extension_id, |
52 const SyncChange& sync_change) { | 53 const csync::SyncChange& sync_change) { |
53 RemoveApp(extension_id); | 54 RemoveApp(extension_id); |
54 sync_processor_->ProcessSyncChanges(FROM_HERE, | 55 sync_processor_->ProcessSyncChanges(FROM_HERE, |
55 SyncChangeList(1, sync_change)); | 56 csync::SyncChangeList(1, sync_change)); |
56 } | 57 } |
57 | 58 |
58 SyncChange AppSyncBundle::CreateSyncChange(const SyncData& sync_data) { | 59 csync::SyncChange AppSyncBundle::CreateSyncChange( |
| 60 const csync::SyncData& sync_data) { |
59 if (HasExtensionId(sync_data.GetTag())) { | 61 if (HasExtensionId(sync_data.GetTag())) { |
60 return SyncChange(SyncChange::ACTION_UPDATE, sync_data); | 62 return csync::SyncChange(csync::SyncChange::ACTION_UPDATE, sync_data); |
61 } else { | 63 } else { |
62 AddApp(sync_data.GetTag()); | 64 AddApp(sync_data.GetTag()); |
63 return SyncChange(SyncChange::ACTION_ADD, sync_data); | 65 return csync::SyncChange(csync::SyncChange::ACTION_ADD, sync_data); |
64 } | 66 } |
65 } | 67 } |
66 | 68 |
67 SyncDataList AppSyncBundle::GetAllSyncData() const { | 69 csync::SyncDataList AppSyncBundle::GetAllSyncData() const { |
68 std::vector<AppSyncData> app_sync_data = | 70 std::vector<AppSyncData> app_sync_data = |
69 extension_service_->GetAppSyncDataList(); | 71 extension_service_->GetAppSyncDataList(); |
70 SyncDataList result(app_sync_data.size()); | 72 csync::SyncDataList result(app_sync_data.size()); |
71 for (int i = 0; i < static_cast<int>(app_sync_data.size()); ++i) { | 73 for (int i = 0; i < static_cast<int>(app_sync_data.size()); ++i) { |
72 result[i] = app_sync_data[i].GetSyncData(); | 74 result[i] = app_sync_data[i].GetSyncData(); |
73 } | 75 } |
74 return result; | 76 return result; |
75 } | 77 } |
76 | 78 |
77 void AppSyncBundle::SyncChangeIfNeeded(const Extension& extension) { | 79 void AppSyncBundle::SyncChangeIfNeeded(const Extension& extension) { |
78 AppSyncData app_sync_data = extension_service_->GetAppSyncData(extension); | 80 AppSyncData app_sync_data = extension_service_->GetAppSyncData(extension); |
79 | 81 |
80 SyncChangeList sync_change_list(1, app_sync_data.GetSyncChange( | 82 csync::SyncChangeList sync_change_list(1, app_sync_data.GetSyncChange( |
81 HasExtensionId(extension.id()) ? | 83 HasExtensionId(extension.id()) ? |
82 SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD)); | 84 csync::SyncChange::ACTION_UPDATE : csync::SyncChange::ACTION_ADD)); |
83 sync_processor_->ProcessSyncChanges(FROM_HERE, sync_change_list); | 85 sync_processor_->ProcessSyncChanges(FROM_HERE, sync_change_list); |
84 MarkPendingAppSynced(extension.id()); | 86 MarkPendingAppSynced(extension.id()); |
85 } | 87 } |
86 | 88 |
87 void AppSyncBundle::ProcessSyncChange(AppSyncData app_sync_data) { | 89 void AppSyncBundle::ProcessSyncChange(AppSyncData app_sync_data) { |
88 if (app_sync_data.uninstalled()) | 90 if (app_sync_data.uninstalled()) |
89 RemoveApp(app_sync_data.id()); | 91 RemoveApp(app_sync_data.id()); |
90 else | 92 else |
91 AddApp(app_sync_data.id()); | 93 AddApp(app_sync_data.id()); |
92 extension_service_->ProcessAppSyncData(app_sync_data); | 94 extension_service_->ProcessAppSyncData(app_sync_data); |
93 } | 95 } |
94 | 96 |
95 void AppSyncBundle::ProcessSyncChangeList(SyncChangeList sync_change_list) { | 97 void AppSyncBundle::ProcessSyncChangeList( |
| 98 csync::SyncChangeList sync_change_list) { |
96 sync_processor_->ProcessSyncChanges(FROM_HERE, sync_change_list); | 99 sync_processor_->ProcessSyncChanges(FROM_HERE, sync_change_list); |
97 extension_service_->extension_prefs()->extension_sorting()-> | 100 extension_service_->extension_prefs()->extension_sorting()-> |
98 FixNTPOrdinalCollisions(); | 101 FixNTPOrdinalCollisions(); |
99 } | 102 } |
100 | 103 |
101 bool AppSyncBundle::HasExtensionId(const std::string& id) const { | 104 bool AppSyncBundle::HasExtensionId(const std::string& id) const { |
102 return synced_apps_.find(id) != synced_apps_.end(); | 105 return synced_apps_.find(id) != synced_apps_.end(); |
103 } | 106 } |
104 | 107 |
105 bool AppSyncBundle::HasPendingExtensionId(const std::string& id) const { | 108 bool AppSyncBundle::HasPendingExtensionId(const std::string& id) const { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 156 } |
154 | 157 |
155 | 158 |
156 void AppSyncBundle::MarkPendingAppSynced(const std::string& id) { | 159 void AppSyncBundle::MarkPendingAppSynced(const std::string& id) { |
157 pending_sync_data_.erase(id); | 160 pending_sync_data_.erase(id); |
158 synced_apps_.insert(id); | 161 synced_apps_.insert(id); |
159 } | 162 } |
160 | 163 |
161 | 164 |
162 } // namespace extensions | 165 } // namespace extensions |
OLD | NEW |