| 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/app_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/api/sync_error.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/glue/extension_sync_traits.h" | |
| 14 #include "chrome/browser/sync/internal_api/read_transaction.h" | |
| 15 #include "chrome/browser/sync/profile_sync_service.h" | |
| 16 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | |
| 17 #include "content/browser/browser_thread.h" | |
| 18 | |
| 19 namespace browser_sync { | |
| 20 | |
| 21 AppModelAssociator::AppModelAssociator( | |
| 22 ExtensionServiceInterface* extension_service, | |
| 23 sync_api::UserShare* user_share) | |
| 24 : traits_(GetAppSyncTraits()), 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 AppModelAssociator::~AppModelAssociator() { | |
| 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 33 } | |
| 34 | |
| 35 bool AppModelAssociator::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 app 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 app data.", model_type()); | |
| 46 return false; | |
| 47 } | |
| 48 | |
| 49 return true; | |
| 50 } | |
| 51 | |
| 52 bool AppModelAssociator::DisassociateModels(SyncError* error) { | |
| 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 54 // Nothing to do. | |
| 55 return true; | |
| 56 } | |
| 57 | |
| 58 bool AppModelAssociator::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 AppModelAssociator::AbortAssociation() { | |
| 64 // No implementation needed, this associator runs on the main | |
| 65 // thread. | |
| 66 } | |
| 67 | |
| 68 bool AppModelAssociator::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 |