blob: 1361c8b8fe5a3220a46b3ba197cae84b139cf0ab [file] [log] [blame]
[email protected]12bb3e112012-01-18 08:58:011// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]88af96012011-02-11 20:50:172// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]91835ca2012-04-21 09:59:425#include "sync/internal_api/js_sync_manager_observer.h"
[email protected]88af96012011-02-11 20:50:176
7#include <cstddef>
8
[email protected]c62dd9d2011-09-21 18:05:419#include "base/location.h"
[email protected]88af96012011-02-11 20:50:1710#include "base/logging.h"
[email protected]a4bbc1f92013-06-11 07:28:1911#include "base/strings/string_number_conversions.h"
[email protected]88af96012011-02-11 20:50:1712#include "base/values.h"
[email protected]002d39192012-07-03 01:30:5613#include "sync/internal_api/public/base/model_type.h"
[email protected]406203d2012-06-17 01:07:1914#include "sync/internal_api/public/change_record.h"
[email protected]3f8556a2012-06-07 17:50:1915#include "sync/internal_api/public/sessions/sync_session_snapshot.h"
[email protected]ceffdf02012-07-17 20:12:1516#include "sync/internal_api/public/util/sync_string_conversions.h"
[email protected]c1c32c82012-03-15 09:35:4217#include "sync/js/js_event_details.h"
18#include "sync/js/js_event_handler.h"
[email protected]88af96012011-02-11 20:50:1719
[email protected]65f173552012-06-28 22:43:5820namespace syncer {
[email protected]88af96012011-02-11 20:50:1721
[email protected]fa134872011-08-02 18:39:5522JsSyncManagerObserver::JsSyncManagerObserver() {}
[email protected]88af96012011-02-11 20:50:1723
24JsSyncManagerObserver::~JsSyncManagerObserver() {}
25
[email protected]fa134872011-08-02 18:39:5526void JsSyncManagerObserver::SetJsEventHandler(
27 const WeakHandle<JsEventHandler>& event_handler) {
28 event_handler_ = event_handler;
29}
30
[email protected]88af96012011-02-11 20:50:1731void JsSyncManagerObserver::OnSyncCycleCompleted(
[email protected]90ce61b52012-04-24 19:32:2832 const sessions::SyncSessionSnapshot& snapshot) {
[email protected]fa134872011-08-02 18:39:5533 if (!event_handler_.IsInitialized()) {
34 return;
35 }
[email protected]0c6c1e42013-06-21 19:42:1936 base::DictionaryValue details;
[email protected]90ce61b52012-04-24 19:32:2837 details.Set("snapshot", snapshot.ToValue());
[email protected]fa134872011-08-02 18:39:5538 HandleJsEvent(FROM_HERE, "onSyncCycleCompleted", JsEventDetails(&details));
[email protected]88af96012011-02-11 20:50:1739}
40
[email protected]d45f0d92012-07-20 17:25:4141void JsSyncManagerObserver::OnConnectionStatusChange(ConnectionStatus status) {
[email protected]fa134872011-08-02 18:39:5542 if (!event_handler_.IsInitialized()) {
43 return;
44 }
[email protected]0c6c1e42013-06-21 19:42:1945 base::DictionaryValue details;
[email protected]d45f0d92012-07-20 17:25:4146 details.SetString("status", ConnectionStatusToString(status));
[email protected]6e2059892012-03-08 02:22:2447 HandleJsEvent(FROM_HERE,
48 "onConnectionStatusChange", JsEventDetails(&details));
[email protected]88af96012011-02-11 20:50:1749}
50
[email protected]cb5199b2011-09-04 01:55:5251void JsSyncManagerObserver::OnActionableError(
52 const SyncProtocolError& sync_error) {
53 if (!event_handler_.IsInitialized()) {
54 return;
55 }
[email protected]0c6c1e42013-06-21 19:42:1956 base::DictionaryValue details;
[email protected]cb5199b2011-09-04 01:55:5257 details.Set("syncError", sync_error.ToValue());
58 HandleJsEvent(FROM_HERE, "onActionableError",
59 JsEventDetails(&details));
60}
61
[email protected]eb370fc2014-03-21 22:14:3562void JsSyncManagerObserver::OnProtocolEvent(
63 const ProtocolEvent& event) { }
64
[email protected]b99f5482014-02-12 23:47:3765void JsSyncManagerObserver::OnMigrationRequested(ModelTypeSet types) { }
66
[email protected]fa134872011-08-02 18:39:5567void JsSyncManagerObserver::OnInitializationComplete(
[email protected]da0832b2011-09-08 17:00:0468 const WeakHandle<JsBackend>& js_backend,
[email protected]12a11e22012-11-08 06:26:3069 const WeakHandle<DataTypeDebugInfoListener>& debug_info_listener,
[email protected]62c28b92012-07-30 04:37:4870 bool success, syncer::ModelTypeSet restored_types) {
[email protected]fa134872011-08-02 18:39:5571 if (!event_handler_.IsInitialized()) {
72 return;
73 }
74 // Ignore the |js_backend| argument; it's not really convertible to
75 // JSON anyway.
[email protected]62c28b92012-07-30 04:37:4876
[email protected]0c6c1e42013-06-21 19:42:1977 base::DictionaryValue details;
[email protected]32e757a2012-07-30 23:09:3678 details.Set("restoredTypes", ModelTypeSetToValue(restored_types));
[email protected]62c28b92012-07-30 04:37:4879
[email protected]32e757a2012-07-30 23:09:3680 HandleJsEvent(FROM_HERE,
81 "onInitializationComplete",
82 JsEventDetails(&details));
[email protected]88af96012011-02-11 20:50:1783}
84
[email protected]fa134872011-08-02 18:39:5585void JsSyncManagerObserver::HandleJsEvent(
86 const tracked_objects::Location& from_here,
87 const std::string& name, const JsEventDetails& details) {
88 if (!event_handler_.IsInitialized()) {
89 NOTREACHED();
90 return;
91 }
92 event_handler_.Call(from_here,
93 &JsEventHandler::HandleJsEvent, name, details);
[email protected]88af96012011-02-11 20:50:1794}
95
[email protected]65f173552012-06-28 22:43:5896} // namespace syncer