summaryrefslogtreecommitdiffstats
path: root/sync/internal_api/js_sync_manager_observer.cc
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-21 09:59:42 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-21 09:59:42 +0000
commit91835ca82c6ff7f1aeb68e314a3842da1aca6841 (patch)
treec7e8119bd0fb2a8e1d6910c969e1d3f62dbff1f8 /sync/internal_api/js_sync_manager_observer.cc
parent7983f3bae6ab9c86aea81816e6bb1bd15ab114fe (diff)
downloadchromium_src-91835ca82c6ff7f1aeb68e314a3842da1aca6841.zip
chromium_src-91835ca82c6ff7f1aeb68e314a3842da1aca6841.tar.gz
chromium_src-91835ca82c6ff7f1aeb68e314a3842da1aca6841.tar.bz2
[Sync] Move 'syncapi_core' and 'sync_unit_tests' targets to sync/
Also move related test files. Lock down deps for sync/internal_api. Clean up some deps on chrome/browser/sync. BUG=117585 TEST= Review URL: https://chromiumcodereview.appspot.com/10147003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133349 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/internal_api/js_sync_manager_observer.cc')
-rw-r--r--sync/internal_api/js_sync_manager_observer.cc169
1 files changed, 169 insertions, 0 deletions
diff --git a/sync/internal_api/js_sync_manager_observer.cc b/sync/internal_api/js_sync_manager_observer.cc
new file mode 100644
index 0000000..b9cf9f3
--- /dev/null
+++ b/sync/internal_api/js_sync_manager_observer.cc
@@ -0,0 +1,169 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sync/internal_api/js_sync_manager_observer.h"
+
+#include <cstddef>
+
+#include "base/location.h"
+#include "base/logging.h"
+#include "base/string_number_conversions.h"
+#include "base/values.h"
+#include "sync/internal_api/change_record.h"
+#include "sync/js/js_arg_list.h"
+#include "sync/js/js_event_details.h"
+#include "sync/js/js_event_handler.h"
+#include "sync/sessions/session_state.h"
+#include "sync/syncable/model_type.h"
+
+namespace browser_sync {
+
+using browser_sync::SyncProtocolError;
+
+JsSyncManagerObserver::JsSyncManagerObserver() {}
+
+JsSyncManagerObserver::~JsSyncManagerObserver() {}
+
+void JsSyncManagerObserver::SetJsEventHandler(
+ const WeakHandle<JsEventHandler>& event_handler) {
+ event_handler_ = event_handler;
+}
+
+void JsSyncManagerObserver::OnSyncCycleCompleted(
+ const sessions::SyncSessionSnapshot* snapshot) {
+ if (!event_handler_.IsInitialized()) {
+ return;
+ }
+ DictionaryValue details;
+ details.Set("snapshot", snapshot->ToValue());
+ HandleJsEvent(FROM_HERE, "onSyncCycleCompleted", JsEventDetails(&details));
+}
+
+void JsSyncManagerObserver::OnConnectionStatusChange(
+ sync_api::ConnectionStatus status) {
+ if (!event_handler_.IsInitialized()) {
+ return;
+ }
+ DictionaryValue details;
+ details.SetString("status", sync_api::ConnectionStatusToString(status));
+ HandleJsEvent(FROM_HERE,
+ "onConnectionStatusChange", JsEventDetails(&details));
+}
+
+void JsSyncManagerObserver::OnUpdatedToken(const std::string& token) {
+ if (!event_handler_.IsInitialized()) {
+ return;
+ }
+ DictionaryValue details;
+ details.SetString("token", "<redacted>");
+ HandleJsEvent(FROM_HERE, "onUpdatedToken", JsEventDetails(&details));
+}
+
+void JsSyncManagerObserver::OnPassphraseRequired(
+ sync_api::PassphraseRequiredReason reason,
+ const sync_pb::EncryptedData& pending_keys) {
+ if (!event_handler_.IsInitialized()) {
+ return;
+ }
+ DictionaryValue details;
+ details.SetString("reason",
+ sync_api::PassphraseRequiredReasonToString(reason));
+ HandleJsEvent(FROM_HERE, "onPassphraseRequired", JsEventDetails(&details));
+}
+
+void JsSyncManagerObserver::OnPassphraseAccepted() {
+ if (!event_handler_.IsInitialized()) {
+ return;
+ }
+ DictionaryValue details;
+ HandleJsEvent(FROM_HERE, "onPassphraseAccepted", JsEventDetails(&details));
+}
+
+void JsSyncManagerObserver::OnBootstrapTokenUpdated(
+ const std::string& boostrap_token) {
+ if (!event_handler_.IsInitialized()) {
+ return;
+ }
+ DictionaryValue details;
+ details.SetString("bootstrapToken", "<redacted>");
+ HandleJsEvent(FROM_HERE, "OnBootstrapTokenUpdated", JsEventDetails(&details));
+}
+
+void JsSyncManagerObserver::OnEncryptedTypesChanged(
+ syncable::ModelTypeSet encrypted_types,
+ bool encrypt_everything) {
+ if (!event_handler_.IsInitialized()) {
+ return;
+ }
+ DictionaryValue details;
+ details.Set("encryptedTypes",
+ syncable::ModelTypeSetToValue(encrypted_types));
+ details.SetBoolean("encryptEverything", encrypt_everything);
+ HandleJsEvent(FROM_HERE,
+ "onEncryptedTypesChanged", JsEventDetails(&details));
+}
+
+void JsSyncManagerObserver::OnEncryptionComplete() {
+ if (!event_handler_.IsInitialized()) {
+ return;
+ }
+ DictionaryValue details;
+ HandleJsEvent(FROM_HERE, "onEncryptionComplete", JsEventDetails());
+}
+
+void JsSyncManagerObserver::OnActionableError(
+ const SyncProtocolError& sync_error) {
+ if (!event_handler_.IsInitialized()) {
+ return;
+ }
+ DictionaryValue details;
+ details.Set("syncError", sync_error.ToValue());
+ HandleJsEvent(FROM_HERE, "onActionableError",
+ JsEventDetails(&details));
+}
+
+void JsSyncManagerObserver::OnInitializationComplete(
+ const WeakHandle<JsBackend>& js_backend,
+ bool success) {
+ if (!event_handler_.IsInitialized()) {
+ return;
+ }
+ // Ignore the |js_backend| argument; it's not really convertible to
+ // JSON anyway.
+ HandleJsEvent(FROM_HERE, "onInitializationComplete", JsEventDetails());
+}
+
+void JsSyncManagerObserver::OnStopSyncingPermanently() {
+ if (!event_handler_.IsInitialized()) {
+ return;
+ }
+ HandleJsEvent(FROM_HERE, "onStopSyncingPermanently", JsEventDetails());
+}
+
+void JsSyncManagerObserver::OnClearServerDataSucceeded() {
+ if (!event_handler_.IsInitialized()) {
+ return;
+ }
+ HandleJsEvent(FROM_HERE, "onClearServerDataSucceeded", JsEventDetails());
+}
+
+void JsSyncManagerObserver::OnClearServerDataFailed() {
+ if (!event_handler_.IsInitialized()) {
+ return;
+ }
+ HandleJsEvent(FROM_HERE, "onClearServerDataFailed", JsEventDetails());
+}
+
+void JsSyncManagerObserver::HandleJsEvent(
+ const tracked_objects::Location& from_here,
+ const std::string& name, const JsEventDetails& details) {
+ if (!event_handler_.IsInitialized()) {
+ NOTREACHED();
+ return;
+ }
+ event_handler_.Call(from_here,
+ &JsEventHandler::HandleJsEvent, name, details);
+}
+
+} // namespace browser_sync