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
3 // found in the LICENSE file.
5 #include "sync/internal_api/js_sync_manager_observer.h"
9 #include "base/location.h"
10 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/values.h"
13 #include "sync/internal_api/public/base/model_type.h"
14 #include "sync/internal_api/public/change_record.h"
15 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
16 #include "sync/internal_api/public/util/sync_string_conversions.h"
17 #include "sync/js/js_event_details.h"
18 #include "sync/js/js_event_handler.h"
22 JsSyncManagerObserver::JsSyncManagerObserver() {}
24 JsSyncManagerObserver::~JsSyncManagerObserver() {}
26 void JsSyncManagerObserver::SetJsEventHandler(
27 const WeakHandle
<JsEventHandler
>& event_handler
) {
28 event_handler_
= event_handler
;
31 void JsSyncManagerObserver::OnSyncCycleCompleted(
32 const sessions::SyncSessionSnapshot
& snapshot
) {
33 if (!event_handler_
.IsInitialized()) {
36 base::DictionaryValue details
;
37 details
.Set("snapshot", snapshot
.ToValue());
38 HandleJsEvent(FROM_HERE
, "onSyncCycleCompleted", JsEventDetails(&details
));
41 void JsSyncManagerObserver::OnConnectionStatusChange(ConnectionStatus status
) {
42 if (!event_handler_
.IsInitialized()) {
45 base::DictionaryValue details
;
46 details
.SetString("status", ConnectionStatusToString(status
));
47 HandleJsEvent(FROM_HERE
,
48 "onConnectionStatusChange", JsEventDetails(&details
));
51 void JsSyncManagerObserver::OnActionableError(
52 const SyncProtocolError
& sync_error
) {
53 if (!event_handler_
.IsInitialized()) {
56 base::DictionaryValue details
;
57 details
.Set("syncError", sync_error
.ToValue());
58 HandleJsEvent(FROM_HERE
, "onActionableError",
59 JsEventDetails(&details
));
62 void JsSyncManagerObserver::OnProtocolEvent(
63 const ProtocolEvent
& event
) { }
65 void JsSyncManagerObserver::OnMigrationRequested(ModelTypeSet types
) { }
67 void JsSyncManagerObserver::OnInitializationComplete(
68 const WeakHandle
<JsBackend
>& js_backend
,
69 const WeakHandle
<DataTypeDebugInfoListener
>& debug_info_listener
,
70 bool success
, syncer::ModelTypeSet restored_types
) {
71 if (!event_handler_
.IsInitialized()) {
74 // Ignore the |js_backend| argument; it's not really convertible to
77 base::DictionaryValue details
;
78 details
.Set("restoredTypes", ModelTypeSetToValue(restored_types
));
80 HandleJsEvent(FROM_HERE
,
81 "onInitializationComplete",
82 JsEventDetails(&details
));
85 void JsSyncManagerObserver::HandleJsEvent(
86 const tracked_objects::Location
& from_here
,
87 const std::string
& name
, const JsEventDetails
& details
) {
88 if (!event_handler_
.IsInitialized()) {
92 event_handler_
.Call(from_here
,
93 &JsEventHandler::HandleJsEvent
, name
, details
);