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

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

Issue 1340493002: Add initial version of chrome://popular-sites-internals page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@finch_country_version
Patch Set: review3 Created 5 years, 2 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/popular_sites_internals_message_handler.h"
6
7 #include "base/bind.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/values.h"
10 #include "chrome/browser/android/popular_sites.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "content/public/browser/web_ui.h"
13
14 PopularSitesInternalsMessageHandler::PopularSitesInternalsMessageHandler() {
15 }
16
17 PopularSitesInternalsMessageHandler::~PopularSitesInternalsMessageHandler() {}
18
19 void PopularSitesInternalsMessageHandler::RegisterMessages() {
20 web_ui()->RegisterMessageCallback("registerForEvents",
21 base::Bind(&PopularSitesInternalsMessageHandler::HandleRegisterForEvents,
22 base::Unretained(this)));
23
24 web_ui()->RegisterMessageCallback("download",
25 base::Bind(&PopularSitesInternalsMessageHandler::HandleDownload,
26 base::Unretained(this)));
27 }
28
29 void PopularSitesInternalsMessageHandler::HandleRegisterForEvents(
30 const base::ListValue* args) {
31 DCHECK(args->empty());
32
33 std::string country;
34 std::string version;
35 popular_sites_.reset(new PopularSites(
36 Profile::FromWebUI(web_ui()), country, version, std::string(), false,
37 base::Bind(&PopularSitesInternalsMessageHandler::OnPopularSitesAvailable,
38 base::Unretained(this), false)));
39 }
40
41 void PopularSitesInternalsMessageHandler::HandleDownload(
42 const base::ListValue* args) {
43 DCHECK_EQ(2u, args->GetSize());
44
45 std::string country;
46 args->GetString(0, &country);
47 std::string version;
48 args->GetString(1, &version);
49 popular_sites_.reset(new PopularSites(
50 Profile::FromWebUI(web_ui()), country, version, std::string(), true,
51 base::Bind(&PopularSitesInternalsMessageHandler::OnPopularSitesAvailable,
52 base::Unretained(this), true)));
53 }
54
55 void PopularSitesInternalsMessageHandler::SendDownloadResult(bool success) {
56 base::StringValue result(success ? "Success" : "Fail");
57 web_ui()->CallJavascriptFunction(
58 "chrome.popular_sites_internals.receiveDownloadResult", result);
59 }
60
61 void PopularSitesInternalsMessageHandler::SendSites() {
62 scoped_ptr<base::ListValue> sites_list(new base::ListValue);
63 for (const PopularSites::Site& site : popular_sites_->sites()) {
64 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue);
65 entry->SetString("title", site.title);
66 entry->SetString("url", site.url.spec());
67 sites_list->Append(entry.Pass());
68 }
69
70 base::DictionaryValue result;
71 result.Set("sites", sites_list.Pass());
72 web_ui()->CallJavascriptFunction(
73 "chrome.popular_sites_internals.receiveSites", result);
74 }
75
76 void PopularSitesInternalsMessageHandler::OnPopularSitesAvailable(
77 bool explicit_request, bool success) {
78 if (explicit_request)
79 SendDownloadResult(success);
80 SendSites();
81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698