[Mac] Add gfx::ScreenPoint[To|From]NSPoint.
[chromium-blink-merge.git] / sync / internal_api / js_sync_manager_observer.cc
blob1361c8b8fe5a3220a46b3ba197cae84b139cf0ab
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_event_details.h"
18 #include "sync/js/js_event_handler.h"
20 namespace syncer {
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()) {
34 return;
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()) {
43 return;
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()) {
54 return;
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()) {
72 return;
74 // Ignore the |js_backend| argument; it's not really convertible to
75 // JSON anyway.
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()) {
89 NOTREACHED();
90 return;
92 event_handler_.Call(from_here,
93 &JsEventHandler::HandleJsEvent, name, details);
96 } // namespace syncer