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