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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 syncer::sync_ui_util::kRequestUpdatedAboutInfo, | 101 syncer::sync_ui_util::kRequestUpdatedAboutInfo, |
81 base::Bind(&SyncInternalsMessageHandler::HandleRequestUpdatedAboutInfo, | 102 base::Bind(&SyncInternalsMessageHandler::HandleRequestUpdatedAboutInfo, |
82 base::Unretained(this))); | 103 base::Unretained(this))); |
83 | 104 |
84 web_ui()->RegisterMessageCallback( | 105 web_ui()->RegisterMessageCallback( |
85 syncer::sync_ui_util::kRequestListOfTypes, | 106 syncer::sync_ui_util::kRequestListOfTypes, |
86 base::Bind(&SyncInternalsMessageHandler::HandleRequestListOfTypes, | 107 base::Bind(&SyncInternalsMessageHandler::HandleRequestListOfTypes, |
87 base::Unretained(this))); | 108 base::Unretained(this))); |
88 | 109 |
89 web_ui()->RegisterMessageCallback( | 110 web_ui()->RegisterMessageCallback( |
| 111 syncer::sync_ui_util::kRequestUserEventsVisibility, |
| 112 base::Bind( |
| 113 &SyncInternalsMessageHandler::HandleRequestUserEventsVisibility, |
| 114 base::Unretained(this))); |
| 115 |
| 116 web_ui()->RegisterMessageCallback( |
| 117 syncer::sync_ui_util::kWriteUserEvent, |
| 118 base::Bind(&SyncInternalsMessageHandler::HandleWriteUserEvent, |
| 119 base::Unretained(this))); |
| 120 |
| 121 web_ui()->RegisterMessageCallback( |
90 syncer::sync_ui_util::kGetAllNodes, | 122 syncer::sync_ui_util::kGetAllNodes, |
91 base::Bind(&SyncInternalsMessageHandler::HandleGetAllNodes, | 123 base::Bind(&SyncInternalsMessageHandler::HandleGetAllNodes, |
92 base::Unretained(this))); | 124 base::Unretained(this))); |
93 } | 125 } |
94 | 126 |
95 void SyncInternalsMessageHandler::HandleRegisterForEvents( | 127 void SyncInternalsMessageHandler::HandleRegisterForEvents( |
96 const ListValue* args) { | 128 const ListValue* args) { |
97 DCHECK(args->empty()); | 129 DCHECK(args->empty()); |
98 AllowJavascript(); | 130 AllowJavascript(); |
99 | 131 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 // This opens up the possibility of non-javascript code calling us | 197 // This opens up the possibility of non-javascript code calling us |
166 // asynchronously, and potentially at times we're not allowed to call into | 198 // asynchronously, and potentially at times we're not allowed to call into |
167 // the javascript side. We guard against this by invalidating this weak ptr | 199 // the javascript side. We guard against this by invalidating this weak ptr |
168 // should javascript become disallowed. | 200 // should javascript become disallowed. |
169 service->GetAllNodes( | 201 service->GetAllNodes( |
170 base::Bind(&SyncInternalsMessageHandler::OnReceivedAllNodes, | 202 base::Bind(&SyncInternalsMessageHandler::OnReceivedAllNodes, |
171 weak_ptr_factory_.GetWeakPtr(), request_id)); | 203 weak_ptr_factory_.GetWeakPtr(), request_id)); |
172 } | 204 } |
173 } | 205 } |
174 | 206 |
| 207 void SyncInternalsMessageHandler::HandleRequestUserEventsVisibility( |
| 208 const base::ListValue* args) { |
| 209 DCHECK(args->empty()); |
| 210 AllowJavascript(); |
| 211 CallJavascriptFunction( |
| 212 syncer::sync_ui_util::kUserEventsVisibilityCallback, |
| 213 Value(base::FeatureList::IsEnabled(switches::kSyncUserEvents))); |
| 214 } |
| 215 |
| 216 void SyncInternalsMessageHandler::HandleWriteUserEvent( |
| 217 const base::ListValue* args) { |
| 218 DCHECK_EQ(2U, args->GetSize()); |
| 219 AllowJavascript(); |
| 220 |
| 221 Profile* profile = Profile::FromWebUI(web_ui()); |
| 222 syncer::UserEventService* user_event_service = |
| 223 browser_sync::UserEventServiceFactory::GetForProfile( |
| 224 profile->GetOriginalProfile()); |
| 225 |
| 226 sync_pb::UserEventSpecifics event_specifics; |
| 227 event_specifics.set_event_time_usec(StringAtIndexToInt64(args, 0)); |
| 228 event_specifics.set_navigation_id(StringAtIndexToInt64(args, 1)); |
| 229 user_event_service->RecordUserEvent(event_specifics); |
| 230 } |
| 231 |
175 void SyncInternalsMessageHandler::OnReceivedAllNodes( | 232 void SyncInternalsMessageHandler::OnReceivedAllNodes( |
176 int request_id, | 233 int request_id, |
177 std::unique_ptr<ListValue> nodes) { | 234 std::unique_ptr<ListValue> nodes) { |
178 CallJavascriptFunction(syncer::sync_ui_util::kGetAllNodesCallback, | 235 CallJavascriptFunction(syncer::sync_ui_util::kGetAllNodesCallback, |
179 Value(request_id), *nodes); | 236 Value(request_id), *nodes); |
180 } | 237 } |
181 | 238 |
182 void SyncInternalsMessageHandler::OnStateChanged(SyncService* sync) { | 239 void SyncInternalsMessageHandler::OnStateChanged(SyncService* sync) { |
183 SendAboutInfo(); | 240 SendAboutInfo(); |
184 } | 241 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 js_controller_->RemoveJsEventHandler(this); | 314 js_controller_->RemoveJsEventHandler(this); |
258 js_controller_ = nullptr; | 315 js_controller_ = nullptr; |
259 is_registered_ = false; | 316 is_registered_ = false; |
260 } | 317 } |
261 | 318 |
262 if (is_registered_for_counters_) { | 319 if (is_registered_for_counters_) { |
263 service->RemoveTypeDebugInfoObserver(this); | 320 service->RemoveTypeDebugInfoObserver(this); |
264 is_registered_for_counters_ = false; | 321 is_registered_for_counters_ = false; |
265 } | 322 } |
266 } | 323 } |
OLD | NEW |