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

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

Issue 210233005: sync: Display protocol events on about:sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nit + unrelated bug Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/sync_internals_message_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/about_sync_util.h" 11 #include "chrome/browser/sync/about_sync_util.h"
12 #include "chrome/browser/sync/profile_sync_service.h" 12 #include "chrome/browser/sync/profile_sync_service.h"
13 #include "chrome/browser/sync/profile_sync_service_factory.h" 13 #include "chrome/browser/sync/profile_sync_service_factory.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/web_ui.h" 15 #include "content/public/browser/web_ui.h"
16 #include "sync/internal_api/public/events/protocol_event.h"
16 #include "sync/internal_api/public/util/weak_handle.h" 17 #include "sync/internal_api/public/util/weak_handle.h"
17 #include "sync/js/js_arg_list.h" 18 #include "sync/js/js_arg_list.h"
18 #include "sync/js/js_event_details.h" 19 #include "sync/js/js_event_details.h"
19 20
20 using syncer::JsArgList; 21 using syncer::JsArgList;
21 using syncer::JsEventDetails; 22 using syncer::JsEventDetails;
22 using syncer::JsReplyHandler; 23 using syncer::JsReplyHandler;
23 using syncer::ModelTypeSet; 24 using syncer::ModelTypeSet;
24 using syncer::WeakHandle; 25 using syncer::WeakHandle;
25 26
26 SyncInternalsMessageHandler::SyncInternalsMessageHandler() 27 SyncInternalsMessageHandler::SyncInternalsMessageHandler()
27 : scoped_observer_(this), 28 : weak_ptr_factory_(this) {}
28 weak_ptr_factory_(this) {}
29 29
30 SyncInternalsMessageHandler::~SyncInternalsMessageHandler() { 30 SyncInternalsMessageHandler::~SyncInternalsMessageHandler() {
31 if (js_controller_) 31 if (js_controller_)
32 js_controller_->RemoveJsEventHandler(this); 32 js_controller_->RemoveJsEventHandler(this);
33
34 ProfileSyncService* service = GetProfileSyncService();
35 if (service && service->HasObserver(this)) {
36 service->RemoveObserver(this);
37 service->RemoveProtocolEventObserver(this);
38 }
33 } 39 }
34 40
35 void SyncInternalsMessageHandler::RegisterMessages() { 41 void SyncInternalsMessageHandler::RegisterMessages() {
36 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 42 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
37 43
38 // Register for ProfileSyncService events. 44 // Register for ProfileSyncService events.
39 ProfileSyncService* service = GetProfileSyncService(); 45 ProfileSyncService* service = GetProfileSyncService();
40 if (service) { 46 if (service) {
41 scoped_observer_.Add(service); 47 service->AddObserver(this);
48 service->AddProtocolEventObserver(this);
42 js_controller_ = service->GetJsController(); 49 js_controller_ = service->GetJsController();
43 js_controller_->AddJsEventHandler(this); 50 js_controller_->AddJsEventHandler(this);
44 } 51 }
45 52
46 web_ui()->RegisterMessageCallback( 53 web_ui()->RegisterMessageCallback(
47 "requestUpdatedAboutInfo", 54 "requestUpdatedAboutInfo",
48 base::Bind(&SyncInternalsMessageHandler::HandleRequestUpdatedAboutInfo, 55 base::Bind(&SyncInternalsMessageHandler::HandleRequestUpdatedAboutInfo,
49 base::Unretained(this))); 56 base::Unretained(this)));
50 57
51 web_ui()->RegisterMessageCallback( 58 web_ui()->RegisterMessageCallback(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 const std::string& reply_handler = "chrome.sync." + name + ".handleReply"; 94 const std::string& reply_handler = "chrome.sync." + name + ".handleReply";
88 std::vector<const base::Value*> arg_list(args.Get().begin(), 95 std::vector<const base::Value*> arg_list(args.Get().begin(),
89 args.Get().end()); 96 args.Get().end());
90 web_ui()->CallJavascriptFunction(reply_handler, arg_list); 97 web_ui()->CallJavascriptFunction(reply_handler, arg_list);
91 } 98 }
92 99
93 void SyncInternalsMessageHandler::OnStateChanged() { 100 void SyncInternalsMessageHandler::OnStateChanged() {
94 SendAboutInfo(); 101 SendAboutInfo();
95 } 102 }
96 103
104 void SyncInternalsMessageHandler::OnProtocolEvent(
105 const syncer::ProtocolEvent& event) {
106 scoped_ptr<base::DictionaryValue> value(
107 syncer::ProtocolEvent::ToValue(event));
108 web_ui()->CallJavascriptFunction(
109 "chrome.sync.dispatchEvent",
110 base::StringValue("onProtocolEvent"),
111 *value);
112 }
113
97 void SyncInternalsMessageHandler::HandleJsEvent( 114 void SyncInternalsMessageHandler::HandleJsEvent(
98 const std::string& name, 115 const std::string& name,
99 const JsEventDetails& details) { 116 const JsEventDetails& details) {
100 DVLOG(1) << "Handling event: " << name 117 DVLOG(1) << "Handling event: " << name
101 << " with details " << details.ToString(); 118 << " with details " << details.ToString();
102 web_ui()->CallJavascriptFunction("chrome.sync.dispatchEvent", 119 web_ui()->CallJavascriptFunction("chrome.sync.dispatchEvent",
103 base::StringValue(name), 120 base::StringValue(name),
104 details.Get()); 121 details.Get());
105 } 122 }
106 123
(...skipping 30 matching lines...) Expand all
137 } 154 }
138 155
139 // Gets the ProfileSyncService of the underlying original profile. 156 // Gets the ProfileSyncService of the underlying original profile.
140 // May return NULL (e.g., if sync is disabled on the command line). 157 // May return NULL (e.g., if sync is disabled on the command line).
141 ProfileSyncService* SyncInternalsMessageHandler::GetProfileSyncService() { 158 ProfileSyncService* SyncInternalsMessageHandler::GetProfileSyncService() {
142 Profile* profile = Profile::FromWebUI(web_ui()); 159 Profile* profile = Profile::FromWebUI(web_ui());
143 ProfileSyncServiceFactory* factory = ProfileSyncServiceFactory::GetInstance(); 160 ProfileSyncServiceFactory* factory = ProfileSyncServiceFactory::GetInstance();
144 return factory->GetForProfile(profile->GetOriginalProfile()); 161 return factory->GetForProfile(profile->GetOriginalProfile());
145 } 162 }
146 163
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/sync_internals_message_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698