| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/engine/syncapi.h" | 5 #include "chrome/browser/sync/engine/syncapi.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include <iomanip> | 9 #include <iomanip> |
| 10 #include <list> | 10 #include <list> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "chrome/browser/sync/engine/syncer.h" | 33 #include "chrome/browser/sync/engine/syncer.h" |
| 34 #include "chrome/browser/sync/engine/syncer_thread.h" | 34 #include "chrome/browser/sync/engine/syncer_thread.h" |
| 35 #include "chrome/browser/sync/notifier/server_notifier_thread.h" | 35 #include "chrome/browser/sync/notifier/server_notifier_thread.h" |
| 36 #include "chrome/browser/sync/protocol/app_specifics.pb.h" | 36 #include "chrome/browser/sync/protocol/app_specifics.pb.h" |
| 37 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 37 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
| 38 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 38 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
| 39 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 39 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
| 40 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" | 40 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" |
| 41 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 41 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
| 42 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" | 42 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" |
| 43 #include "chrome/browser/sync/protocol/session_specifics.pb.h" |
| 43 #include "chrome/browser/sync/protocol/service_constants.h" | 44 #include "chrome/browser/sync/protocol/service_constants.h" |
| 44 #include "chrome/browser/sync/protocol/sync.pb.h" | 45 #include "chrome/browser/sync/protocol/sync.pb.h" |
| 45 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" | 46 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" |
| 46 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" | 47 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" |
| 47 #include "chrome/browser/sync/sessions/sync_session_context.h" | 48 #include "chrome/browser/sync/sessions/sync_session_context.h" |
| 48 #include "chrome/browser/sync/syncable/directory_manager.h" | 49 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 49 #include "chrome/browser/sync/syncable/syncable.h" | 50 #include "chrome/browser/sync/syncable/syncable.h" |
| 50 #include "chrome/browser/sync/util/crypto_helpers.h" | 51 #include "chrome/browser/sync/util/crypto_helpers.h" |
| 51 #include "chrome/browser/sync/util/user_settings.h" | 52 #include "chrome/browser/sync/util/user_settings.h" |
| 52 #include "chrome/common/chrome_switches.h" | 53 #include "chrome/common/chrome_switches.h" |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 const sync_pb::TypedUrlSpecifics& BaseNode::GetTypedUrlSpecifics() const { | 293 const sync_pb::TypedUrlSpecifics& BaseNode::GetTypedUrlSpecifics() const { |
| 293 DCHECK(GetModelType() == syncable::TYPED_URLS); | 294 DCHECK(GetModelType() == syncable::TYPED_URLS); |
| 294 return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::typed_url); | 295 return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::typed_url); |
| 295 } | 296 } |
| 296 | 297 |
| 297 const sync_pb::ExtensionSpecifics& BaseNode::GetExtensionSpecifics() const { | 298 const sync_pb::ExtensionSpecifics& BaseNode::GetExtensionSpecifics() const { |
| 298 DCHECK(GetModelType() == syncable::EXTENSIONS); | 299 DCHECK(GetModelType() == syncable::EXTENSIONS); |
| 299 return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::extension); | 300 return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::extension); |
| 300 } | 301 } |
| 301 | 302 |
| 303 const sync_pb::SessionSpecifics& BaseNode::GetSessionSpecifics() const { |
| 304 DCHECK(GetModelType() == syncable::SESSIONS); |
| 305 return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::session); |
| 306 } |
| 307 |
| 302 syncable::ModelType BaseNode::GetModelType() const { | 308 syncable::ModelType BaseNode::GetModelType() const { |
| 303 return GetEntry()->GetModelType(); | 309 return GetEntry()->GetModelType(); |
| 304 } | 310 } |
| 305 | 311 |
| 306 //////////////////////////////////// | 312 //////////////////////////////////// |
| 307 // WriteNode member definitions | 313 // WriteNode member definitions |
| 308 void WriteNode::SetIsFolder(bool folder) { | 314 void WriteNode::SetIsFolder(bool folder) { |
| 309 if (entry_->Get(syncable::IS_DIR) == folder) | 315 if (entry_->Get(syncable::IS_DIR) == folder) |
| 310 return; // Skip redundant changes. | 316 return; // Skip redundant changes. |
| 311 | 317 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 DCHECK(GetModelType() == syncable::PREFERENCES); | 402 DCHECK(GetModelType() == syncable::PREFERENCES); |
| 397 PutPreferenceSpecificsAndMarkForSyncing(new_value); | 403 PutPreferenceSpecificsAndMarkForSyncing(new_value); |
| 398 } | 404 } |
| 399 | 405 |
| 400 void WriteNode::SetThemeSpecifics( | 406 void WriteNode::SetThemeSpecifics( |
| 401 const sync_pb::ThemeSpecifics& new_value) { | 407 const sync_pb::ThemeSpecifics& new_value) { |
| 402 DCHECK(GetModelType() == syncable::THEMES); | 408 DCHECK(GetModelType() == syncable::THEMES); |
| 403 PutThemeSpecificsAndMarkForSyncing(new_value); | 409 PutThemeSpecificsAndMarkForSyncing(new_value); |
| 404 } | 410 } |
| 405 | 411 |
| 412 |
| 413 void WriteNode::SetSessionSpecifics( |
| 414 const sync_pb::SessionSpecifics& new_value) { |
| 415 DCHECK(GetModelType() == syncable::SESSIONS); |
| 416 PutSessionSpecificsAndMarkForSyncing(new_value); |
| 417 } |
| 418 |
| 419 |
| 406 void WriteNode::PutPasswordSpecificsAndMarkForSyncing( | 420 void WriteNode::PutPasswordSpecificsAndMarkForSyncing( |
| 407 const sync_pb::PasswordSpecifics& new_value) { | 421 const sync_pb::PasswordSpecifics& new_value) { |
| 408 sync_pb::EntitySpecifics entity_specifics; | 422 sync_pb::EntitySpecifics entity_specifics; |
| 409 entity_specifics.MutableExtension(sync_pb::password)->CopyFrom(new_value); | 423 entity_specifics.MutableExtension(sync_pb::password)->CopyFrom(new_value); |
| 410 PutSpecificsAndMarkForSyncing(entity_specifics); | 424 PutSpecificsAndMarkForSyncing(entity_specifics); |
| 411 } | 425 } |
| 412 | 426 |
| 413 void WriteNode::PutPreferenceSpecificsAndMarkForSyncing( | 427 void WriteNode::PutPreferenceSpecificsAndMarkForSyncing( |
| 414 const sync_pb::PreferenceSpecifics& new_value) { | 428 const sync_pb::PreferenceSpecifics& new_value) { |
| 415 sync_pb::EntitySpecifics entity_specifics; | 429 sync_pb::EntitySpecifics entity_specifics; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 PutSpecificsAndMarkForSyncing(entity_specifics); | 464 PutSpecificsAndMarkForSyncing(entity_specifics); |
| 451 } | 465 } |
| 452 | 466 |
| 453 void WriteNode::PutExtensionSpecificsAndMarkForSyncing( | 467 void WriteNode::PutExtensionSpecificsAndMarkForSyncing( |
| 454 const sync_pb::ExtensionSpecifics& new_value) { | 468 const sync_pb::ExtensionSpecifics& new_value) { |
| 455 sync_pb::EntitySpecifics entity_specifics; | 469 sync_pb::EntitySpecifics entity_specifics; |
| 456 entity_specifics.MutableExtension(sync_pb::extension)->CopyFrom(new_value); | 470 entity_specifics.MutableExtension(sync_pb::extension)->CopyFrom(new_value); |
| 457 PutSpecificsAndMarkForSyncing(entity_specifics); | 471 PutSpecificsAndMarkForSyncing(entity_specifics); |
| 458 } | 472 } |
| 459 | 473 |
| 474 |
| 475 void WriteNode::PutSessionSpecificsAndMarkForSyncing( |
| 476 const sync_pb::SessionSpecifics& new_value) { |
| 477 sync_pb::EntitySpecifics entity_specifics; |
| 478 entity_specifics.MutableExtension(sync_pb::session)->CopyFrom(new_value); |
| 479 PutSpecificsAndMarkForSyncing(entity_specifics); |
| 480 } |
| 481 |
| 482 |
| 460 void WriteNode::PutSpecificsAndMarkForSyncing( | 483 void WriteNode::PutSpecificsAndMarkForSyncing( |
| 461 const sync_pb::EntitySpecifics& specifics) { | 484 const sync_pb::EntitySpecifics& specifics) { |
| 462 // Skip redundant changes. | 485 // Skip redundant changes. |
| 463 if (specifics.SerializeAsString() == | 486 if (specifics.SerializeAsString() == |
| 464 entry_->Get(SPECIFICS).SerializeAsString()) { | 487 entry_->Get(SPECIFICS).SerializeAsString()) { |
| 465 return; | 488 return; |
| 466 } | 489 } |
| 467 entry_->Put(SPECIFICS, specifics); | 490 entry_->Put(SPECIFICS, specifics); |
| 468 MarkForSyncing(); | 491 MarkForSyncing(); |
| 469 } | 492 } |
| (...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1874 return; | 1897 return; |
| 1875 | 1898 |
| 1876 // Only send an event if this is due to a cycle ending and this cycle | 1899 // Only send an event if this is due to a cycle ending and this cycle |
| 1877 // concludes a canonical "sync" process; that is, based on what is known | 1900 // concludes a canonical "sync" process; that is, based on what is known |
| 1878 // locally we are "all happy" and up-to-date. There may be new changes on | 1901 // locally we are "all happy" and up-to-date. There may be new changes on |
| 1879 // the server, but we'll get them on a subsequent sync. | 1902 // the server, but we'll get them on a subsequent sync. |
| 1880 // | 1903 // |
| 1881 // Notifications are sent at the end of every sync cycle, regardless of | 1904 // Notifications are sent at the end of every sync cycle, regardless of |
| 1882 // whether we should sync again. | 1905 // whether we should sync again. |
| 1883 if (event.what_happened == SyncerEvent::SYNC_CYCLE_ENDED) { | 1906 if (event.what_happened == SyncerEvent::SYNC_CYCLE_ENDED) { |
| 1884 | |
| 1885 ModelSafeRoutingInfo enabled_types; | 1907 ModelSafeRoutingInfo enabled_types; |
| 1886 registrar_->GetModelSafeRoutingInfo(&enabled_types); | 1908 registrar_->GetModelSafeRoutingInfo(&enabled_types); |
| 1887 if (enabled_types.count(syncable::PASSWORDS) > 0) { | 1909 if (enabled_types.count(syncable::PASSWORDS) > 0) { |
| 1888 Cryptographer* cryptographer = | 1910 Cryptographer* cryptographer = |
| 1889 GetUserShare()->dir_manager->cryptographer(); | 1911 GetUserShare()->dir_manager->cryptographer(); |
| 1890 if (!cryptographer->is_ready() && !cryptographer->has_pending_keys()) { | 1912 if (!cryptographer->is_ready() && !cryptographer->has_pending_keys()) { |
| 1891 sync_api::ReadTransaction trans(GetUserShare()); | 1913 sync_api::ReadTransaction trans(GetUserShare()); |
| 1892 sync_api::ReadNode node(&trans); | 1914 sync_api::ReadNode node(&trans); |
| 1893 if (!node.InitByTagLookup(kNigoriTag)) { | 1915 if (!node.InitByTagLookup(kNigoriTag)) { |
| 1894 NOTREACHED(); | 1916 NOTREACHED(); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2190 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; | 2212 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; |
| 2191 return data_->GetUserShare(); | 2213 return data_->GetUserShare(); |
| 2192 } | 2214 } |
| 2193 | 2215 |
| 2194 bool SyncManager::HasUnsyncedItems() const { | 2216 bool SyncManager::HasUnsyncedItems() const { |
| 2195 sync_api::ReadTransaction trans(GetUserShare()); | 2217 sync_api::ReadTransaction trans(GetUserShare()); |
| 2196 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); | 2218 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); |
| 2197 } | 2219 } |
| 2198 | 2220 |
| 2199 } // namespace sync_api | 2221 } // namespace sync_api |
| OLD | NEW |