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 10837111: [Sync] Print out notification state explicitly in about:sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests 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
« no previous file with comments | « sync/internal_api/sync_manager_impl.h ('k') | sync/internal_api/sync_manager_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 22 matching lines...) Expand all
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"
35 #include "sync/internal_api/public/write_transaction.h" 35 #include "sync/internal_api/public/write_transaction.h"
36 #include "sync/internal_api/syncapi_internal.h" 36 #include "sync/internal_api/syncapi_internal.h"
37 #include "sync/internal_api/syncapi_server_connection_manager.h" 37 #include "sync/internal_api/syncapi_server_connection_manager.h"
38 #include "sync/js/js_arg_list.h" 38 #include "sync/js/js_arg_list.h"
39 #include "sync/js/js_event_details.h" 39 #include "sync/js/js_event_details.h"
40 #include "sync/js/js_event_handler.h" 40 #include "sync/js/js_event_handler.h"
41 #include "sync/js/js_reply_handler.h" 41 #include "sync/js/js_reply_handler.h"
42 #include "sync/notifier/invalidation_util.h" 42 #include "sync/notifier/invalidation_util.h"
43 #include "sync/notifier/notifications_disabled_reason.h"
44 #include "sync/notifier/sync_notifier.h" 43 #include "sync/notifier/sync_notifier.h"
45 #include "sync/protocol/encryption.pb.h" 44 #include "sync/protocol/encryption.pb.h"
46 #include "sync/protocol/proto_value_conversions.h" 45 #include "sync/protocol/proto_value_conversions.h"
47 #include "sync/protocol/sync.pb.h" 46 #include "sync/protocol/sync.pb.h"
48 #include "sync/syncable/directory.h" 47 #include "sync/syncable/directory.h"
49 #include "sync/syncable/entry.h" 48 #include "sync/syncable/entry.h"
50 #include "sync/syncable/in_memory_directory_backing_store.h" 49 #include "sync/syncable/in_memory_directory_backing_store.h"
51 #include "sync/syncable/nigori_util.h" 50 #include "sync/syncable/nigori_util.h"
52 #include "sync/syncable/on_disk_directory_backing_store.h" 51 #include "sync/syncable/on_disk_directory_backing_store.h"
53 #include "sync/util/get_session_name.h" 52 #include "sync/util/get_session_name.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 return delay; 167 return delay;
169 } 168 }
170 }; 169 };
171 170
172 SyncManagerImpl::SyncManagerImpl(const std::string& name) 171 SyncManagerImpl::SyncManagerImpl(const std::string& name)
173 : name_(name), 172 : name_(name),
174 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 173 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
175 change_delegate_(NULL), 174 change_delegate_(NULL),
176 initialized_(false), 175 initialized_(false),
177 observing_ip_address_changes_(false), 176 observing_ip_address_changes_(false),
177 notifications_disabled_reason_(TRANSIENT_NOTIFICATION_ERROR),
178 throttled_data_type_tracker_(&allstatus_), 178 throttled_data_type_tracker_(&allstatus_),
179 traffic_recorder_(kMaxMessagesToRecord, kMaxMessageSizeToRecord), 179 traffic_recorder_(kMaxMessagesToRecord, kMaxMessageSizeToRecord),
180 encryptor_(NULL), 180 encryptor_(NULL),
181 unrecoverable_error_handler_(NULL), 181 unrecoverable_error_handler_(NULL),
182 report_unrecoverable_error_function_(NULL), 182 report_unrecoverable_error_function_(NULL),
183 nigori_overwrite_count_(0) { 183 nigori_overwrite_count_(0) {
184 // Pre-fill |notification_info_map_|. 184 // Pre-fill |notification_info_map_|.
185 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { 185 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
186 notification_info_map_.insert( 186 notification_info_map_.insert(
187 std::make_pair(ModelTypeFromInt(i), NotificationInfo())); 187 std::make_pair(ModelTypeFromInt(i), NotificationInfo()));
(...skipping 1420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 name, js_message_handler.Run(args)); 1608 name, js_message_handler.Run(args));
1609 } 1609 }
1610 1610
1611 void SyncManagerImpl::BindJsMessageHandler( 1611 void SyncManagerImpl::BindJsMessageHandler(
1612 const std::string& name, 1612 const std::string& name,
1613 UnboundJsMessageHandler unbound_message_handler) { 1613 UnboundJsMessageHandler unbound_message_handler) {
1614 js_message_handlers_[name] = 1614 js_message_handlers_[name] =
1615 base::Bind(unbound_message_handler, base::Unretained(this)); 1615 base::Bind(unbound_message_handler, base::Unretained(this));
1616 } 1616 }
1617 1617
1618 void SyncManagerImpl::OnNotificationStateChange(
1619 NotificationsDisabledReason reason) {
1620 const std::string& reason_str = NotificationsDisabledReasonToString(reason);
1621 notifications_disabled_reason_ = reason;
1622 DVLOG(1) << "Notification state changed to: " << reason_str;
1623 const bool notifications_enabled =
1624 (notifications_disabled_reason_ == NO_NOTIFICATION_ERROR);
1625 allstatus_.SetNotificationsEnabled(notifications_enabled);
1626 scheduler_->SetNotificationsEnabled(notifications_enabled);
1627
1628 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth
1629 // error.
1630
1631 if (js_event_handler_.IsInitialized()) {
1632 DictionaryValue details;
1633 details.Set("state", Value::CreateStringValue(reason_str));
1634 js_event_handler_.Call(FROM_HERE,
1635 &JsEventHandler::HandleJsEvent,
1636 "onNotificationStateChange",
1637 JsEventDetails(&details));
1638 }
1639 }
1640
1618 DictionaryValue* SyncManagerImpl::NotificationInfoToValue( 1641 DictionaryValue* SyncManagerImpl::NotificationInfoToValue(
1619 const NotificationInfoMap& notification_info) { 1642 const NotificationInfoMap& notification_info) {
1620 DictionaryValue* value = new DictionaryValue(); 1643 DictionaryValue* value = new DictionaryValue();
1621 1644
1622 for (NotificationInfoMap::const_iterator it = notification_info.begin(); 1645 for (NotificationInfoMap::const_iterator it = notification_info.begin();
1623 it != notification_info.end(); ++it) { 1646 it != notification_info.end(); ++it) {
1624 const std::string& model_type_str = ModelTypeToString(it->first); 1647 const std::string& model_type_str = ModelTypeToString(it->first);
1625 value->Set(model_type_str, it->second.ToValue()); 1648 value->Set(model_type_str, it->second.ToValue());
1626 } 1649 }
1627 1650
1628 return value; 1651 return value;
1629 } 1652 }
1630 1653
1654 std::string SyncManagerImpl::NotificationInfoToString(
1655 const NotificationInfoMap& notification_info) {
1656 scoped_ptr<DictionaryValue> value(
1657 NotificationInfoToValue(notification_info));
1658 std::string str;
1659 base::JSONWriter::Write(value.get(), &str);
1660 return str;
1661 }
1662
1631 JsArgList SyncManagerImpl::GetNotificationState( 1663 JsArgList SyncManagerImpl::GetNotificationState(
1632 const JsArgList& args) { 1664 const JsArgList& args) {
1633 bool notifications_enabled = allstatus_.status().notifications_enabled; 1665 const std::string& notification_state =
1666 NotificationsDisabledReasonToString(notifications_disabled_reason_);
1667 DVLOG(1) << "GetNotificationState: " << notification_state;
1634 ListValue return_args; 1668 ListValue return_args;
1635 return_args.Append(Value::CreateBooleanValue(notifications_enabled)); 1669 return_args.Append(Value::CreateStringValue(notification_state));
1636 return JsArgList(&return_args); 1670 return JsArgList(&return_args);
1637 } 1671 }
1638 1672
1639 JsArgList SyncManagerImpl::GetNotificationInfo( 1673 JsArgList SyncManagerImpl::GetNotificationInfo(
1640 const JsArgList& args) { 1674 const JsArgList& args) {
1675 DVLOG(1) << "GetNotificationInfo: "
1676 << NotificationInfoToString(notification_info_map_);
1641 ListValue return_args; 1677 ListValue return_args;
1642 return_args.Append(NotificationInfoToValue(notification_info_map_)); 1678 return_args.Append(NotificationInfoToValue(notification_info_map_));
1643 return JsArgList(&return_args); 1679 return JsArgList(&return_args);
1644 } 1680 }
1645 1681
1646 JsArgList SyncManagerImpl::GetRootNodeDetails( 1682 JsArgList SyncManagerImpl::GetRootNodeDetails(
1647 const JsArgList& args) { 1683 const JsArgList& args) {
1648 ReadTransaction trans(FROM_HERE, GetUserShare()); 1684 ReadTransaction trans(FROM_HERE, GetUserShare());
1649 ReadNode root(&trans); 1685 ReadNode root(&trans);
1650 root.InitByRootLookup(); 1686 root.InitByRootLookup();
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 const ModelTypePayloadMap& type_payloads) { 1798 const ModelTypePayloadMap& type_payloads) {
1763 for (ModelTypePayloadMap::const_iterator it = type_payloads.begin(); 1799 for (ModelTypePayloadMap::const_iterator it = type_payloads.begin();
1764 it != type_payloads.end(); ++it) { 1800 it != type_payloads.end(); ++it) {
1765 NotificationInfo* info = &notification_info_map_[it->first]; 1801 NotificationInfo* info = &notification_info_map_[it->first];
1766 info->total_count++; 1802 info->total_count++;
1767 info->payload = it->second; 1803 info->payload = it->second;
1768 } 1804 }
1769 } 1805 }
1770 1806
1771 void SyncManagerImpl::OnNotificationsEnabled() { 1807 void SyncManagerImpl::OnNotificationsEnabled() {
1772 DVLOG(1) << "Notifications enabled"; 1808 OnNotificationStateChange(NO_NOTIFICATION_ERROR);
1773 allstatus_.SetNotificationsEnabled(true);
1774 scheduler_->SetNotificationsEnabled(true);
1775
1776 // TODO(akalin): Separate onNotificationStateChange into
1777 // enabled/disabled events.
1778 if (js_event_handler_.IsInitialized()) {
1779 DictionaryValue details;
1780 details.Set("enabled", Value::CreateBooleanValue(true));
1781 js_event_handler_.Call(FROM_HERE,
1782 &JsEventHandler::HandleJsEvent,
1783 "onNotificationStateChange",
1784 JsEventDetails(&details));
1785 }
1786 } 1809 }
1787 1810
1788 void SyncManagerImpl::OnNotificationsDisabled( 1811 void SyncManagerImpl::OnNotificationsDisabled(
1789 NotificationsDisabledReason reason) { 1812 NotificationsDisabledReason reason) {
1790 DVLOG(1) << "Notifications disabled with reason " 1813 OnNotificationStateChange(reason);
1791 << NotificationsDisabledReasonToString(reason);
1792 allstatus_.SetNotificationsEnabled(false);
1793 scheduler_->SetNotificationsEnabled(false);
1794 if (js_event_handler_.IsInitialized()) {
1795 DictionaryValue details;
1796 details.Set("enabled", Value::CreateBooleanValue(false));
1797 js_event_handler_.Call(FROM_HERE,
1798 &JsEventHandler::HandleJsEvent,
1799 "onNotificationStateChange",
1800 JsEventDetails(&details));
1801 }
1802 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth
1803 // error.
1804 } 1814 }
1805 1815
1806 void SyncManagerImpl::OnIncomingNotification( 1816 void SyncManagerImpl::OnIncomingNotification(
1807 const ObjectIdPayloadMap& id_payloads, 1817 const ObjectIdPayloadMap& id_payloads,
1808 IncomingNotificationSource source) { 1818 IncomingNotificationSource source) {
1809 DCHECK(thread_checker_.CalledOnValidThread()); 1819 DCHECK(thread_checker_.CalledOnValidThread());
1810 const ModelTypePayloadMap& type_payloads = 1820 const ModelTypePayloadMap& type_payloads =
1811 ObjectIdPayloadMapToModelTypePayloadMap(id_payloads); 1821 ObjectIdPayloadMapToModelTypePayloadMap(id_payloads);
1812 if (source == LOCAL_NOTIFICATION) { 1822 if (source == LOCAL_NOTIFICATION) {
1813 scheduler_->ScheduleNudgeWithPayloadsAsync( 1823 scheduler_->ScheduleNudgeWithPayloadsAsync(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1886 int SyncManagerImpl::GetDefaultNudgeDelay() { 1896 int SyncManagerImpl::GetDefaultNudgeDelay() {
1887 return kDefaultNudgeDelayMilliseconds; 1897 return kDefaultNudgeDelayMilliseconds;
1888 } 1898 }
1889 1899
1890 // static. 1900 // static.
1891 int SyncManagerImpl::GetPreferencesNudgeDelay() { 1901 int SyncManagerImpl::GetPreferencesNudgeDelay() {
1892 return kPreferencesNudgeDelayMilliseconds; 1902 return kPreferencesNudgeDelayMilliseconds;
1893 } 1903 }
1894 1904
1895 } // namespace syncer 1905 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/sync_manager_impl.h ('k') | sync/internal_api/sync_manager_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698