Fix import error in mac_platform_backend.py
[chromium-blink-merge.git] / sync / internal_api / js_sync_manager_observer.cc
blob9f8848d8499ef044b75e88fa1a1b07c605178312
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"
7 #include <cstddef>
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_arg_list.h"
18 #include "sync/js/js_event_details.h"
19 #include "sync/js/js_event_handler.h"
21 namespace syncer {
23 JsSyncManagerObserver::JsSyncManagerObserver() {}
25 JsSyncManagerObserver::~JsSyncManagerObserver() {}
27 void JsSyncManagerObserver::SetJsEventHandler(
28 const WeakHandle<JsEventHandler>& event_handler) {
29 event_handler_ = event_handler;
32 void JsSyncManagerObserver::OnSyncCycleCompleted(
33 const sessions::SyncSessionSnapshot& snapshot) {
34 if (!event_handler_.IsInitialized()) {
35 return;
37 base::DictionaryValue details;
38 details.Set("snapshot", snapshot.ToValue());
39 HandleJsEvent(FROM_HERE, "onSyncCycleCompleted", JsEventDetails(&details));
42 void JsSyncManagerObserver::OnConnectionStatusChange(ConnectionStatus status) {
43 if (!event_handler_.IsInitialized()) {
44 return;
46 base::DictionaryValue details;
47 details.SetString("status", ConnectionStatusToString(status));
48 HandleJsEvent(FROM_HERE,
49 "onConnectionStatusChange", JsEventDetails(&details));
52 void JsSyncManagerObserver::OnActionableError(
53 const SyncProtocolError& sync_error) {
54 if (!event_handler_.IsInitialized()) {
55 return;
57 base::DictionaryValue details;
58 details.Set("syncError", sync_error.ToValue());
59 HandleJsEvent(FROM_HERE, "onActionableError",
60 JsEventDetails(&details));
63 void JsSyncManagerObserver::OnInitializationComplete(
64 const WeakHandle<JsBackend>& js_backend,
65 const WeakHandle<DataTypeDebugInfoListener>& debug_info_listener,
66 bool success, syncer::ModelTypeSet restored_types) {
67 if (!event_handler_.IsInitialized()) {
68 return;
70 // Ignore the |js_backend| argument; it's not really convertible to
71 // JSON anyway.
73 base::DictionaryValue details;
74 details.Set("restoredTypes", ModelTypeSetToValue(restored_types));
76 HandleJsEvent(FROM_HERE,
77 "onInitializationComplete",
78 JsEventDetails(&details));
81 void JsSyncManagerObserver::OnStopSyncingPermanently() {
82 if (!event_handler_.IsInitialized()) {
83 return;
85 HandleJsEvent(FROM_HERE, "onStopSyncingPermanently", JsEventDetails());
88 void JsSyncManagerObserver::HandleJsEvent(
89 const tracked_objects::Location& from_here,
90 const std::string& name, const JsEventDetails& details) {
91 if (!event_handler_.IsInitialized()) {
92 NOTREACHED();
93 return;
95 event_handler_.Call(from_here,
96 &JsEventHandler::HandleJsEvent, name, details);
99 } // namespace syncer