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

Side by Side Diff: chrome/browser/ui/webui/sync_internals_message_handler.cc

Issue 1334173006: Move sync_internals resources and constants to //components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gcmInternals
Patch Set: Update resource_ids Created 5 years, 3 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
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 <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/sync/profile_sync_service.h" 11 #include "chrome/browser/sync/profile_sync_service.h"
12 #include "chrome/browser/sync/profile_sync_service_factory.h" 12 #include "chrome/browser/sync/profile_sync_service_factory.h"
13 #include "chrome/common/channel_info.h" 13 #include "chrome/common/channel_info.h"
14 #include "components/sync_driver/about_sync_util.h" 14 #include "components/sync_driver/about_sync_util.h"
15 #include "components/sync_driver/about_sync_util.h"
15 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/web_ui.h" 17 #include "content/public/browser/web_ui.h"
17 #include "sync/internal_api/public/events/protocol_event.h" 18 #include "sync/internal_api/public/events/protocol_event.h"
18 #include "sync/internal_api/public/sessions/commit_counters.h" 19 #include "sync/internal_api/public/sessions/commit_counters.h"
19 #include "sync/internal_api/public/sessions/status_counters.h" 20 #include "sync/internal_api/public/sessions/status_counters.h"
20 #include "sync/internal_api/public/sessions/update_counters.h" 21 #include "sync/internal_api/public/sessions/update_counters.h"
21 #include "sync/internal_api/public/util/weak_handle.h" 22 #include "sync/internal_api/public/util/weak_handle.h"
22 #include "sync/js/js_event_details.h" 23 #include "sync/js/js_event_details.h"
23 24
24 using syncer::JsEventDetails; 25 using syncer::JsEventDetails;
(...skipping 18 matching lines...) Expand all
43 44
44 if (service && is_registered_for_counters_) { 45 if (service && is_registered_for_counters_) {
45 service->RemoveTypeDebugInfoObserver(this); 46 service->RemoveTypeDebugInfoObserver(this);
46 } 47 }
47 } 48 }
48 49
49 void SyncInternalsMessageHandler::RegisterMessages() { 50 void SyncInternalsMessageHandler::RegisterMessages() {
50 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 51 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
51 52
52 web_ui()->RegisterMessageCallback( 53 web_ui()->RegisterMessageCallback(
53 "registerForEvents", 54 sync_driver::kRegisterForEvents,
54 base::Bind(&SyncInternalsMessageHandler::HandleRegisterForEvents, 55 base::Bind(&SyncInternalsMessageHandler::HandleRegisterForEvents,
55 base::Unretained(this))); 56 base::Unretained(this)));
56 57
57 web_ui()->RegisterMessageCallback( 58 web_ui()->RegisterMessageCallback(
58 "registerForPerTypeCounters", 59 sync_driver::kRegisterForPerTypeCounters,
59 base::Bind(&SyncInternalsMessageHandler::HandleRegisterForPerTypeCounters, 60 base::Bind(&SyncInternalsMessageHandler::HandleRegisterForPerTypeCounters,
60 base::Unretained(this))); 61 base::Unretained(this)));
61 62
62 web_ui()->RegisterMessageCallback( 63 web_ui()->RegisterMessageCallback(
63 "requestUpdatedAboutInfo", 64 sync_driver::kRequestUpdatedAboutInfo,
64 base::Bind(&SyncInternalsMessageHandler::HandleRequestUpdatedAboutInfo, 65 base::Bind(&SyncInternalsMessageHandler::HandleRequestUpdatedAboutInfo,
65 base::Unretained(this))); 66 base::Unretained(this)));
66 67
67 web_ui()->RegisterMessageCallback( 68 web_ui()->RegisterMessageCallback(
68 "requestListOfTypes", 69 sync_driver::kRequestListOfTypes,
69 base::Bind(&SyncInternalsMessageHandler::HandleRequestListOfTypes, 70 base::Bind(&SyncInternalsMessageHandler::HandleRequestListOfTypes,
70 base::Unretained(this))); 71 base::Unretained(this)));
71 72
72 web_ui()->RegisterMessageCallback( 73 web_ui()->RegisterMessageCallback(
73 "getAllNodes", 74 sync_driver::kGetAllNodes,
74 base::Bind(&SyncInternalsMessageHandler::HandleGetAllNodes, 75 base::Bind(&SyncInternalsMessageHandler::HandleGetAllNodes,
75 base::Unretained(this))); 76 base::Unretained(this)));
76 } 77 }
77 78
78 void SyncInternalsMessageHandler::HandleRegisterForEvents( 79 void SyncInternalsMessageHandler::HandleRegisterForEvents(
79 const base::ListValue* args) { 80 const base::ListValue* args) {
80 DCHECK(args->empty()); 81 DCHECK(args->empty());
81 82
82 // is_registered_ flag protects us from double-registering. This could 83 // is_registered_ flag protects us from double-registering. This could
83 // happen on a page refresh, where the JavaScript gets re-run but the 84 // happen on a page refresh, where the JavaScript gets re-run but the
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 void SyncInternalsMessageHandler::HandleRequestListOfTypes( 118 void SyncInternalsMessageHandler::HandleRequestListOfTypes(
118 const base::ListValue* args) { 119 const base::ListValue* args) {
119 DCHECK(args->empty()); 120 DCHECK(args->empty());
120 base::DictionaryValue event_details; 121 base::DictionaryValue event_details;
121 scoped_ptr<base::ListValue> type_list(new base::ListValue()); 122 scoped_ptr<base::ListValue> type_list(new base::ListValue());
122 ModelTypeSet protocol_types = syncer::ProtocolTypes(); 123 ModelTypeSet protocol_types = syncer::ProtocolTypes();
123 for (ModelTypeSet::Iterator it = protocol_types.First(); 124 for (ModelTypeSet::Iterator it = protocol_types.First();
124 it.Good(); it.Inc()) { 125 it.Good(); it.Inc()) {
125 type_list->Append(new base::StringValue(ModelTypeToString(it.Get()))); 126 type_list->Append(new base::StringValue(ModelTypeToString(it.Get())));
126 } 127 }
127 event_details.Set("types", type_list.release()); 128 event_details.Set(sync_driver::kTypes, type_list.release());
128 web_ui()->CallJavascriptFunction( 129 web_ui()->CallJavascriptFunction(
129 "chrome.sync.dispatchEvent", 130 sync_driver::kDispatchEvent,
130 base::StringValue("onReceivedListOfTypes"), 131 base::StringValue(sync_driver::kOnReceivedListOfTypes), event_details);
131 event_details);
132 } 132 }
133 133
134 void SyncInternalsMessageHandler::HandleGetAllNodes( 134 void SyncInternalsMessageHandler::HandleGetAllNodes(
135 const base::ListValue* args) { 135 const base::ListValue* args) {
136 DCHECK_EQ(1U, args->GetSize()); 136 DCHECK_EQ(1U, args->GetSize());
137 int request_id = 0; 137 int request_id = 0;
138 bool success = args->GetInteger(0, &request_id); 138 bool success = args->GetInteger(0, &request_id);
139 DCHECK(success); 139 DCHECK(success);
140 140
141 ProfileSyncService* service = GetProfileSyncService(); 141 ProfileSyncService* service = GetProfileSyncService();
142 if (service) { 142 if (service) {
143 service->GetAllNodes( 143 service->GetAllNodes(
144 base::Bind(&SyncInternalsMessageHandler::OnReceivedAllNodes, 144 base::Bind(&SyncInternalsMessageHandler::OnReceivedAllNodes,
145 weak_ptr_factory_.GetWeakPtr(), request_id)); 145 weak_ptr_factory_.GetWeakPtr(), request_id));
146 } 146 }
147 } 147 }
148 148
149 void SyncInternalsMessageHandler::OnReceivedAllNodes( 149 void SyncInternalsMessageHandler::OnReceivedAllNodes(
150 int request_id, 150 int request_id,
151 scoped_ptr<base::ListValue> nodes) { 151 scoped_ptr<base::ListValue> nodes) {
152 base::FundamentalValue id(request_id); 152 base::FundamentalValue id(request_id);
153 web_ui()->CallJavascriptFunction("chrome.sync.getAllNodesCallback", 153 web_ui()->CallJavascriptFunction(sync_driver::kGetAllNodesCallback, id,
154 id, *nodes); 154 *nodes);
155 } 155 }
156 156
157 void SyncInternalsMessageHandler::OnStateChanged() { 157 void SyncInternalsMessageHandler::OnStateChanged() {
158 SendAboutInfo(); 158 SendAboutInfo();
159 } 159 }
160 160
161 void SyncInternalsMessageHandler::OnProtocolEvent( 161 void SyncInternalsMessageHandler::OnProtocolEvent(
162 const syncer::ProtocolEvent& event) { 162 const syncer::ProtocolEvent& event) {
163 scoped_ptr<base::DictionaryValue> value( 163 scoped_ptr<base::DictionaryValue> value(
164 syncer::ProtocolEvent::ToValue(event)); 164 syncer::ProtocolEvent::ToValue(event));
165 web_ui()->CallJavascriptFunction( 165 web_ui()->CallJavascriptFunction(
166 "chrome.sync.dispatchEvent", 166 sync_driver::kDispatchEvent,
167 base::StringValue("onProtocolEvent"), 167 base::StringValue(sync_driver::kOnProtocolEvent), *value);
168 *value);
169 } 168 }
170 169
171 void SyncInternalsMessageHandler::OnCommitCountersUpdated( 170 void SyncInternalsMessageHandler::OnCommitCountersUpdated(
172 syncer::ModelType type, 171 syncer::ModelType type,
173 const syncer::CommitCounters& counters) { 172 const syncer::CommitCounters& counters) {
174 EmitCounterUpdate(type, "commit", counters.ToValue()); 173 EmitCounterUpdate(type, sync_driver::kCommit, counters.ToValue());
175 } 174 }
176 175
177 void SyncInternalsMessageHandler::OnUpdateCountersUpdated( 176 void SyncInternalsMessageHandler::OnUpdateCountersUpdated(
178 syncer::ModelType type, 177 syncer::ModelType type,
179 const syncer::UpdateCounters& counters) { 178 const syncer::UpdateCounters& counters) {
180 EmitCounterUpdate(type, "update", counters.ToValue()); 179 EmitCounterUpdate(type, sync_driver::kUpdate, counters.ToValue());
181 } 180 }
182 181
183 void SyncInternalsMessageHandler::OnStatusCountersUpdated( 182 void SyncInternalsMessageHandler::OnStatusCountersUpdated(
184 syncer::ModelType type, 183 syncer::ModelType type,
185 const syncer::StatusCounters& counters) { 184 const syncer::StatusCounters& counters) {
186 EmitCounterUpdate(type, "status", counters.ToValue()); 185 EmitCounterUpdate(type, sync_driver::kStatus, counters.ToValue());
187 } 186 }
188 187
189 void SyncInternalsMessageHandler::EmitCounterUpdate( 188 void SyncInternalsMessageHandler::EmitCounterUpdate(
190 syncer::ModelType type, 189 syncer::ModelType type,
191 const std::string& counter_type, 190 const std::string& counter_type,
192 scoped_ptr<base::DictionaryValue> value) { 191 scoped_ptr<base::DictionaryValue> value) {
193 scoped_ptr<base::DictionaryValue> details(new base::DictionaryValue()); 192 scoped_ptr<base::DictionaryValue> details(new base::DictionaryValue());
194 details->SetString("modelType", ModelTypeToString(type)); 193 details->SetString(sync_driver::kModelType, ModelTypeToString(type));
195 details->SetString("counterType", counter_type); 194 details->SetString(sync_driver::kCounterType, counter_type);
196 details->Set("counters", value.release()); 195 details->Set(sync_driver::kCounters, value.release());
197 web_ui()->CallJavascriptFunction("chrome.sync.dispatchEvent", 196 web_ui()->CallJavascriptFunction(
198 base::StringValue("onCountersUpdated"), 197 sync_driver::kDispatchEvent,
199 *details); 198 base::StringValue(sync_driver::kOnCountersUpdated), *details);
200 } 199 }
201 200
202 void SyncInternalsMessageHandler::HandleJsEvent( 201 void SyncInternalsMessageHandler::HandleJsEvent(
203 const std::string& name, 202 const std::string& name,
204 const JsEventDetails& details) { 203 const JsEventDetails& details) {
205 DVLOG(1) << "Handling event: " << name 204 DVLOG(1) << "Handling event: " << name
206 << " with details " << details.ToString(); 205 << " with details " << details.ToString();
207 web_ui()->CallJavascriptFunction("chrome.sync.dispatchEvent", 206 web_ui()->CallJavascriptFunction(sync_driver::kDispatchEvent,
208 base::StringValue(name), 207 base::StringValue(name), details.Get());
209 details.Get());
210 } 208 }
211 209
212 void SyncInternalsMessageHandler::SendAboutInfo() { 210 void SyncInternalsMessageHandler::SendAboutInfo() {
213 ProfileSyncService* sync_service = GetProfileSyncService(); 211 ProfileSyncService* sync_service = GetProfileSyncService();
214 scoped_ptr<base::DictionaryValue> value = 212 scoped_ptr<base::DictionaryValue> value =
215 sync_ui_util::ConstructAboutInformation(sync_service, 213 sync_driver::ConstructAboutInformation(
216 sync_service->signin(), 214 sync_service, sync_service->signin(), chrome::GetChannel());
217 chrome::GetChannel());
218 web_ui()->CallJavascriptFunction( 215 web_ui()->CallJavascriptFunction(
219 "chrome.sync.dispatchEvent", 216 sync_driver::kDispatchEvent,
220 base::StringValue("onAboutInfoUpdated"), 217 base::StringValue(sync_driver::kOnAboutInfoUpdated), *value);
221 *value);
222 } 218 }
223 219
224 // Gets the ProfileSyncService of the underlying original profile. 220 // Gets the ProfileSyncService of the underlying original profile.
225 // May return NULL (e.g., if sync is disabled on the command line). 221 // May return NULL (e.g., if sync is disabled on the command line).
226 ProfileSyncService* SyncInternalsMessageHandler::GetProfileSyncService() { 222 ProfileSyncService* SyncInternalsMessageHandler::GetProfileSyncService() {
227 Profile* profile = Profile::FromWebUI(web_ui()); 223 Profile* profile = Profile::FromWebUI(web_ui());
228 return ProfileSyncServiceFactory::GetForProfile( 224 return ProfileSyncServiceFactory::GetForProfile(
229 profile->GetOriginalProfile()); 225 profile->GetOriginalProfile());
230 } 226 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698