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