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" | |
44 #include "chrome/browser/sync/protocol/service_constants.h" | 43 #include "chrome/browser/sync/protocol/service_constants.h" |
45 #include "chrome/browser/sync/protocol/sync.pb.h" | 44 #include "chrome/browser/sync/protocol/sync.pb.h" |
46 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" | 45 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" |
47 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" | 46 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" |
48 #include "chrome/browser/sync/sessions/sync_session_context.h" | 47 #include "chrome/browser/sync/sessions/sync_session_context.h" |
49 #include "chrome/browser/sync/syncable/directory_manager.h" | 48 #include "chrome/browser/sync/syncable/directory_manager.h" |
50 #include "chrome/browser/sync/syncable/syncable.h" | 49 #include "chrome/browser/sync/syncable/syncable.h" |
51 #include "chrome/browser/sync/util/crypto_helpers.h" | 50 #include "chrome/browser/sync/util/crypto_helpers.h" |
52 #include "chrome/browser/sync/util/user_settings.h" | 51 #include "chrome/browser/sync/util/user_settings.h" |
53 #include "chrome/common/chrome_switches.h" | 52 #include "chrome/common/chrome_switches.h" |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 const sync_pb::TypedUrlSpecifics& BaseNode::GetTypedUrlSpecifics() const { | 292 const sync_pb::TypedUrlSpecifics& BaseNode::GetTypedUrlSpecifics() const { |
294 DCHECK(GetModelType() == syncable::TYPED_URLS); | 293 DCHECK(GetModelType() == syncable::TYPED_URLS); |
295 return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::typed_url); | 294 return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::typed_url); |
296 } | 295 } |
297 | 296 |
298 const sync_pb::ExtensionSpecifics& BaseNode::GetExtensionSpecifics() const { | 297 const sync_pb::ExtensionSpecifics& BaseNode::GetExtensionSpecifics() const { |
299 DCHECK(GetModelType() == syncable::EXTENSIONS); | 298 DCHECK(GetModelType() == syncable::EXTENSIONS); |
300 return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::extension); | 299 return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::extension); |
301 } | 300 } |
302 | 301 |
303 const sync_pb::SessionSpecifics& BaseNode::GetSessionSpecifics() const { | |
304 DCHECK(GetModelType() == syncable::SESSIONS); | |
305 return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::session); | |
306 } | |
307 | |
308 syncable::ModelType BaseNode::GetModelType() const { | 302 syncable::ModelType BaseNode::GetModelType() const { |
309 return GetEntry()->GetModelType(); | 303 return GetEntry()->GetModelType(); |
310 } | 304 } |
311 | 305 |
312 //////////////////////////////////// | 306 //////////////////////////////////// |
313 // WriteNode member definitions | 307 // WriteNode member definitions |
314 void WriteNode::SetIsFolder(bool folder) { | 308 void WriteNode::SetIsFolder(bool folder) { |
315 if (entry_->Get(syncable::IS_DIR) == folder) | 309 if (entry_->Get(syncable::IS_DIR) == folder) |
316 return; // Skip redundant changes. | 310 return; // Skip redundant changes. |
317 | 311 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 DCHECK(GetModelType() == syncable::PREFERENCES); | 396 DCHECK(GetModelType() == syncable::PREFERENCES); |
403 PutPreferenceSpecificsAndMarkForSyncing(new_value); | 397 PutPreferenceSpecificsAndMarkForSyncing(new_value); |
404 } | 398 } |
405 | 399 |
406 void WriteNode::SetThemeSpecifics( | 400 void WriteNode::SetThemeSpecifics( |
407 const sync_pb::ThemeSpecifics& new_value) { | 401 const sync_pb::ThemeSpecifics& new_value) { |
408 DCHECK(GetModelType() == syncable::THEMES); | 402 DCHECK(GetModelType() == syncable::THEMES); |
409 PutThemeSpecificsAndMarkForSyncing(new_value); | 403 PutThemeSpecificsAndMarkForSyncing(new_value); |
410 } | 404 } |
411 | 405 |
412 | |
413 void WriteNode::SetSessionSpecifics( | |
414 const sync_pb::SessionSpecifics& new_value) { | |
415 DCHECK(GetModelType() == syncable::SESSIONS); | |
416 PutSessionSpecificsAndMarkForSyncing(new_value); | |
417 } | |
418 | |
419 | |
420 void WriteNode::PutPasswordSpecificsAndMarkForSyncing( | 406 void WriteNode::PutPasswordSpecificsAndMarkForSyncing( |
421 const sync_pb::PasswordSpecifics& new_value) { | 407 const sync_pb::PasswordSpecifics& new_value) { |
422 sync_pb::EntitySpecifics entity_specifics; | 408 sync_pb::EntitySpecifics entity_specifics; |
423 entity_specifics.MutableExtension(sync_pb::password)->CopyFrom(new_value); | 409 entity_specifics.MutableExtension(sync_pb::password)->CopyFrom(new_value); |
424 PutSpecificsAndMarkForSyncing(entity_specifics); | 410 PutSpecificsAndMarkForSyncing(entity_specifics); |
425 } | 411 } |
426 | 412 |
427 void WriteNode::PutPreferenceSpecificsAndMarkForSyncing( | 413 void WriteNode::PutPreferenceSpecificsAndMarkForSyncing( |
428 const sync_pb::PreferenceSpecifics& new_value) { | 414 const sync_pb::PreferenceSpecifics& new_value) { |
429 sync_pb::EntitySpecifics entity_specifics; | 415 sync_pb::EntitySpecifics entity_specifics; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 PutSpecificsAndMarkForSyncing(entity_specifics); | 450 PutSpecificsAndMarkForSyncing(entity_specifics); |
465 } | 451 } |
466 | 452 |
467 void WriteNode::PutExtensionSpecificsAndMarkForSyncing( | 453 void WriteNode::PutExtensionSpecificsAndMarkForSyncing( |
468 const sync_pb::ExtensionSpecifics& new_value) { | 454 const sync_pb::ExtensionSpecifics& new_value) { |
469 sync_pb::EntitySpecifics entity_specifics; | 455 sync_pb::EntitySpecifics entity_specifics; |
470 entity_specifics.MutableExtension(sync_pb::extension)->CopyFrom(new_value); | 456 entity_specifics.MutableExtension(sync_pb::extension)->CopyFrom(new_value); |
471 PutSpecificsAndMarkForSyncing(entity_specifics); | 457 PutSpecificsAndMarkForSyncing(entity_specifics); |
472 } | 458 } |
473 | 459 |
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 | |
483 void WriteNode::PutSpecificsAndMarkForSyncing( | 460 void WriteNode::PutSpecificsAndMarkForSyncing( |
484 const sync_pb::EntitySpecifics& specifics) { | 461 const sync_pb::EntitySpecifics& specifics) { |
485 // Skip redundant changes. | 462 // Skip redundant changes. |
486 if (specifics.SerializeAsString() == | 463 if (specifics.SerializeAsString() == |
487 entry_->Get(SPECIFICS).SerializeAsString()) { | 464 entry_->Get(SPECIFICS).SerializeAsString()) { |
488 return; | 465 return; |
489 } | 466 } |
490 entry_->Put(SPECIFICS, specifics); | 467 entry_->Put(SPECIFICS, specifics); |
491 MarkForSyncing(); | 468 MarkForSyncing(); |
492 } | 469 } |
(...skipping 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1904 return; | 1881 return; |
1905 | 1882 |
1906 // Only send an event if this is due to a cycle ending and this cycle | 1883 // Only send an event if this is due to a cycle ending and this cycle |
1907 // concludes a canonical "sync" process; that is, based on what is known | 1884 // concludes a canonical "sync" process; that is, based on what is known |
1908 // locally we are "all happy" and up-to-date. There may be new changes on | 1885 // locally we are "all happy" and up-to-date. There may be new changes on |
1909 // the server, but we'll get them on a subsequent sync. | 1886 // the server, but we'll get them on a subsequent sync. |
1910 // | 1887 // |
1911 // Notifications are sent at the end of every sync cycle, regardless of | 1888 // Notifications are sent at the end of every sync cycle, regardless of |
1912 // whether we should sync again. | 1889 // whether we should sync again. |
1913 if (event.what_happened == SyncerEvent::SYNC_CYCLE_ENDED) { | 1890 if (event.what_happened == SyncerEvent::SYNC_CYCLE_ENDED) { |
| 1891 |
1914 ModelSafeRoutingInfo enabled_types; | 1892 ModelSafeRoutingInfo enabled_types; |
1915 registrar_->GetModelSafeRoutingInfo(&enabled_types); | 1893 registrar_->GetModelSafeRoutingInfo(&enabled_types); |
1916 if (enabled_types.count(syncable::PASSWORDS) > 0) { | 1894 if (enabled_types.count(syncable::PASSWORDS) > 0) { |
1917 Cryptographer* cryptographer = | 1895 Cryptographer* cryptographer = |
1918 GetUserShare()->dir_manager->cryptographer(); | 1896 GetUserShare()->dir_manager->cryptographer(); |
1919 if (!cryptographer->is_ready() && !cryptographer->has_pending_keys()) { | 1897 if (!cryptographer->is_ready() && !cryptographer->has_pending_keys()) { |
1920 sync_api::ReadTransaction trans(GetUserShare()); | 1898 sync_api::ReadTransaction trans(GetUserShare()); |
1921 sync_api::ReadNode node(&trans); | 1899 sync_api::ReadNode node(&trans); |
1922 if (!node.InitByTagLookup(kNigoriTag)) { | 1900 if (!node.InitByTagLookup(kNigoriTag)) { |
1923 NOTREACHED(); | 1901 NOTREACHED(); |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2219 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; | 2197 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; |
2220 return data_->GetUserShare(); | 2198 return data_->GetUserShare(); |
2221 } | 2199 } |
2222 | 2200 |
2223 bool SyncManager::HasUnsyncedItems() const { | 2201 bool SyncManager::HasUnsyncedItems() const { |
2224 sync_api::ReadTransaction trans(GetUserShare()); | 2202 sync_api::ReadTransaction trans(GetUserShare()); |
2225 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); | 2203 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); |
2226 } | 2204 } |
2227 | 2205 |
2228 } // namespace sync_api | 2206 } // namespace sync_api |
OLD | NEW |