Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: sync/internal_api/sync_manager_impl.cc

Issue 10837214: Refactor ModelTypePayloadMap and ObjectIdPayloadMap to StateMaps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_impl.h" 5 #include "sync/internal_api/sync_manager_impl.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"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/json/json_writer.h" 14 #include "base/json/json_writer.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/observer_list.h" 17 #include "base/observer_list.h"
18 #include "base/string_number_conversions.h" 18 #include "base/string_number_conversions.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "sync/engine/sync_scheduler.h" 20 #include "sync/engine/sync_scheduler.h"
21 #include "sync/engine/syncer_types.h" 21 #include "sync/engine/syncer_types.h"
22 #include "sync/internal_api/change_reorder_buffer.h" 22 #include "sync/internal_api/change_reorder_buffer.h"
23 #include "sync/internal_api/public/base/model_type.h" 23 #include "sync/internal_api/public/base/model_type.h"
24 #include "sync/internal_api/public/base/model_type_payload_map.h" 24 #include "sync/internal_api/public/base/model_type_state_map.h"
25 #include "sync/internal_api/public/base_node.h" 25 #include "sync/internal_api/public/base_node.h"
26 #include "sync/internal_api/public/configure_reason.h" 26 #include "sync/internal_api/public/configure_reason.h"
27 #include "sync/internal_api/public/engine/polling_constants.h" 27 #include "sync/internal_api/public/engine/polling_constants.h"
28 #include "sync/internal_api/public/http_post_provider_factory.h" 28 #include "sync/internal_api/public/http_post_provider_factory.h"
29 #include "sync/internal_api/public/internal_components_factory.h" 29 #include "sync/internal_api/public/internal_components_factory.h"
30 #include "sync/internal_api/public/read_node.h" 30 #include "sync/internal_api/public/read_node.h"
31 #include "sync/internal_api/public/read_transaction.h" 31 #include "sync/internal_api/public/read_transaction.h"
32 #include "sync/internal_api/public/user_share.h" 32 #include "sync/internal_api/public/user_share.h"
33 #include "sync/internal_api/public/util/experiments.h" 33 #include "sync/internal_api/public/util/experiments.h"
34 #include "sync/internal_api/public/write_node.h" 34 #include "sync/internal_api/public/write_node.h"
(...skipping 1524 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 1559
1560 // This is here for tests, which are still using p2p notifications. 1560 // This is here for tests, which are still using p2p notifications.
1561 // 1561 //
1562 // TODO(chron): Consider changing this back to track has_more_to_sync 1562 // TODO(chron): Consider changing this back to track has_more_to_sync
1563 // only notify peers if a successful commit has occurred. 1563 // only notify peers if a successful commit has occurred.
1564 bool is_notifiable_commit = 1564 bool is_notifiable_commit =
1565 (event.snapshot.model_neutral_state().num_successful_commits > 0); 1565 (event.snapshot.model_neutral_state().num_successful_commits > 0);
1566 if (is_notifiable_commit) { 1566 if (is_notifiable_commit) {
1567 if (sync_notifier_.get()) { 1567 if (sync_notifier_.get()) {
1568 const ModelTypeSet changed_types = 1568 const ModelTypeSet changed_types =
1569 ModelTypePayloadMapToEnumSet(event.snapshot.source().types); 1569 ModelTypeStateMapToEnumSet(event.snapshot.source().types);
1570 sync_notifier_->SendNotification(changed_types); 1570 sync_notifier_->SendNotification(changed_types);
1571 } else { 1571 } else {
1572 DVLOG(1) << "Not sending notification: sync_notifier_ is NULL"; 1572 DVLOG(1) << "Not sending notification: sync_notifier_ is NULL";
1573 } 1573 }
1574 } 1574 }
1575 } 1575 }
1576 1576
1577 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { 1577 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) {
1578 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, 1578 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
1579 OnStopSyncingPermanently()); 1579 OnStopSyncingPermanently());
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1809 void SyncManagerImpl::OnEncryptedTypesChanged( 1809 void SyncManagerImpl::OnEncryptedTypesChanged(
1810 ModelTypeSet encrypted_types, 1810 ModelTypeSet encrypted_types,
1811 bool encrypt_everything) { 1811 bool encrypt_everything) {
1812 // NOTE: We're in a transaction. 1812 // NOTE: We're in a transaction.
1813 FOR_EACH_OBSERVER( 1813 FOR_EACH_OBSERVER(
1814 SyncManager::Observer, observers_, 1814 SyncManager::Observer, observers_,
1815 OnEncryptedTypesChanged(encrypted_types, encrypt_everything)); 1815 OnEncryptedTypesChanged(encrypted_types, encrypt_everything));
1816 } 1816 }
1817 1817
1818 void SyncManagerImpl::UpdateNotificationInfo( 1818 void SyncManagerImpl::UpdateNotificationInfo(
1819 const ModelTypePayloadMap& type_payloads) { 1819 const ModelTypeStateMap& type_state_map) {
1820 for (ModelTypePayloadMap::const_iterator it = type_payloads.begin(); 1820 for (ModelTypeStateMap::const_iterator it = type_state_map.begin();
1821 it != type_payloads.end(); ++it) { 1821 it != type_state_map.end(); ++it) {
1822 NotificationInfo* info = &notification_info_map_[it->first]; 1822 NotificationInfo* info = &notification_info_map_[it->first];
1823 info->total_count++; 1823 info->total_count++;
1824 info->payload = it->second; 1824 info->payload = it->second.payload;
1825 } 1825 }
1826 } 1826 }
1827 1827
1828 void SyncManagerImpl::OnNotificationsEnabled() { 1828 void SyncManagerImpl::OnNotificationsEnabled() {
1829 OnNotificationStateChange(NO_NOTIFICATION_ERROR); 1829 OnNotificationStateChange(NO_NOTIFICATION_ERROR);
1830 } 1830 }
1831 1831
1832 void SyncManagerImpl::OnNotificationsDisabled( 1832 void SyncManagerImpl::OnNotificationsDisabled(
1833 NotificationsDisabledReason reason) { 1833 NotificationsDisabledReason reason) {
1834 OnNotificationStateChange(reason); 1834 OnNotificationStateChange(reason);
1835 } 1835 }
1836 1836
1837 void SyncManagerImpl::OnIncomingNotification( 1837 void SyncManagerImpl::OnIncomingNotification(
1838 const ObjectIdPayloadMap& id_payloads, 1838 const ObjectIdStateMap& id_state_map,
1839 IncomingNotificationSource source) { 1839 IncomingNotificationSource source) {
1840 DCHECK(thread_checker_.CalledOnValidThread()); 1840 DCHECK(thread_checker_.CalledOnValidThread());
1841 const ModelTypePayloadMap& type_payloads = 1841 const ModelTypeStateMap& type_state_map =
1842 ObjectIdPayloadMapToModelTypePayloadMap(id_payloads); 1842 ObjectIdStateMapToModelTypeStateMap(id_state_map);
1843 if (source == LOCAL_NOTIFICATION) { 1843 if (source == LOCAL_NOTIFICATION) {
1844 scheduler_->ScheduleNudgeWithPayloadsAsync( 1844 scheduler_->ScheduleNudgeWithStatesAsync(
1845 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), 1845 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec),
1846 NUDGE_SOURCE_LOCAL_REFRESH, 1846 NUDGE_SOURCE_LOCAL_REFRESH,
1847 type_payloads, FROM_HERE); 1847 type_state_map, FROM_HERE);
1848 } else if (!type_payloads.empty()) { 1848 } else if (!type_state_map.empty()) {
1849 scheduler_->ScheduleNudgeWithPayloadsAsync( 1849 scheduler_->ScheduleNudgeWithStatesAsync(
1850 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), 1850 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec),
1851 NUDGE_SOURCE_NOTIFICATION, 1851 NUDGE_SOURCE_NOTIFICATION,
1852 type_payloads, FROM_HERE); 1852 type_state_map, FROM_HERE);
1853 allstatus_.IncrementNotificationsReceived(); 1853 allstatus_.IncrementNotificationsReceived();
1854 UpdateNotificationInfo(type_payloads); 1854 UpdateNotificationInfo(type_state_map);
1855 debug_info_event_listener_.OnIncomingNotification(type_payloads); 1855 debug_info_event_listener_.OnIncomingNotification(type_state_map);
1856 } else { 1856 } else {
1857 LOG(WARNING) << "Sync received notification without any type information."; 1857 LOG(WARNING) << "Sync received notification without any type information.";
1858 } 1858 }
1859 1859
1860 if (js_event_handler_.IsInitialized()) { 1860 if (js_event_handler_.IsInitialized()) {
1861 DictionaryValue details; 1861 DictionaryValue details;
1862 ListValue* changed_types = new ListValue(); 1862 ListValue* changed_types = new ListValue();
1863 details.Set("changedTypes", changed_types); 1863 details.Set("changedTypes", changed_types);
1864 for (ModelTypePayloadMap::const_iterator it = type_payloads.begin(); 1864 for (ModelTypeStateMap::const_iterator it = type_state_map.begin();
1865 it != type_payloads.end(); ++it) { 1865 it != type_state_map.end(); ++it) {
1866 const std::string& model_type_str = 1866 const std::string& model_type_str =
1867 ModelTypeToString(it->first); 1867 ModelTypeToString(it->first);
1868 changed_types->Append(Value::CreateStringValue(model_type_str)); 1868 changed_types->Append(Value::CreateStringValue(model_type_str));
1869 } 1869 }
1870 details.SetString("source", (source == LOCAL_NOTIFICATION) ? 1870 details.SetString("source", (source == LOCAL_NOTIFICATION) ?
1871 "LOCAL_NOTIFICATION" : "REMOTE_NOTIFICATION"); 1871 "LOCAL_NOTIFICATION" : "REMOTE_NOTIFICATION");
1872 js_event_handler_.Call(FROM_HERE, 1872 js_event_handler_.Call(FROM_HERE,
1873 &JsEventHandler::HandleJsEvent, 1873 &JsEventHandler::HandleJsEvent,
1874 "onIncomingNotification", 1874 "onIncomingNotification",
1875 JsEventDetails(&details)); 1875 JsEventDetails(&details));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1917 int SyncManagerImpl::GetDefaultNudgeDelay() { 1917 int SyncManagerImpl::GetDefaultNudgeDelay() {
1918 return kDefaultNudgeDelayMilliseconds; 1918 return kDefaultNudgeDelayMilliseconds;
1919 } 1919 }
1920 1920
1921 // static. 1921 // static.
1922 int SyncManagerImpl::GetPreferencesNudgeDelay() { 1922 int SyncManagerImpl::GetPreferencesNudgeDelay() {
1923 return kPreferencesNudgeDelayMilliseconds; 1923 return kPreferencesNudgeDelayMilliseconds;
1924 } 1924 }
1925 1925
1926 } // namespace syncer 1926 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698