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 <bitset> | 7 #include <bitset> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <list> | 9 #include <list> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/base64.h" | 13 #include "base/base64.h" |
14 #include "base/lock.h" | |
15 #include "base/logging.h" | 14 #include "base/logging.h" |
16 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
17 #include "base/scoped_ptr.h" | 16 #include "base/scoped_ptr.h" |
18 #include "base/sha1.h" | 17 #include "base/sha1.h" |
19 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "base/synchronization/lock.h" |
20 #include "base/task.h" | 20 #include "base/task.h" |
21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
22 #include "chrome/browser/browser_thread.h" | 22 #include "chrome/browser/browser_thread.h" |
23 #include "chrome/browser/sync/sync_constants.h" | 23 #include "chrome/browser/sync/sync_constants.h" |
24 #include "chrome/browser/sync/engine/all_status.h" | 24 #include "chrome/browser/sync/engine/all_status.h" |
25 #include "chrome/browser/sync/engine/change_reorder_buffer.h" | 25 #include "chrome/browser/sync/engine/change_reorder_buffer.h" |
26 #include "chrome/browser/sync/engine/model_safe_worker.h" | 26 #include "chrome/browser/sync/engine/model_safe_worker.h" |
27 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 27 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
28 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h" | 28 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h" |
29 #include "chrome/browser/sync/engine/syncer.h" | 29 #include "chrome/browser/sync/engine/syncer.h" |
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 // AllStatus::Status information. | 1072 // AllStatus::Status information. |
1073 Status ComputeAggregatedStatus(); | 1073 Status ComputeAggregatedStatus(); |
1074 Status::Summary ComputeAggregatedStatusSummary(); | 1074 Status::Summary ComputeAggregatedStatusSummary(); |
1075 | 1075 |
1076 // See SyncManager::Shutdown for information. | 1076 // See SyncManager::Shutdown for information. |
1077 void Shutdown(); | 1077 void Shutdown(); |
1078 | 1078 |
1079 // Whether we're initialized to the point of being able to accept changes | 1079 // Whether we're initialized to the point of being able to accept changes |
1080 // (and hence allow transaction creation). See initialized_ for details. | 1080 // (and hence allow transaction creation). See initialized_ for details. |
1081 bool initialized() const { | 1081 bool initialized() const { |
1082 AutoLock lock(initialized_mutex_); | 1082 base::AutoLock lock(initialized_mutex_); |
1083 return initialized_; | 1083 return initialized_; |
1084 } | 1084 } |
1085 | 1085 |
1086 void SetExtraChangeRecordData(int64 id, | 1086 void SetExtraChangeRecordData(int64 id, |
1087 syncable::ModelType type, | 1087 syncable::ModelType type, |
1088 ChangeReorderBuffer* buffer, | 1088 ChangeReorderBuffer* buffer, |
1089 Cryptographer* cryptographer, | 1089 Cryptographer* cryptographer, |
1090 const syncable::EntryKernel& original, | 1090 const syncable::EntryKernel& original, |
1091 bool existed_before, | 1091 bool existed_before, |
1092 bool exists_now); | 1092 bool exists_now); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1312 // True if the next SyncCycle should notify peers of an update. | 1312 // True if the next SyncCycle should notify peers of an update. |
1313 bool notification_pending_; | 1313 bool notification_pending_; |
1314 | 1314 |
1315 // Set to true once Init has been called, and we know of an authenticated | 1315 // Set to true once Init has been called, and we know of an authenticated |
1316 // valid) username either from a fresh authentication attempt (as in | 1316 // valid) username either from a fresh authentication attempt (as in |
1317 // first-use case) or from a previous attempt stored in our UserSettings | 1317 // first-use case) or from a previous attempt stored in our UserSettings |
1318 // (as in the steady-state), and the syncable::Directory has been opened, | 1318 // (as in the steady-state), and the syncable::Directory has been opened, |
1319 // meaning we are ready to accept changes. Protected by initialized_mutex_ | 1319 // meaning we are ready to accept changes. Protected by initialized_mutex_ |
1320 // as it can get read/set by both the SyncerThread and the AuthWatcherThread. | 1320 // as it can get read/set by both the SyncerThread and the AuthWatcherThread. |
1321 bool initialized_; | 1321 bool initialized_; |
1322 mutable Lock initialized_mutex_; | 1322 mutable base::Lock initialized_mutex_; |
1323 | 1323 |
1324 notifier::NotifierOptions notifier_options_; | 1324 notifier::NotifierOptions notifier_options_; |
1325 | 1325 |
1326 // True if the SyncManager should be running in test mode (no syncer thread | 1326 // True if the SyncManager should be running in test mode (no syncer thread |
1327 // actually communicating with the server). | 1327 // actually communicating with the server). |
1328 bool setup_for_test_mode_; | 1328 bool setup_for_test_mode_; |
1329 | 1329 |
1330 ScopedRunnableMethodFactory<SyncManager::SyncInternal> method_factory_; | 1330 ScopedRunnableMethodFactory<SyncManager::SyncInternal> method_factory_; |
1331 }; | 1331 }; |
1332 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; | 1332 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1533 // and a valid server connection is detected. | 1533 // and a valid server connection is detected. |
1534 } | 1534 } |
1535 | 1535 |
1536 void SyncManager::SyncInternal::MarkAndNotifyInitializationComplete() { | 1536 void SyncManager::SyncInternal::MarkAndNotifyInitializationComplete() { |
1537 // There is only one real time we need this mutex. If we get an auth | 1537 // There is only one real time we need this mutex. If we get an auth |
1538 // success, and before the initial sync ends we get an auth failure. In this | 1538 // success, and before the initial sync ends we get an auth failure. In this |
1539 // case we'll be listening to both the AuthWatcher and Syncer, and it's a race | 1539 // case we'll be listening to both the AuthWatcher and Syncer, and it's a race |
1540 // between their respective threads to call MarkAndNotify. We need to make | 1540 // between their respective threads to call MarkAndNotify. We need to make |
1541 // sure the observer is notified once and only once. | 1541 // sure the observer is notified once and only once. |
1542 { | 1542 { |
1543 AutoLock lock(initialized_mutex_); | 1543 base::AutoLock lock(initialized_mutex_); |
1544 if (initialized_) | 1544 if (initialized_) |
1545 return; | 1545 return; |
1546 initialized_ = true; | 1546 initialized_ = true; |
1547 } | 1547 } |
1548 | 1548 |
1549 // Notify that initialization is complete. | 1549 // Notify that initialization is complete. |
1550 if (observer_) | 1550 if (observer_) |
1551 observer_->OnInitializationComplete(); | 1551 observer_->OnInitializationComplete(); |
1552 } | 1552 } |
1553 | 1553 |
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2350 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; | 2350 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; |
2351 return data_->GetUserShare(); | 2351 return data_->GetUserShare(); |
2352 } | 2352 } |
2353 | 2353 |
2354 bool SyncManager::HasUnsyncedItems() const { | 2354 bool SyncManager::HasUnsyncedItems() const { |
2355 sync_api::ReadTransaction trans(GetUserShare()); | 2355 sync_api::ReadTransaction trans(GetUserShare()); |
2356 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); | 2356 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); |
2357 } | 2357 } |
2358 | 2358 |
2359 } // namespace sync_api | 2359 } // namespace sync_api |
OLD | NEW |