OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/sync_internals_message_handler.h" | 5 #include "chrome/browser/ui/webui/sync_internals_message_handler.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
| 12 #include "base/feature_list.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/strings/string_number_conversions.h" |
14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/sync/profile_sync_service_factory.h" | 17 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 18 #include "chrome/browser/sync/user_event_service_factory.h" |
16 #include "chrome/common/channel_info.h" | 19 #include "chrome/common/channel_info.h" |
17 #include "components/browser_sync/profile_sync_service.h" | 20 #include "components/browser_sync/profile_sync_service.h" |
18 #include "components/sync/base/weak_handle.h" | 21 #include "components/sync/base/weak_handle.h" |
19 #include "components/sync/driver/about_sync_util.h" | 22 #include "components/sync/driver/about_sync_util.h" |
| 23 #include "components/sync/driver/sync_driver_switches.h" |
20 #include "components/sync/driver/sync_service.h" | 24 #include "components/sync/driver/sync_service.h" |
21 #include "components/sync/engine/cycle/commit_counters.h" | 25 #include "components/sync/engine/cycle/commit_counters.h" |
22 #include "components/sync/engine/cycle/status_counters.h" | 26 #include "components/sync/engine/cycle/status_counters.h" |
23 #include "components/sync/engine/cycle/update_counters.h" | 27 #include "components/sync/engine/cycle/update_counters.h" |
24 #include "components/sync/engine/events/protocol_event.h" | 28 #include "components/sync/engine/events/protocol_event.h" |
25 #include "components/sync/js/js_event_details.h" | 29 #include "components/sync/js/js_event_details.h" |
| 30 #include "components/sync/protocol/sync.pb.h" |
| 31 #include "components/sync/user_events/user_event_service.h" |
26 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/web_ui.h" | 33 #include "content/public/browser/web_ui.h" |
28 | 34 |
29 using base::DictionaryValue; | 35 using base::DictionaryValue; |
30 using base::ListValue; | 36 using base::ListValue; |
31 using base::Value; | 37 using base::Value; |
32 using browser_sync::ProfileSyncService; | 38 using browser_sync::ProfileSyncService; |
33 using syncer::JsEventDetails; | 39 using syncer::JsEventDetails; |
34 using syncer::ModelTypeSet; | 40 using syncer::ModelTypeSet; |
35 using syncer::SyncService; | 41 using syncer::SyncService; |
36 using syncer::WeakHandle; | 42 using syncer::WeakHandle; |
37 | 43 |
| 44 namespace { |
| 45 |
| 46 // Converts the string at |index| in |list| to an int, defaulting to 0 on error. |
| 47 int64_t StringAtIndexToInt64(const base::ListValue* list, int index) { |
| 48 std::string str; |
| 49 if (list->GetString(index, &str)) { |
| 50 int64_t integer = 0; |
| 51 if (base::StringToInt64(str, &integer)) |
| 52 return integer; |
| 53 } |
| 54 return 0; |
| 55 } |
| 56 |
| 57 } // namespace |
| 58 |
38 SyncInternalsMessageHandler::SyncInternalsMessageHandler() | 59 SyncInternalsMessageHandler::SyncInternalsMessageHandler() |
39 : SyncInternalsMessageHandler( | 60 : SyncInternalsMessageHandler( |
40 base::BindRepeating( | 61 base::BindRepeating( |
41 &SyncInternalsMessageHandler::BindForSyncServiceProvider, | 62 &SyncInternalsMessageHandler::BindForSyncServiceProvider, |
42 base::Unretained(this)), | 63 base::Unretained(this)), |
43 base::BindRepeating( | 64 base::BindRepeating( |
44 &syncer::sync_ui_util::ConstructAboutInformation)) {} | 65 &syncer::sync_ui_util::ConstructAboutInformation)) {} |
45 | 66 |
46 SyncInternalsMessageHandler::SyncInternalsMessageHandler( | 67 SyncInternalsMessageHandler::SyncInternalsMessageHandler( |
47 SyncServiceProvider sync_service_provider, | 68 SyncServiceProvider sync_service_provider, |
(...skipping 27 matching lines...) Expand all Loading... |
75 syncer::sync_ui_util::kRequestUpdatedAboutInfo, | 96 syncer::sync_ui_util::kRequestUpdatedAboutInfo, |
76 base::Bind(&SyncInternalsMessageHandler::HandleRequestUpdatedAboutInfo, | 97 base::Bind(&SyncInternalsMessageHandler::HandleRequestUpdatedAboutInfo, |
77 base::Unretained(this))); | 98 base::Unretained(this))); |
78 | 99 |
79 web_ui()->RegisterMessageCallback( | 100 web_ui()->RegisterMessageCallback( |
80 syncer::sync_ui_util::kRequestListOfTypes, | 101 syncer::sync_ui_util::kRequestListOfTypes, |
81 base::Bind(&SyncInternalsMessageHandler::HandleRequestListOfTypes, | 102 base::Bind(&SyncInternalsMessageHandler::HandleRequestListOfTypes, |
82 base::Unretained(this))); | 103 base::Unretained(this))); |
83 | 104 |
84 web_ui()->RegisterMessageCallback( | 105 web_ui()->RegisterMessageCallback( |
| 106 syncer::sync_ui_util::kRequestUserEventsVisibility, |
| 107 base::Bind( |
| 108 &SyncInternalsMessageHandler::HandleRequestUserEventsVisibility, |
| 109 base::Unretained(this))); |
| 110 |
| 111 web_ui()->RegisterMessageCallback( |
| 112 syncer::sync_ui_util::kWriteUserEvent, |
| 113 base::Bind(&SyncInternalsMessageHandler::HandleWriteUserEvent, |
| 114 base::Unretained(this))); |
| 115 |
| 116 web_ui()->RegisterMessageCallback( |
85 syncer::sync_ui_util::kGetAllNodes, | 117 syncer::sync_ui_util::kGetAllNodes, |
86 base::Bind(&SyncInternalsMessageHandler::HandleGetAllNodes, | 118 base::Bind(&SyncInternalsMessageHandler::HandleGetAllNodes, |
87 base::Unretained(this))); | 119 base::Unretained(this))); |
88 } | 120 } |
89 | 121 |
90 void SyncInternalsMessageHandler::HandleRegisterForEvents( | 122 void SyncInternalsMessageHandler::HandleRegisterForEvents( |
91 const ListValue* args) { | 123 const ListValue* args) { |
92 DCHECK(args->empty()); | 124 DCHECK(args->empty()); |
93 AllowJavascript(); | 125 AllowJavascript(); |
94 | 126 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 DCHECK(success); | 185 DCHECK(success); |
154 | 186 |
155 SyncService* service = sync_service_provider_.Run(); | 187 SyncService* service = sync_service_provider_.Run(); |
156 if (service) { | 188 if (service) { |
157 service->GetAllNodes( | 189 service->GetAllNodes( |
158 base::Bind(&SyncInternalsMessageHandler::OnReceivedAllNodes, | 190 base::Bind(&SyncInternalsMessageHandler::OnReceivedAllNodes, |
159 weak_ptr_factory_.GetWeakPtr(), request_id)); | 191 weak_ptr_factory_.GetWeakPtr(), request_id)); |
160 } | 192 } |
161 } | 193 } |
162 | 194 |
| 195 void SyncInternalsMessageHandler::HandleRequestUserEventsVisibility( |
| 196 const base::ListValue* args) { |
| 197 DCHECK(args->empty()); |
| 198 AllowJavascript(); |
| 199 CallJavascriptFunction( |
| 200 syncer::sync_ui_util::kUserEventsVisibilityCallback, |
| 201 Value(base::FeatureList::IsEnabled(switches::kSyncUserEvents))); |
| 202 } |
| 203 |
| 204 void SyncInternalsMessageHandler::HandleWriteUserEvent( |
| 205 const base::ListValue* args) { |
| 206 DCHECK_EQ(2U, args->GetSize()); |
| 207 AllowJavascript(); |
| 208 |
| 209 Profile* profile = Profile::FromWebUI(web_ui()); |
| 210 syncer::UserEventService* user_event_service = |
| 211 browser_sync::UserEventServiceFactory::GetForProfile( |
| 212 profile->GetOriginalProfile()); |
| 213 |
| 214 sync_pb::UserEventSpecifics event_specifics; |
| 215 event_specifics.set_event_time_usec(StringAtIndexToInt64(args, 0)); |
| 216 event_specifics.set_navigation_id(StringAtIndexToInt64(args, 1)); |
| 217 user_event_service->RecordUserEvent(event_specifics); |
| 218 } |
| 219 |
163 void SyncInternalsMessageHandler::OnReceivedAllNodes( | 220 void SyncInternalsMessageHandler::OnReceivedAllNodes( |
164 int request_id, | 221 int request_id, |
165 std::unique_ptr<ListValue> nodes) { | 222 std::unique_ptr<ListValue> nodes) { |
166 // This is a callback that's invoked asyncrhonously. However, it's possible | 223 // This is a callback that's invoked asyncrhonously. However, it's possible |
167 // that our UI is no longer allowing javascript, and we need to manually check | 224 // that our UI is no longer allowing javascript, and we need to manually check |
168 // before proceeding. | 225 // before proceeding. |
169 if (IsJavascriptAllowed()) { | 226 if (IsJavascriptAllowed()) { |
170 CallJavascriptFunction(syncer::sync_ui_util::kGetAllNodesCallback, | 227 CallJavascriptFunction(syncer::sync_ui_util::kGetAllNodesCallback, |
171 Value(request_id), *nodes); | 228 Value(request_id), *nodes); |
172 } | 229 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 js_controller_ = nullptr; | 308 js_controller_ = nullptr; |
252 is_registered_ = false; | 309 is_registered_ = false; |
253 } | 310 } |
254 | 311 |
255 if (is_registered_for_counters_) { | 312 if (is_registered_for_counters_) { |
256 DCHECK(service); | 313 DCHECK(service); |
257 service->RemoveTypeDebugInfoObserver(this); | 314 service->RemoveTypeDebugInfoObserver(this); |
258 is_registered_for_counters_ = false; | 315 is_registered_for_counters_ = false; |
259 } | 316 } |
260 } | 317 } |
OLD | NEW |