| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "sync/internal_api/sync_manager.h" | 5 #include "sync/internal_api/sync_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 2052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2063 Cryptographer* cryptographer = trans.GetCryptographer(); | 2063 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2064 // If we've completed a sync cycle and the cryptographer isn't ready | 2064 // If we've completed a sync cycle and the cryptographer isn't ready |
| 2065 // yet, prompt the user for a passphrase. | 2065 // yet, prompt the user for a passphrase. |
| 2066 if (cryptographer->has_pending_keys()) { | 2066 if (cryptographer->has_pending_keys()) { |
| 2067 DVLOG(1) << "OnPassPhraseRequired Sent"; | 2067 DVLOG(1) << "OnPassPhraseRequired Sent"; |
| 2068 sync_pb::EncryptedData pending_keys = cryptographer->GetPendingKeys(); | 2068 sync_pb::EncryptedData pending_keys = cryptographer->GetPendingKeys(); |
| 2069 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2069 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 2070 OnPassphraseRequired(sync_api::REASON_DECRYPTION, | 2070 OnPassphraseRequired(sync_api::REASON_DECRYPTION, |
| 2071 pending_keys)); | 2071 pending_keys)); |
| 2072 } else if (!cryptographer->is_ready() && | 2072 } else if (!cryptographer->is_ready() && |
| 2073 event.snapshot->initial_sync_ended.Has(syncable::NIGORI)) { | 2073 event.snapshot.initial_sync_ended().Has(syncable::NIGORI)) { |
| 2074 DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not " | 2074 DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not " |
| 2075 << "ready"; | 2075 << "ready"; |
| 2076 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2076 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 2077 OnPassphraseRequired(sync_api::REASON_ENCRYPTION, | 2077 OnPassphraseRequired(sync_api::REASON_ENCRYPTION, |
| 2078 sync_pb::EncryptedData())); | 2078 sync_pb::EncryptedData())); |
| 2079 } | 2079 } |
| 2080 | 2080 |
| 2081 NotifyCryptographerState(cryptographer); | 2081 NotifyCryptographerState(cryptographer); |
| 2082 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); | 2082 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); |
| 2083 } | 2083 } |
| 2084 | 2084 |
| 2085 if (!initialized_) { | 2085 if (!initialized_) { |
| 2086 LOG(INFO) << "OnSyncCycleCompleted not sent because sync api is not " | 2086 LOG(INFO) << "OnSyncCycleCompleted not sent because sync api is not " |
| 2087 << "initialized"; | 2087 << "initialized"; |
| 2088 return; | 2088 return; |
| 2089 } | 2089 } |
| 2090 | 2090 |
| 2091 if (!event.snapshot->has_more_to_sync) { | 2091 if (!event.snapshot.has_more_to_sync()) { |
| 2092 // To account for a nigori node arriving with stale/bad data, we ensure | 2092 // To account for a nigori node arriving with stale/bad data, we ensure |
| 2093 // that the nigori node is up to date at the end of each cycle. | 2093 // that the nigori node is up to date at the end of each cycle. |
| 2094 WriteTransaction trans(FROM_HERE, GetUserShare()); | 2094 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 2095 WriteNode nigori_node(&trans); | 2095 WriteNode nigori_node(&trans); |
| 2096 if (nigori_node.InitByTagLookup(kNigoriTag) == | 2096 if (nigori_node.InitByTagLookup(kNigoriTag) == |
| 2097 sync_api::BaseNode::INIT_OK) { | 2097 sync_api::BaseNode::INIT_OK) { |
| 2098 Cryptographer* cryptographer = trans.GetCryptographer(); | 2098 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2099 UpdateNigoriEncryptionState(cryptographer, &nigori_node); | 2099 UpdateNigoriEncryptionState(cryptographer, &nigori_node); |
| 2100 } | 2100 } |
| 2101 | 2101 |
| 2102 DVLOG(1) << "Sending OnSyncCycleCompleted"; | 2102 DVLOG(1) << "Sending OnSyncCycleCompleted"; |
| 2103 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2103 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 2104 OnSyncCycleCompleted(event.snapshot)); | 2104 OnSyncCycleCompleted(event.snapshot)); |
| 2105 } | 2105 } |
| 2106 | 2106 |
| 2107 // This is here for tests, which are still using p2p notifications. | 2107 // This is here for tests, which are still using p2p notifications. |
| 2108 // | 2108 // |
| 2109 // TODO(chron): Consider changing this back to track has_more_to_sync | 2109 // TODO(chron): Consider changing this back to track has_more_to_sync |
| 2110 // only notify peers if a successful commit has occurred. | 2110 // only notify peers if a successful commit has occurred. |
| 2111 bool is_notifiable_commit = | 2111 bool is_notifiable_commit = |
| 2112 (event.snapshot->syncer_status.num_successful_commits > 0); | 2112 (event.snapshot.syncer_status().num_successful_commits > 0); |
| 2113 if (is_notifiable_commit) { | 2113 if (is_notifiable_commit) { |
| 2114 if (sync_notifier_.get()) { | 2114 if (sync_notifier_.get()) { |
| 2115 const ModelTypeSet changed_types = | 2115 const ModelTypeSet changed_types = |
| 2116 syncable::ModelTypePayloadMapToEnumSet( | 2116 syncable::ModelTypePayloadMapToEnumSet( |
| 2117 event.snapshot->source.types); | 2117 event.snapshot.source().types); |
| 2118 sync_notifier_->SendNotification(changed_types); | 2118 sync_notifier_->SendNotification(changed_types); |
| 2119 } else { | 2119 } else { |
| 2120 DVLOG(1) << "Not sending notification: sync_notifier_ is NULL"; | 2120 DVLOG(1) << "Not sending notification: sync_notifier_ is NULL"; |
| 2121 } | 2121 } |
| 2122 } | 2122 } |
| 2123 } | 2123 } |
| 2124 | 2124 |
| 2125 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { | 2125 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { |
| 2126 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2126 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 2127 OnStopSyncingPermanently()); | 2127 OnStopSyncingPermanently()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2142 | 2142 |
| 2143 if (event.what_happened == SyncEngineEvent::UPDATED_TOKEN) { | 2143 if (event.what_happened == SyncEngineEvent::UPDATED_TOKEN) { |
| 2144 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2144 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 2145 OnUpdatedToken(event.updated_token)); | 2145 OnUpdatedToken(event.updated_token)); |
| 2146 return; | 2146 return; |
| 2147 } | 2147 } |
| 2148 | 2148 |
| 2149 if (event.what_happened == SyncEngineEvent::ACTIONABLE_ERROR) { | 2149 if (event.what_happened == SyncEngineEvent::ACTIONABLE_ERROR) { |
| 2150 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2150 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 2151 OnActionableError( | 2151 OnActionableError( |
| 2152 event.snapshot->errors.sync_protocol_error)); | 2152 event.snapshot.errors().sync_protocol_error)); |
| 2153 return; | 2153 return; |
| 2154 } | 2154 } |
| 2155 | 2155 |
| 2156 } | 2156 } |
| 2157 | 2157 |
| 2158 void SyncManager::SyncInternal::SetJsEventHandler( | 2158 void SyncManager::SyncInternal::SetJsEventHandler( |
| 2159 const WeakHandle<JsEventHandler>& event_handler) { | 2159 const WeakHandle<JsEventHandler>& event_handler) { |
| 2160 js_event_handler_ = event_handler; | 2160 js_event_handler_ = event_handler; |
| 2161 js_sync_manager_observer_.SetJsEventHandler(js_event_handler_); | 2161 js_sync_manager_observer_.SetJsEventHandler(js_event_handler_); |
| 2162 js_mutation_event_observer_.SetJsEventHandler(js_event_handler_); | 2162 js_mutation_event_observer_.SetJsEventHandler(js_event_handler_); |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2566 share->directory->GetDownloadProgress(i.Get(), &marker); | 2566 share->directory->GetDownloadProgress(i.Get(), &marker); |
| 2567 | 2567 |
| 2568 if (marker.token().empty()) | 2568 if (marker.token().empty()) |
| 2569 result.Put(i.Get()); | 2569 result.Put(i.Get()); |
| 2570 | 2570 |
| 2571 } | 2571 } |
| 2572 return result; | 2572 return result; |
| 2573 } | 2573 } |
| 2574 | 2574 |
| 2575 } // namespace sync_api | 2575 } // namespace sync_api |
| OLD | NEW |