Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: sync/internal_api/js_sync_manager_observer.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "sync/internal_api/js_sync_manager_observer.h"
6
7 #include <cstddef>
8
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"
19
20 namespace syncer {
21
22 JsSyncManagerObserver::JsSyncManagerObserver() {}
23
24 JsSyncManagerObserver::~JsSyncManagerObserver() {}
25
26 void JsSyncManagerObserver::SetJsEventHandler(
27 const WeakHandle<JsEventHandler>& event_handler) {
28 event_handler_ = event_handler;
29 }
30
31 void JsSyncManagerObserver::OnSyncCycleCompleted(
32 const sessions::SyncSessionSnapshot& snapshot) {
33 if (!event_handler_.IsInitialized()) {
34 return;
35 }
36 base::DictionaryValue details;
37 details.Set("snapshot", snapshot.ToValue());
38 HandleJsEvent(FROM_HERE, "onSyncCycleCompleted", JsEventDetails(&details));
39 }
40
41 void JsSyncManagerObserver::OnConnectionStatusChange(ConnectionStatus status) {
42 if (!event_handler_.IsInitialized()) {
43 return;
44 }
45 base::DictionaryValue details;
46 details.SetString("status", ConnectionStatusToString(status));
47 HandleJsEvent(FROM_HERE,
48 "onConnectionStatusChange", JsEventDetails(&details));
49 }
50
51 void JsSyncManagerObserver::OnActionableError(
52 const SyncProtocolError& sync_error) {
53 if (!event_handler_.IsInitialized()) {
54 return;
55 }
56 base::DictionaryValue details;
57 details.Set("syncError", sync_error.ToValue());
58 HandleJsEvent(FROM_HERE, "onActionableError",
59 JsEventDetails(&details));
60 }
61
62 void JsSyncManagerObserver::OnProtocolEvent(
63 const ProtocolEvent& event) { }
64
65 void JsSyncManagerObserver::OnMigrationRequested(ModelTypeSet types) { }
66
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;
73 }
74 // Ignore the |js_backend| argument; it's not really convertible to
75 // JSON anyway.
76
77 base::DictionaryValue details;
78 details.Set("restoredTypes", ModelTypeSetToValue(restored_types));
79
80 HandleJsEvent(FROM_HERE,
81 "onInitializationComplete",
82 JsEventDetails(&details));
83 }
84
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;
91 }
92 event_handler_.Call(from_here,
93 &JsEventHandler::HandleJsEvent, name, details);
94 }
95
96 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/js_sync_manager_observer.h ('k') | sync/internal_api/js_sync_manager_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698