Index: sync/internal_api/sync_manager_impl.cc |
diff --git a/sync/internal_api/sync_manager_impl.cc b/sync/internal_api/sync_manager_impl.cc |
index 93da8de4e6ef4cefd1aa83a868ded25e19cb68b2..83d552e44841d45dd599320ffe4c5c1e4969bc4f 100644 |
--- a/sync/internal_api/sync_manager_impl.cc |
+++ b/sync/internal_api/sync_manager_impl.cc |
@@ -40,7 +40,6 @@ |
#include "sync/js/js_event_handler.h" |
#include "sync/js/js_reply_handler.h" |
#include "sync/notifier/invalidation_util.h" |
-#include "sync/notifier/notifications_disabled_reason.h" |
#include "sync/notifier/sync_notifier.h" |
#include "sync/protocol/encryption.pb.h" |
#include "sync/protocol/proto_value_conversions.h" |
@@ -175,6 +174,7 @@ SyncManagerImpl::SyncManagerImpl(const std::string& name) |
change_delegate_(NULL), |
initialized_(false), |
observing_ip_address_changes_(false), |
+ notifications_disabled_reason_(TRANSIENT_NOTIFICATION_ERROR), |
throttled_data_type_tracker_(&allstatus_), |
traffic_recorder_(kMaxMessagesToRecord, kMaxMessageSizeToRecord), |
encryptor_(NULL), |
@@ -1615,6 +1615,29 @@ void SyncManagerImpl::BindJsMessageHandler( |
base::Bind(unbound_message_handler, base::Unretained(this)); |
} |
+void SyncManagerImpl::OnNotificationStateChange( |
+ NotificationsDisabledReason reason) { |
+ const std::string& reason_str = NotificationsDisabledReasonToString(reason); |
+ notifications_disabled_reason_ = reason; |
+ DVLOG(1) << "Notification state changed to: " << reason_str; |
+ const bool notifications_enabled = |
+ (notifications_disabled_reason_ == NO_NOTIFICATION_ERROR); |
+ allstatus_.SetNotificationsEnabled(notifications_enabled); |
+ scheduler_->SetNotificationsEnabled(notifications_enabled); |
+ |
+ // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth |
+ // error. |
+ |
+ if (js_event_handler_.IsInitialized()) { |
+ DictionaryValue details; |
+ details.Set("state", Value::CreateStringValue(reason_str)); |
+ js_event_handler_.Call(FROM_HERE, |
+ &JsEventHandler::HandleJsEvent, |
+ "onNotificationStateChange", |
+ JsEventDetails(&details)); |
+ } |
+} |
+ |
DictionaryValue* SyncManagerImpl::NotificationInfoToValue( |
const NotificationInfoMap& notification_info) { |
DictionaryValue* value = new DictionaryValue(); |
@@ -1628,16 +1651,29 @@ DictionaryValue* SyncManagerImpl::NotificationInfoToValue( |
return value; |
} |
+std::string SyncManagerImpl::NotificationInfoToString( |
+ const NotificationInfoMap& notification_info) { |
+ scoped_ptr<DictionaryValue> value( |
+ NotificationInfoToValue(notification_info)); |
+ std::string str; |
+ base::JSONWriter::Write(value.get(), &str); |
+ return str; |
+} |
+ |
JsArgList SyncManagerImpl::GetNotificationState( |
const JsArgList& args) { |
- bool notifications_enabled = allstatus_.status().notifications_enabled; |
+ const std::string& notification_state = |
+ NotificationsDisabledReasonToString(notifications_disabled_reason_); |
+ DVLOG(1) << "GetNotificationState: " << notification_state; |
ListValue return_args; |
- return_args.Append(Value::CreateBooleanValue(notifications_enabled)); |
+ return_args.Append(Value::CreateStringValue(notification_state)); |
return JsArgList(&return_args); |
} |
JsArgList SyncManagerImpl::GetNotificationInfo( |
const JsArgList& args) { |
+ DVLOG(1) << "GetNotificationInfo: " |
+ << NotificationInfoToString(notification_info_map_); |
ListValue return_args; |
return_args.Append(NotificationInfoToValue(notification_info_map_)); |
return JsArgList(&return_args); |
@@ -1769,38 +1805,12 @@ void SyncManagerImpl::UpdateNotificationInfo( |
} |
void SyncManagerImpl::OnNotificationsEnabled() { |
- DVLOG(1) << "Notifications enabled"; |
- allstatus_.SetNotificationsEnabled(true); |
- scheduler_->SetNotificationsEnabled(true); |
- |
- // TODO(akalin): Separate onNotificationStateChange into |
- // enabled/disabled events. |
- if (js_event_handler_.IsInitialized()) { |
- DictionaryValue details; |
- details.Set("enabled", Value::CreateBooleanValue(true)); |
- js_event_handler_.Call(FROM_HERE, |
- &JsEventHandler::HandleJsEvent, |
- "onNotificationStateChange", |
- JsEventDetails(&details)); |
- } |
+ OnNotificationStateChange(NO_NOTIFICATION_ERROR); |
} |
void SyncManagerImpl::OnNotificationsDisabled( |
NotificationsDisabledReason reason) { |
- DVLOG(1) << "Notifications disabled with reason " |
- << NotificationsDisabledReasonToString(reason); |
- allstatus_.SetNotificationsEnabled(false); |
- scheduler_->SetNotificationsEnabled(false); |
- if (js_event_handler_.IsInitialized()) { |
- DictionaryValue details; |
- details.Set("enabled", Value::CreateBooleanValue(false)); |
- js_event_handler_.Call(FROM_HERE, |
- &JsEventHandler::HandleJsEvent, |
- "onNotificationStateChange", |
- JsEventDetails(&details)); |
- } |
- // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth |
- // error. |
+ OnNotificationStateChange(reason); |
} |
void SyncManagerImpl::OnIncomingNotification( |