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

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

Issue 1851803002: [NTP Popular Sites] Store country/version in prefs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 4 years, 8 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
« no previous file with comments | « chrome/browser/supervised_user/supervised_user_service.cc ('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 2015 The Chromium Authors. All rights reserved. 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 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/popular_sites_internals_message_handler.h" 5 #include "chrome/browser/ui/webui/popular_sites_internals_message_handler.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/task_runner_util.h" 13 #include "base/task_runner_util.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/android/ntp/popular_sites.h" 15 #include "chrome/browser/android/ntp/popular_sites.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "components/url_formatter/url_fixer.h" 17 #include "components/url_formatter/url_fixer.h"
18 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/web_ui.h" 19 #include "content/public/browser/web_ui.h"
20 20
21 namespace { 21 namespace {
22 22
23 std::string ReadFileToString(const base::FilePath& path) { 23 std::string ReadFileToString(const base::FilePath& path) {
24 std::string result; 24 std::string result;
25 if (!base::ReadFileToString(path, &result)) 25 if (!base::ReadFileToString(path, &result))
26 result.clear(); 26 result.clear();
27 return result; 27 return result;
28 } 28 }
29 } 29
30 } // namespace
30 31
31 PopularSitesInternalsMessageHandler::PopularSitesInternalsMessageHandler() 32 PopularSitesInternalsMessageHandler::PopularSitesInternalsMessageHandler()
32 : weak_ptr_factory_(this) {} 33 : weak_ptr_factory_(this) {}
33 34
34 PopularSitesInternalsMessageHandler::~PopularSitesInternalsMessageHandler() {} 35 PopularSitesInternalsMessageHandler::~PopularSitesInternalsMessageHandler() {}
35 36
36 void PopularSitesInternalsMessageHandler::RegisterMessages() { 37 void PopularSitesInternalsMessageHandler::RegisterMessages() {
37 web_ui()->RegisterMessageCallback("registerForEvents", 38 web_ui()->RegisterMessageCallback("registerForEvents",
38 base::Bind(&PopularSitesInternalsMessageHandler::HandleRegisterForEvents, 39 base::Bind(&PopularSitesInternalsMessageHandler::HandleRegisterForEvents,
39 base::Unretained(this))); 40 base::Unretained(this)));
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 scoped_ptr<base::ListValue> sites_list(new base::ListValue); 109 scoped_ptr<base::ListValue> sites_list(new base::ListValue);
109 for (const PopularSites::Site& site : popular_sites_->sites()) { 110 for (const PopularSites::Site& site : popular_sites_->sites()) {
110 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); 111 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue);
111 entry->SetString("title", site.title); 112 entry->SetString("title", site.title);
112 entry->SetString("url", site.url.spec()); 113 entry->SetString("url", site.url.spec());
113 sites_list->Append(std::move(entry)); 114 sites_list->Append(std::move(entry));
114 } 115 }
115 116
116 base::DictionaryValue result; 117 base::DictionaryValue result;
117 result.Set("sites", std::move(sites_list)); 118 result.Set("sites", std::move(sites_list));
119 result.SetString("country", popular_sites_->GetCountry());
120 result.SetString("version", popular_sites_->GetVersion());
118 web_ui()->CallJavascriptFunction( 121 web_ui()->CallJavascriptFunction(
119 "chrome.popular_sites_internals.receiveSites", result); 122 "chrome.popular_sites_internals.receiveSites", result);
120 } 123 }
121 124
122 void PopularSitesInternalsMessageHandler::SendJson(const std::string& json) { 125 void PopularSitesInternalsMessageHandler::SendJson(const std::string& json) {
123 web_ui()->CallJavascriptFunction("chrome.popular_sites_internals.receiveJson", 126 web_ui()->CallJavascriptFunction("chrome.popular_sites_internals.receiveJson",
124 base::StringValue(json)); 127 base::StringValue(json));
125 } 128 }
126 129
127 void PopularSitesInternalsMessageHandler::OnPopularSitesAvailable( 130 void PopularSitesInternalsMessageHandler::OnPopularSitesAvailable(
128 bool explicit_request, bool success) { 131 bool explicit_request, bool success) {
129 if (explicit_request) 132 if (explicit_request)
130 SendDownloadResult(success); 133 SendDownloadResult(success);
131 SendSites(); 134 SendSites();
132 } 135 }
OLDNEW
« no previous file with comments | « chrome/browser/supervised_user/supervised_user_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698