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