| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/sync/glue/extension_model_associator.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/tracked.h" | |
| 9 #include "chrome/browser/extensions/extension_sync_data.h" | |
| 10 #include "chrome/browser/sync/glue/extension_sync_traits.h" | |
| 11 #include "chrome/browser/sync/glue/extension_sync.h" | |
| 12 #include "chrome/browser/sync/glue/extension_sync_traits.h" | |
| 13 #include "chrome/browser/sync/internal_api/read_transaction.h" | |
| 14 #include "chrome/browser/sync/profile_sync_service.h" | |
| 15 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | |
| 16 #include "content/browser/browser_thread.h" | |
| 17 | |
| 18 namespace browser_sync { | |
| 19 | |
| 20 ExtensionModelAssociator::ExtensionModelAssociator( | |
| 21 ExtensionServiceInterface* extension_service, | |
| 22 sync_api::UserShare* user_share) | |
| 23 : traits_(GetExtensionSyncTraits()), | |
| 24 extension_service_(extension_service), | |
| 25 user_share_(user_share) { | |
| 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 27 DCHECK(extension_service_); | |
| 28 DCHECK(user_share_); | |
| 29 } | |
| 30 | |
| 31 ExtensionModelAssociator::~ExtensionModelAssociator() { | |
| 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 33 } | |
| 34 | |
| 35 bool ExtensionModelAssociator::AssociateModels(SyncError* error) { | |
| 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 37 ExtensionDataMap extension_data_map; | |
| 38 if (!SlurpExtensionData( | |
| 39 traits_, *extension_service_, user_share_, &extension_data_map)) { | |
| 40 error->Reset(FROM_HERE, "Failed to get extension data.", model_type()); | |
| 41 return false; | |
| 42 } | |
| 43 if (!FlushExtensionData( | |
| 44 traits_, extension_data_map, extension_service_, user_share_)) { | |
| 45 error->Reset(FROM_HERE, "Failed to flush extension data.", model_type()); | |
| 46 return false; | |
| 47 } | |
| 48 | |
| 49 return true; | |
| 50 } | |
| 51 | |
| 52 bool ExtensionModelAssociator::DisassociateModels(SyncError* error) { | |
| 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 54 // Nothing to do. | |
| 55 return true; | |
| 56 } | |
| 57 | |
| 58 bool ExtensionModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { | |
| 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 60 return RootNodeHasChildren(traits_.root_node_tag, user_share_, has_nodes); | |
| 61 } | |
| 62 | |
| 63 void ExtensionModelAssociator::AbortAssociation() { | |
| 64 // No implementation needed, this associator runs on the main | |
| 65 // thread. | |
| 66 } | |
| 67 | |
| 68 bool ExtensionModelAssociator::CryptoReadyIfNecessary() { | |
| 69 // We only access the cryptographer while holding a transaction. | |
| 70 sync_api::ReadTransaction trans(FROM_HERE, user_share_); | |
| 71 const syncable::ModelTypeSet& encrypted_types = | |
| 72 sync_api::GetEncryptedTypes(&trans); | |
| 73 return encrypted_types.count(traits_.model_type) == 0 || | |
| 74 trans.GetCryptographer()->is_ready(); | |
| 75 } | |
| 76 | |
| 77 } // namespace browser_sync | |
| OLD | NEW |