| 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 <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" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 ProfileSyncService* service = GetProfileSyncService(); | 34 ProfileSyncService* service = GetProfileSyncService(); |
| 35 if (service && service->HasObserver(this)) { | 35 if (service && service->HasObserver(this)) { |
| 36 service->RemoveObserver(this); | 36 service->RemoveObserver(this); |
| 37 service->RemoveProtocolEventObserver(this); | 37 service->RemoveProtocolEventObserver(this); |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 void SyncInternalsMessageHandler::RegisterMessages() { | 41 void SyncInternalsMessageHandler::RegisterMessages() { |
| 42 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 42 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 43 | 43 |
| 44 // Register for ProfileSyncService events. | 44 web_ui()->RegisterMessageCallback( |
| 45 ProfileSyncService* service = GetProfileSyncService(); | 45 "registerForEvents", |
| 46 if (service) { | 46 base::Bind(&SyncInternalsMessageHandler::HandleRegisterForEvents, |
| 47 service->AddObserver(this); | 47 base::Unretained(this))); |
| 48 service->AddProtocolEventObserver(this); | |
| 49 js_controller_ = service->GetJsController(); | |
| 50 js_controller_->AddJsEventHandler(this); | |
| 51 } | |
| 52 | 48 |
| 53 web_ui()->RegisterMessageCallback( | 49 web_ui()->RegisterMessageCallback( |
| 54 "requestUpdatedAboutInfo", | 50 "requestUpdatedAboutInfo", |
| 55 base::Bind(&SyncInternalsMessageHandler::HandleRequestUpdatedAboutInfo, | 51 base::Bind(&SyncInternalsMessageHandler::HandleRequestUpdatedAboutInfo, |
| 56 base::Unretained(this))); | 52 base::Unretained(this))); |
| 57 | 53 |
| 58 web_ui()->RegisterMessageCallback( | 54 web_ui()->RegisterMessageCallback( |
| 59 "requestListOfTypes", | 55 "requestListOfTypes", |
| 60 base::Bind(&SyncInternalsMessageHandler::HandleRequestListOfTypes, | 56 base::Bind(&SyncInternalsMessageHandler::HandleRequestListOfTypes, |
| 61 base::Unretained(this))); | 57 base::Unretained(this))); |
| 62 | 58 |
| 63 RegisterJsControllerCallback("getAllNodes"); | 59 RegisterJsControllerCallback("getAllNodes"); |
| 64 RegisterJsControllerCallback("getClientServerTraffic"); | 60 RegisterJsControllerCallback("getClientServerTraffic"); |
| 65 } | 61 } |
| 66 | 62 |
| 63 void SyncInternalsMessageHandler::HandleRegisterForEvents( |
| 64 const base::ListValue* args) { |
| 65 DCHECK(args->empty()); |
| 66 |
| 67 ProfileSyncService* service = GetProfileSyncService(); |
| 68 if (service) { |
| 69 service->AddObserver(this); |
| 70 service->AddProtocolEventObserver(this); |
| 71 js_controller_ = service->GetJsController(); |
| 72 js_controller_->AddJsEventHandler(this); |
| 73 } |
| 74 } |
| 75 |
| 67 void SyncInternalsMessageHandler::HandleRequestUpdatedAboutInfo( | 76 void SyncInternalsMessageHandler::HandleRequestUpdatedAboutInfo( |
| 68 const base::ListValue* args) { | 77 const base::ListValue* args) { |
| 69 DCHECK(args->empty()); | 78 DCHECK(args->empty()); |
| 70 SendAboutInfo(); | 79 SendAboutInfo(); |
| 71 } | 80 } |
| 72 | 81 |
| 73 void SyncInternalsMessageHandler::HandleRequestListOfTypes( | 82 void SyncInternalsMessageHandler::HandleRequestListOfTypes( |
| 74 const base::ListValue* args) { | 83 const base::ListValue* args) { |
| 75 DCHECK(args->empty()); | 84 DCHECK(args->empty()); |
| 76 base::DictionaryValue event_details; | 85 base::DictionaryValue event_details; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 } | 163 } |
| 155 | 164 |
| 156 // Gets the ProfileSyncService of the underlying original profile. | 165 // Gets the ProfileSyncService of the underlying original profile. |
| 157 // May return NULL (e.g., if sync is disabled on the command line). | 166 // May return NULL (e.g., if sync is disabled on the command line). |
| 158 ProfileSyncService* SyncInternalsMessageHandler::GetProfileSyncService() { | 167 ProfileSyncService* SyncInternalsMessageHandler::GetProfileSyncService() { |
| 159 Profile* profile = Profile::FromWebUI(web_ui()); | 168 Profile* profile = Profile::FromWebUI(web_ui()); |
| 160 ProfileSyncServiceFactory* factory = ProfileSyncServiceFactory::GetInstance(); | 169 ProfileSyncServiceFactory* factory = ProfileSyncServiceFactory::GetInstance(); |
| 161 return factory->GetForProfile(profile->GetOriginalProfile()); | 170 return factory->GetForProfile(profile->GetOriginalProfile()); |
| 162 } | 171 } |
| 163 | 172 |
| OLD | NEW |