Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: chrome/browser/sync/glue/extension_change_processor.cc

Issue 6852029: [Sync] Move some extension-sync-related logic to ExtensionService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address asargent's comments Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/stl_util-inl.h" 11 #include "base/stl_util-inl.h"
12 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/extension_sync_data.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/sync/glue/extension_sync.h" 15 #include "chrome/browser/sync/glue/extension_sync.h"
15 #include "chrome/browser/sync/glue/extension_util.h" 16 #include "chrome/browser/sync/glue/extension_util.h"
16 #include "chrome/browser/sync/profile_sync_service.h" 17 #include "chrome/browser/sync/profile_sync_service.h"
17 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" 18 #include "chrome/browser/sync/protocol/extension_specifics.pb.h"
18 #include "chrome/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension.h"
19 #include "content/browser/browser_thread.h" 20 #include "content/browser/browser_thread.h"
20 #include "content/common/notification_details.h" 21 #include "content/common/notification_details.h"
21 #include "content/common/notification_source.h" 22 #include "content/common/notification_source.h"
22 23
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 void ExtensionChangeProcessor::ApplyChangesFromSyncModel( 95 void ExtensionChangeProcessor::ApplyChangesFromSyncModel(
95 const sync_api::BaseTransaction* trans, 96 const sync_api::BaseTransaction* trans,
96 const sync_api::SyncManager::ChangeRecord* changes, 97 const sync_api::SyncManager::ChangeRecord* changes,
97 int change_count) { 98 int change_count) {
98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
99 if (!running()) { 100 if (!running()) {
100 return; 101 return;
101 } 102 }
102 for (int i = 0; i < change_count; ++i) { 103 for (int i = 0; i < change_count; ++i) {
103 const sync_api::SyncManager::ChangeRecord& change = changes[i]; 104 const sync_api::SyncManager::ChangeRecord& change = changes[i];
105 sync_pb::ExtensionSpecifics specifics;
104 switch (change.action) { 106 switch (change.action) {
105 case sync_api::SyncManager::ChangeRecord::ACTION_ADD: 107 case sync_api::SyncManager::ChangeRecord::ACTION_ADD:
106 case sync_api::SyncManager::ChangeRecord::ACTION_UPDATE: { 108 case sync_api::SyncManager::ChangeRecord::ACTION_UPDATE: {
107 sync_api::ReadNode node(trans); 109 sync_api::ReadNode node(trans);
108 if (!node.InitByIdLookup(change.id)) { 110 if (!node.InitByIdLookup(change.id)) {
109 std::stringstream error; 111 std::stringstream error;
110 error << "Extension node lookup failed for change " << change.id 112 error << "Extension node lookup failed for change " << change.id
111 << " of action type " << change.action; 113 << " of action type " << change.action;
112 error_handler()->OnUnrecoverableError(FROM_HERE, error.str()); 114 error_handler()->OnUnrecoverableError(FROM_HERE, error.str());
113 return; 115 return;
114 } 116 }
115 DCHECK_EQ(node.GetModelType(), traits_.model_type); 117 DCHECK_EQ(node.GetModelType(), traits_.model_type);
116 const sync_pb::ExtensionSpecifics& specifics = 118 specifics = (*traits_.extension_specifics_getter)(node);
117 (*traits_.extension_specifics_getter)(node);
118 if (!IsExtensionSpecificsValid(specifics)) {
119 std::string error =
120 std::string("Invalid server specifics: ") +
121 ExtensionSpecificsToString(specifics);
122 error_handler()->OnUnrecoverableError(FROM_HERE, error);
123 return;
124 }
125 StopObserving();
126 UpdateClient(traits_, specifics, extension_service_);
127 StartObserving();
128 break; 119 break;
129 } 120 }
130 case sync_api::SyncManager::ChangeRecord::ACTION_DELETE: { 121 case sync_api::SyncManager::ChangeRecord::ACTION_DELETE: {
131 sync_pb::ExtensionSpecifics specifics; 122 if (!(*traits_.extension_specifics_entity_getter)(
132 if ((*traits_.extension_specifics_entity_getter)(
133 change.specifics, &specifics)) { 123 change.specifics, &specifics)) {
134 StopObserving();
135 RemoveFromClient(traits_, specifics.id(), extension_service_);
136 StartObserving();
137 } else {
138 std::stringstream error; 124 std::stringstream error;
139 error << "Could not get extension ID for deleted node " 125 error << "Could not get extension specifics from deleted node "
140 << change.id; 126 << change.id;
141 error_handler()->OnUnrecoverableError(FROM_HERE, error.str()); 127 error_handler()->OnUnrecoverableError(FROM_HERE, error.str());
142 LOG(DFATAL) << error.str(); 128 LOG(DFATAL) << error.str();
143 } 129 }
144 break; 130 break;
145 } 131 }
146 } 132 }
133 ExtensionSyncData sync_data;
134 if (!GetExtensionSyncData(specifics, &sync_data)) {
135 // TODO(akalin): Should probably recover or drop.
136 std::string error =
137 std::string("Invalid server specifics: ") +
138 ExtensionSpecificsToString(specifics);
139 error_handler()->OnUnrecoverableError(FROM_HERE, error);
140 return;
141 }
142 sync_data.uninstalled =
143 (change.action == sync_api::SyncManager::ChangeRecord::ACTION_DELETE);
144 StopObserving();
145 extension_service_->ProcessSyncData(sync_data,
146 traits_.is_valid_and_syncable);
147 StartObserving();
147 } 148 }
148 } 149 }
149 150
150 void ExtensionChangeProcessor::StartImpl(Profile* profile) { 151 void ExtensionChangeProcessor::StartImpl(Profile* profile) {
151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
152 profile_ = profile; 153 profile_ = profile;
153 extension_service_ = profile_->GetExtensionService(); 154 extension_service_ = profile_->GetExtensionService();
154 user_share_ = profile_->GetProfileSyncService()->GetUserShare(); 155 user_share_ = profile_->GetProfileSyncService()->GetUserShare();
155 DCHECK(profile_); 156 DCHECK(profile_);
156 DCHECK(extension_service_); 157 DCHECK(extension_service_);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 192 }
192 193
193 void ExtensionChangeProcessor::StopObserving() { 194 void ExtensionChangeProcessor::StopObserving() {
194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
195 DCHECK(profile_); 196 DCHECK(profile_);
196 VLOG(1) << "Unobserving all notifications"; 197 VLOG(1) << "Unobserving all notifications";
197 notification_registrar_.RemoveAll(); 198 notification_registrar_.RemoveAll();
198 } 199 }
199 200
200 } // namespace browser_sync 201 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/extensions/mock_extension_service.h ('k') | chrome/browser/sync/glue/extension_sync.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698