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_sync.h" | 5 #include "chrome/browser/sync/glue/extension_sync.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "chrome/browser/extensions/extension_updater.h" | 10 #include "chrome/browser/extensions/extension_updater.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/sync/engine/syncapi.h" | 13 #include "chrome/browser/sync/engine/syncapi.h" |
14 #include "chrome/browser/sync/glue/extension_data.h" | 14 #include "chrome/browser/sync/glue/extension_data.h" |
15 #include "chrome/browser/sync/glue/extension_sync_traits.h" | 15 #include "chrome/browser/sync/glue/extension_sync_traits.h" |
16 #include "chrome/browser/sync/glue/extension_util.h" | 16 #include "chrome/browser/sync/glue/extension_util.h" |
17 #include "chrome/browser/sync/profile_sync_service.h" | 17 #include "chrome/browser/sync/profile_sync_service.h" |
18 | 18 |
19 namespace browser_sync { | 19 namespace browser_sync { |
20 | 20 |
21 bool RootNodeHasChildren(const char* tag, | 21 bool RootNodeHasChildren(const char* tag, |
22 ProfileSyncService* sync_service, | 22 ProfileSyncService* sync_service, |
23 bool* has_children) { | 23 bool* has_children) { |
24 CHECK(has_children); | 24 CHECK(has_children); |
25 *has_children = false; | 25 *has_children = false; |
26 sync_api::ReadTransaction trans( | 26 sync_api::ReadTransaction trans(sync_service->GetUserShare()); |
27 sync_service->backend()->GetUserShareHandle()); | |
28 sync_api::ReadNode node(&trans); | 27 sync_api::ReadNode node(&trans); |
29 if (!node.InitByTagLookup(tag)) { | 28 if (!node.InitByTagLookup(tag)) { |
30 LOG(ERROR) << "Root node with tag " << tag << " does not exist"; | 29 LOG(ERROR) << "Root node with tag " << tag << " does not exist"; |
31 return false; | 30 return false; |
32 } | 31 } |
33 *has_children = node.GetFirstChildId() != sync_api::kInvalidId; | 32 *has_children = node.GetFirstChildId() != sync_api::kInvalidId; |
34 return true; | 33 return true; |
35 } | 34 } |
36 | 35 |
37 ExtensionService* GetExtensionServiceFromProfile( | 36 ExtensionService* GetExtensionServiceFromProfile( |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 140 |
142 // Gets the data from the server for extensions to be synced and | 141 // Gets the data from the server for extensions to be synced and |
143 // updates |extension_data_map|. Skips all extensions in | 142 // updates |extension_data_map|. Skips all extensions in |
144 // |unsynced_extensions|. | 143 // |unsynced_extensions|. |
145 bool SlurpServerData( | 144 bool SlurpServerData( |
146 const char* root_node_tag, | 145 const char* root_node_tag, |
147 const ExtensionSpecificsGetter extension_specifics_getter, | 146 const ExtensionSpecificsGetter extension_specifics_getter, |
148 const std::set<std::string>& unsynced_extensions, | 147 const std::set<std::string>& unsynced_extensions, |
149 ProfileSyncService* sync_service, | 148 ProfileSyncService* sync_service, |
150 ExtensionDataMap* extension_data_map) { | 149 ExtensionDataMap* extension_data_map) { |
151 sync_api::WriteTransaction trans( | 150 sync_api::WriteTransaction trans(sync_service->GetUserShare()); |
152 sync_service->backend()->GetUserShareHandle()); | |
153 sync_api::ReadNode root(&trans); | 151 sync_api::ReadNode root(&trans); |
154 if (!root.InitByTagLookup(root_node_tag)) { | 152 if (!root.InitByTagLookup(root_node_tag)) { |
155 LOG(ERROR) << GetRootNodeDoesNotExistError(root_node_tag); | 153 LOG(ERROR) << GetRootNodeDoesNotExistError(root_node_tag); |
156 return false; | 154 return false; |
157 } | 155 } |
158 | 156 |
159 int64 id = root.GetFirstChildId(); | 157 int64 id = root.GetFirstChildId(); |
160 while (id != sync_api::kInvalidId) { | 158 while (id != sync_api::kInvalidId) { |
161 sync_api::ReadNode sync_node(&trans); | 159 sync_api::ReadNode sync_node(&trans); |
162 if (!sync_node.InitByIdLookup(id)) { | 160 if (!sync_node.InitByIdLookup(id)) { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 LOG(DFATAL) << "Extension updater unexpectedly NULL; " | 315 LOG(DFATAL) << "Extension updater unexpectedly NULL; " |
318 << "auto-updates may be turned off"; | 316 << "auto-updates may be turned off"; |
319 } | 317 } |
320 } | 318 } |
321 | 319 |
322 } // namespace | 320 } // namespace |
323 | 321 |
324 bool FlushExtensionData(const ExtensionSyncTraits& traits, | 322 bool FlushExtensionData(const ExtensionSyncTraits& traits, |
325 const ExtensionDataMap& extension_data_map, | 323 const ExtensionDataMap& extension_data_map, |
326 ProfileSyncService* sync_service) { | 324 ProfileSyncService* sync_service) { |
327 sync_api::WriteTransaction trans( | 325 sync_api::WriteTransaction trans(sync_service->GetUserShare()); |
328 sync_service->backend()->GetUserShareHandle()); | |
329 sync_api::ReadNode root(&trans); | 326 sync_api::ReadNode root(&trans); |
330 if (!root.InitByTagLookup(traits.root_node_tag)) { | 327 if (!root.InitByTagLookup(traits.root_node_tag)) { |
331 LOG(ERROR) << GetRootNodeDoesNotExistError(traits.root_node_tag); | 328 LOG(ERROR) << GetRootNodeDoesNotExistError(traits.root_node_tag); |
332 return false; | 329 return false; |
333 } | 330 } |
334 | 331 |
335 ExtensionService* extensions_service = | 332 ExtensionService* extensions_service = |
336 GetExtensionServiceFromProfileSyncService(sync_service); | 333 GetExtensionServiceFromProfileSyncService(sync_service); |
337 | 334 |
338 // Update server and client as necessary. | 335 // Update server and client as necessary. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 | 378 |
382 ExtensionService* extensions_service = | 379 ExtensionService* extensions_service = |
383 GetExtensionServiceFromProfileSyncService(sync_service); | 380 GetExtensionServiceFromProfileSyncService(sync_service); |
384 sync_pb::ExtensionSpecifics client_data; | 381 sync_pb::ExtensionSpecifics client_data; |
385 GetExtensionSpecifics(extension, extensions_service->extension_prefs(), | 382 GetExtensionSpecifics(extension, extensions_service->extension_prefs(), |
386 &client_data); | 383 &client_data); |
387 DcheckIsExtensionSpecificsValid(client_data); | 384 DcheckIsExtensionSpecificsValid(client_data); |
388 ExtensionData extension_data = | 385 ExtensionData extension_data = |
389 ExtensionData::FromData(ExtensionData::CLIENT, client_data); | 386 ExtensionData::FromData(ExtensionData::CLIENT, client_data); |
390 | 387 |
391 sync_api::WriteTransaction trans( | 388 sync_api::WriteTransaction trans(sync_service->GetUserShare()); |
392 sync_service->backend()->GetUserShareHandle()); | |
393 | 389 |
394 sync_api::ReadNode node(&trans); | 390 sync_api::ReadNode node(&trans); |
395 if (node.InitByClientTagLookup(traits.model_type, id)) { | 391 if (node.InitByClientTagLookup(traits.model_type, id)) { |
396 sync_pb::ExtensionSpecifics server_data = | 392 sync_pb::ExtensionSpecifics server_data = |
397 (*traits.extension_specifics_getter)(node); | 393 (*traits.extension_specifics_getter)(node); |
398 if (IsExtensionSpecificsValid(server_data)) { | 394 if (IsExtensionSpecificsValid(server_data)) { |
399 // If server node exists and is valid, update |extension_data| | 395 // If server node exists and is valid, update |extension_data| |
400 // from it (but with it taking precedence). | 396 // from it (but with it taking precedence). |
401 extension_data = | 397 extension_data = |
402 ExtensionData::FromData(ExtensionData::SERVER, server_data); | 398 ExtensionData::FromData(ExtensionData::SERVER, server_data); |
(...skipping 18 matching lines...) Expand all Loading... |
421 // again once the auto-update is finished. | 417 // again once the auto-update is finished. |
422 // | 418 // |
423 // TODO(akalin): Figure out a way to tell when the above happens, | 419 // TODO(akalin): Figure out a way to tell when the above happens, |
424 // so we know exactly what NeedsUpdate(CLIENT) should return. | 420 // so we know exactly what NeedsUpdate(CLIENT) should return. |
425 return true; | 421 return true; |
426 } | 422 } |
427 | 423 |
428 void RemoveServerData(const ExtensionSyncTraits& traits, | 424 void RemoveServerData(const ExtensionSyncTraits& traits, |
429 const std::string& id, | 425 const std::string& id, |
430 ProfileSyncService* sync_service) { | 426 ProfileSyncService* sync_service) { |
431 sync_api::WriteTransaction trans( | 427 sync_api::WriteTransaction trans(sync_service->GetUserShare()); |
432 sync_service->backend()->GetUserShareHandle()); | |
433 sync_api::WriteNode write_node(&trans); | 428 sync_api::WriteNode write_node(&trans); |
434 if (write_node.InitByClientTagLookup(traits.model_type, id)) { | 429 if (write_node.InitByClientTagLookup(traits.model_type, id)) { |
435 write_node.Remove(); | 430 write_node.Remove(); |
436 } else { | 431 } else { |
437 LOG(ERROR) << "Server data does not exist for extension " << id; | 432 LOG(ERROR) << "Server data does not exist for extension " << id; |
438 } | 433 } |
439 } | 434 } |
440 | 435 |
441 void UpdateClient(const ExtensionSyncTraits& traits, | 436 void UpdateClient(const ExtensionSyncTraits& traits, |
442 const sync_pb::ExtensionSpecifics& server_data, | 437 const sync_pb::ExtensionSpecifics& server_data, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 } else { | 476 } else { |
482 LOG(WARNING) << "Ignoring server data for invalid or " | 477 LOG(WARNING) << "Ignoring server data for invalid or " |
483 << "non-syncable extension " << extension->id(); | 478 << "non-syncable extension " << extension->id(); |
484 } | 479 } |
485 } else { | 480 } else { |
486 LOG(ERROR) << "Trying to uninstall nonexistent extension " << id; | 481 LOG(ERROR) << "Trying to uninstall nonexistent extension " << id; |
487 } | 482 } |
488 } | 483 } |
489 | 484 |
490 } // namespace browser_sync | 485 } // namespace browser_sync |
OLD | NEW |