summaryrefslogtreecommitdiffstats
path: root/sync
diff options
context:
space:
mode:
Diffstat (limited to 'sync')
-rw-r--r--sync/internal_api/sync_manager_impl.cc72
-rw-r--r--sync/internal_api/sync_manager_impl.h9
-rw-r--r--sync/internal_api/sync_manager_impl_unittest.cc19
3 files changed, 60 insertions, 40 deletions
diff --git a/sync/internal_api/sync_manager_impl.cc b/sync/internal_api/sync_manager_impl.cc
index a3ee000..72f936f 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),
@@ -1616,6 +1616,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();
@@ -1629,16 +1652,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);
@@ -1770,38 +1806,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(
diff --git a/sync/internal_api/sync_manager_impl.h b/sync/internal_api/sync_manager_impl.h
index 01f37fc..c09a498 100644
--- a/sync/internal_api/sync_manager_impl.h
+++ b/sync/internal_api/sync_manager_impl.h
@@ -20,6 +20,7 @@
#include "sync/internal_api/js_sync_manager_observer.h"
#include "sync/internal_api/public/sync_manager.h"
#include "sync/js/js_backend.h"
+#include "sync/notifier/notifications_disabled_reason.h"
#include "sync/notifier/sync_notifier_observer.h"
#include "sync/syncable/directory_change_delegate.h"
#include "sync/util/cryptographer.h"
@@ -298,10 +299,16 @@ class SyncManagerImpl : public SyncManager,
void BindJsMessageHandler(
const std::string& name, UnboundJsMessageHandler unbound_message_handler);
+ // Helper function used by OnNotifications{Enabled,Disabled}().
+ void OnNotificationStateChange(NotificationsDisabledReason reason);
+
// Returned pointer is owned by the caller.
static DictionaryValue* NotificationInfoToValue(
const NotificationInfoMap& notification_info);
+ static std::string NotificationInfoToString(
+ const NotificationInfoMap& notification_info);
+
// JS message handlers.
JsArgList GetNotificationState(const JsArgList& args);
JsArgList GetNotificationInfo(const JsArgList& args);
@@ -381,6 +388,8 @@ class SyncManagerImpl : public SyncManager,
bool observing_ip_address_changes_;
+ NotificationsDisabledReason notifications_disabled_reason_;
+
// Map used to store the notification info to be displayed in
// about:sync page.
NotificationInfoMap notification_info_map_;
diff --git a/sync/internal_api/sync_manager_impl_unittest.cc b/sync/internal_api/sync_manager_impl_unittest.cc
index 0e6b464..bd2ffef 100644
--- a/sync/internal_api/sync_manager_impl_unittest.cc
+++ b/sync/internal_api/sync_manager_impl_unittest.cc
@@ -973,12 +973,13 @@ TEST_F(SyncManagerTest, ProcessJsMessage) {
StrictMock<MockJsReplyHandler> reply_handler;
- ListValue false_args;
- false_args.Append(Value::CreateBooleanValue(false));
+ ListValue disabled_args;
+ disabled_args.Append(
+ Value::CreateStringValue("TRANSIENT_NOTIFICATION_ERROR"));
EXPECT_CALL(reply_handler,
HandleJsReply("getNotificationState",
- HasArgsAsList(false_args)));
+ HasArgsAsList(disabled_args)));
// This message should be dropped.
SendJsMessage("unknownMessage", kNoArgs, reply_handler.AsWeakHandle());
@@ -1261,17 +1262,17 @@ TEST_F(SyncManagerTest, OnNotificationStateChange) {
InSequence dummy;
StrictMock<MockJsEventHandler> event_handler;
- DictionaryValue true_details;
- true_details.SetBoolean("enabled", true);
- DictionaryValue false_details;
- false_details.SetBoolean("enabled", false);
+ DictionaryValue enabled_details;
+ enabled_details.SetString("state", "NO_NOTIFICATION_ERROR");
+ DictionaryValue disabled_details;
+ disabled_details.SetString("state", "TRANSIENT_NOTIFICATION_ERROR");
EXPECT_CALL(event_handler,
HandleJsEvent("onNotificationStateChange",
- HasDetailsAsDictionary(true_details)));
+ HasDetailsAsDictionary(enabled_details)));
EXPECT_CALL(event_handler,
HandleJsEvent("onNotificationStateChange",
- HasDetailsAsDictionary(false_details)));
+ HasDetailsAsDictionary(disabled_details)));
SimulateEnableNotificationsForTest();
SimulateDisableNotificationsForTest(TRANSIENT_NOTIFICATION_ERROR);