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 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1881 return; | 1904 return; |
1882 | 1905 |
1883 // Only send an event if this is due to a cycle ending and this cycle | 1906 // Only send an event if this is due to a cycle ending and this cycle |
1884 // concludes a canonical "sync" process; that is, based on what is known | 1907 // concludes a canonical "sync" process; that is, based on what is known |
1885 // locally we are "all happy" and up-to-date. There may be new changes on | 1908 // locally we are "all happy" and up-to-date. There may be new changes on |
1886 // the server, but we'll get them on a subsequent sync. | 1909 // the server, but we'll get them on a subsequent sync. |
1887 // | 1910 // |
1888 // Notifications are sent at the end of every sync cycle, regardless of | 1911 // Notifications are sent at the end of every sync cycle, regardless of |
1889 // whether we should sync again. | 1912 // whether we should sync again. |
1890 if (event.what_happened == SyncerEvent::SYNC_CYCLE_ENDED) { | 1913 if (event.what_happened == SyncerEvent::SYNC_CYCLE_ENDED) { |
1891 | |
1892 ModelSafeRoutingInfo enabled_types; | 1914 ModelSafeRoutingInfo enabled_types; |
1893 registrar_->GetModelSafeRoutingInfo(&enabled_types); | 1915 registrar_->GetModelSafeRoutingInfo(&enabled_types); |
1894 if (enabled_types.count(syncable::PASSWORDS) > 0) { | 1916 if (enabled_types.count(syncable::PASSWORDS) > 0) { |
1895 Cryptographer* cryptographer = | 1917 Cryptographer* cryptographer = |
1896 GetUserShare()->dir_manager->cryptographer(); | 1918 GetUserShare()->dir_manager->cryptographer(); |
1897 if (!cryptographer->is_ready() && !cryptographer->has_pending_keys()) { | 1919 if (!cryptographer->is_ready() && !cryptographer->has_pending_keys()) { |
1898 sync_api::ReadTransaction trans(GetUserShare()); | 1920 sync_api::ReadTransaction trans(GetUserShare()); |
1899 sync_api::ReadNode node(&trans); | 1921 sync_api::ReadNode node(&trans); |
1900 if (!node.InitByTagLookup(kNigoriTag)) { | 1922 if (!node.InitByTagLookup(kNigoriTag)) { |
1901 NOTREACHED(); | 1923 NOTREACHED(); |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2197 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; | 2219 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; |
2198 return data_->GetUserShare(); | 2220 return data_->GetUserShare(); |
2199 } | 2221 } |
2200 | 2222 |
2201 bool SyncManager::HasUnsyncedItems() const { | 2223 bool SyncManager::HasUnsyncedItems() const { |
2202 sync_api::ReadTransaction trans(GetUserShare()); | 2224 sync_api::ReadTransaction trans(GetUserShare()); |
2203 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); | 2225 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); |
2204 } | 2226 } |
2205 | 2227 |
2206 } // namespace sync_api | 2228 } // namespace sync_api |
OLD | NEW |