| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/sync/glue/extension_change_processor.h" | 5 #include "chrome/browser/sync/glue/extension_change_processor.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "chrome/browser/chrome_thread.h" | 11 #include "chrome/browser/chrome_thread.h" |
| 12 #include "chrome/browser/extensions/extensions_service.h" |
| 13 #include "chrome/browser/profile.h" |
| 12 #include "chrome/browser/sync/engine/syncapi.h" | 14 #include "chrome/browser/sync/engine/syncapi.h" |
| 13 #include "chrome/browser/sync/glue/extension_model_associator.h" | 15 #include "chrome/browser/sync/glue/extension_model_associator.h" |
| 14 #include "chrome/browser/sync/glue/extension_util.h" | 16 #include "chrome/browser/sync/glue/extension_util.h" |
| 15 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/notification_details.h" | 18 #include "chrome/common/notification_details.h" |
| 17 #include "chrome/common/notification_source.h" | 19 #include "chrome/common/notification_source.h" |
| 18 | 20 |
| 19 namespace browser_sync { | 21 namespace browser_sync { |
| 20 | 22 |
| 21 ExtensionChangeProcessor::ExtensionChangeProcessor( | 23 ExtensionChangeProcessor::ExtensionChangeProcessor( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 44 DCHECK(running()); | 46 DCHECK(running()); |
| 45 DCHECK(profile_); | 47 DCHECK(profile_); |
| 46 switch (type.value) { | 48 switch (type.value) { |
| 47 case NotificationType::EXTENSION_LOADED: | 49 case NotificationType::EXTENSION_LOADED: |
| 48 case NotificationType::EXTENSION_UPDATE_DISABLED: | 50 case NotificationType::EXTENSION_UPDATE_DISABLED: |
| 49 case NotificationType::EXTENSION_UNLOADED: | 51 case NotificationType::EXTENSION_UNLOADED: |
| 50 case NotificationType::EXTENSION_UNLOADED_DISABLED: { | 52 case NotificationType::EXTENSION_UNLOADED_DISABLED: { |
| 51 DCHECK_EQ(Source<Profile>(source).ptr(), profile_); | 53 DCHECK_EQ(Source<Profile>(source).ptr(), profile_); |
| 52 Extension* extension = Details<Extension>(details).ptr(); | 54 Extension* extension = Details<Extension>(details).ptr(); |
| 53 CHECK(extension); | 55 CHECK(extension); |
| 56 // Ignore non-syncable extensions. |
| 54 if (!IsExtensionSyncable(*extension)) { | 57 if (!IsExtensionSyncable(*extension)) { |
| 55 return; | 58 return; |
| 56 } | 59 } |
| 57 const std::string& id = extension->id(); | 60 const std::string& id = extension->id(); |
| 58 LOG(INFO) << "Got change notification of type " << type.value | 61 LOG(INFO) << "Got change notification of type " << type.value |
| 59 << " for extension " << id; | 62 << " for extension " << id; |
| 60 if (!extension_model_associator_->OnClientUpdate(id)) { | 63 if (!extension_model_associator_->OnClientUpdate(id)) { |
| 61 std::string error = std::string("Client update failed for ") + id; | 64 std::string error = std::string("Client update failed for ") + id; |
| 62 error_handler()->OnUnrecoverableError(FROM_HERE, error); | 65 error_handler()->OnUnrecoverableError(FROM_HERE, error); |
| 63 return; | 66 return; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 DCHECK_EQ(node.GetModelType(), syncable::EXTENSIONS); | 98 DCHECK_EQ(node.GetModelType(), syncable::EXTENSIONS); |
| 96 const sync_pb::ExtensionSpecifics& specifics = | 99 const sync_pb::ExtensionSpecifics& specifics = |
| 97 node.GetExtensionSpecifics(); | 100 node.GetExtensionSpecifics(); |
| 98 if (!IsExtensionSpecificsValid(specifics)) { | 101 if (!IsExtensionSpecificsValid(specifics)) { |
| 99 std::string error = | 102 std::string error = |
| 100 std::string("Invalid server specifics: ") + | 103 std::string("Invalid server specifics: ") + |
| 101 ExtensionSpecificsToString(specifics); | 104 ExtensionSpecificsToString(specifics); |
| 102 error_handler()->OnUnrecoverableError(FROM_HERE, error); | 105 error_handler()->OnUnrecoverableError(FROM_HERE, error); |
| 103 return; | 106 return; |
| 104 } | 107 } |
| 108 const std::string& id = specifics.id(); |
| 109 CHECK(profile_); |
| 110 ExtensionsService* extensions_service = |
| 111 profile_->GetExtensionsService(); |
| 112 CHECK(extensions_service); |
| 113 Extension* extension = |
| 114 extensions_service->GetExtensionById(id, true); |
| 115 if (extension && !IsExtensionSyncable(*extension)) { |
| 116 LOG(WARNING) << "Not updating unsyncable extension " << id; |
| 117 return; |
| 118 } |
| 105 StopObserving(); | 119 StopObserving(); |
| 106 extension_model_associator_->OnServerUpdate(specifics); | 120 extension_model_associator_->OnServerUpdate(specifics, extension); |
| 107 StartObserving(); | 121 StartObserving(); |
| 108 break; | 122 break; |
| 109 } | 123 } |
| 110 case sync_api::SyncManager::ChangeRecord::ACTION_DELETE: { | 124 case sync_api::SyncManager::ChangeRecord::ACTION_DELETE: { |
| 111 StopObserving(); | 125 if (!change.specifics.HasExtension(sync_pb::extension)) { |
| 112 if (change.specifics.HasExtension(sync_pb::extension)) { | |
| 113 extension_model_associator_->OnServerRemove( | |
| 114 change.specifics.GetExtension(sync_pb::extension).id()); | |
| 115 } else { | |
| 116 std::stringstream error; | 126 std::stringstream error; |
| 117 error << "Could not get extension ID for deleted node " | 127 error << "Could not get extension ID for delete node " |
| 118 << change.id; | 128 << change.id; |
| 119 error_handler()->OnUnrecoverableError(FROM_HERE, error.str()); | 129 error_handler()->OnUnrecoverableError(FROM_HERE, error.str()); |
| 120 LOG(DFATAL) << error.str(); | 130 LOG(DFATAL) << error.str(); |
| 131 return; |
| 121 } | 132 } |
| 133 const std::string& id = |
| 134 change.specifics.GetExtension(sync_pb::extension).id(); |
| 135 CHECK(profile_); |
| 136 ExtensionsService* extensions_service = |
| 137 profile_->GetExtensionsService(); |
| 138 CHECK(extensions_service); |
| 139 Extension* extension = |
| 140 extensions_service->GetExtensionById(id, true); |
| 141 if (!extension) { |
| 142 LOG(ERROR) << "Trying to uninstall nonexistent extension " << id |
| 143 << " for delete node " << change.id; |
| 144 return; |
| 145 } |
| 146 if (!IsExtensionSyncable(*extension)) { |
| 147 LOG(WARNING) << "Not uninstalling unsyncable extension " << id |
| 148 << " for delete node " << change.id; |
| 149 return; |
| 150 } |
| 151 StopObserving(); |
| 152 extensions_service->UninstallExtension(id, false); |
| 122 StartObserving(); | 153 StartObserving(); |
| 123 break; | 154 break; |
| 124 } | 155 } |
| 125 } | 156 } |
| 126 } | 157 } |
| 127 } | 158 } |
| 128 | 159 |
| 129 void ExtensionChangeProcessor::StartImpl(Profile* profile) { | 160 void ExtensionChangeProcessor::StartImpl(Profile* profile) { |
| 130 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 161 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 131 DCHECK(profile); | 162 DCHECK(profile); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 } | 195 } |
| 165 | 196 |
| 166 void ExtensionChangeProcessor::StopObserving() { | 197 void ExtensionChangeProcessor::StopObserving() { |
| 167 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 198 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 168 DCHECK(profile_); | 199 DCHECK(profile_); |
| 169 LOG(INFO) << "Unobserving all notifications"; | 200 LOG(INFO) << "Unobserving all notifications"; |
| 170 notification_registrar_.RemoveAll(); | 201 notification_registrar_.RemoveAll(); |
| 171 } | 202 } |
| 172 | 203 |
| 173 } // namespace browser_sync | 204 } // namespace browser_sync |
| OLD | NEW |