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

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

Issue 1919043005: Remove Profile dependency from PopularSites. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/android/ntp/popular_sites.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 "chrome/browser/search_engines/template_url_service_factory.h"
17 #include "components/url_formatter/url_fixer.h" 18 #include "components/url_formatter/url_fixer.h"
18 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/web_ui.h" 20 #include "content/public/browser/web_ui.h"
20 21
21 namespace { 22 namespace {
22 23
23 std::string ReadFileToString(const base::FilePath& path) { 24 std::string ReadFileToString(const base::FilePath& path) {
24 std::string result; 25 std::string result;
25 if (!base::ReadFileToString(path, &result)) 26 if (!base::ReadFileToString(path, &result))
26 result.clear(); 27 result.clear();
(...skipping 21 matching lines...) Expand all
48 base::Bind(&PopularSitesInternalsMessageHandler::HandleViewJson, 49 base::Bind(&PopularSitesInternalsMessageHandler::HandleViewJson,
49 base::Unretained(this))); 50 base::Unretained(this)));
50 } 51 }
51 52
52 void PopularSitesInternalsMessageHandler::HandleRegisterForEvents( 53 void PopularSitesInternalsMessageHandler::HandleRegisterForEvents(
53 const base::ListValue* args) { 54 const base::ListValue* args) {
54 DCHECK(args->empty()); 55 DCHECK(args->empty());
55 56
56 std::string country; 57 std::string country;
57 std::string version; 58 std::string version;
59 Profile* profile = Profile::FromWebUI(web_ui());
58 popular_sites_.reset(new PopularSites( 60 popular_sites_.reset(new PopularSites(
59 Profile::FromWebUI(web_ui()), country, version, false, 61 profile->GetPrefs(),
62 TemplateURLServiceFactory::GetForProfile(profile),
63 profile->GetRequestContext(),
64 country, version, false,
60 base::Bind(&PopularSitesInternalsMessageHandler::OnPopularSitesAvailable, 65 base::Bind(&PopularSitesInternalsMessageHandler::OnPopularSitesAvailable,
61 base::Unretained(this), false))); 66 base::Unretained(this), false)));
62 } 67 }
63 68
64 void PopularSitesInternalsMessageHandler::HandleDownload( 69 void PopularSitesInternalsMessageHandler::HandleDownload(
65 const base::ListValue* args) { 70 const base::ListValue* args) {
66 DCHECK_EQ(3u, args->GetSize()); 71 DCHECK_EQ(3u, args->GetSize());
72 Profile* profile = Profile::FromWebUI(web_ui());
67 auto callback = 73 auto callback =
68 base::Bind(&PopularSitesInternalsMessageHandler::OnPopularSitesAvailable, 74 base::Bind(&PopularSitesInternalsMessageHandler::OnPopularSitesAvailable,
69 base::Unretained(this), true); 75 base::Unretained(this), true);
70 76
71 std::string url; 77 std::string url;
72 args->GetString(0, &url); 78 args->GetString(0, &url);
73 if (!url.empty()) { 79 if (!url.empty()) {
74 popular_sites_.reset(new PopularSites( 80 popular_sites_.reset(new PopularSites(
75 Profile::FromWebUI(web_ui()), 81 profile->GetPrefs(),
82 TemplateURLServiceFactory::GetForProfile(profile),
83 profile->GetRequestContext(),
76 url_formatter::FixupURL(url, std::string()), callback)); 84 url_formatter::FixupURL(url, std::string()), callback));
77 return; 85 return;
78 } 86 }
79 std::string country; 87 std::string country;
80 args->GetString(1, &country); 88 args->GetString(1, &country);
81 std::string version; 89 std::string version;
82 args->GetString(2, &version); 90 args->GetString(2, &version);
83 popular_sites_.reset(new PopularSites(Profile::FromWebUI(web_ui()), country, 91 popular_sites_.reset(new PopularSites(
84 version, true, callback)); 92 profile->GetPrefs(),
93 TemplateURLServiceFactory::GetForProfile(profile),
94 profile->GetRequestContext(),
95 country, version, true, callback));
85 } 96 }
86 97
87 void PopularSitesInternalsMessageHandler::HandleViewJson( 98 void PopularSitesInternalsMessageHandler::HandleViewJson(
88 const base::ListValue* args) { 99 const base::ListValue* args) {
89 DCHECK_EQ(0u, args->GetSize()); 100 DCHECK_EQ(0u, args->GetSize());
90 101
91 const base::FilePath& path = popular_sites_->local_path(); 102 const base::FilePath& path = popular_sites_->local_path();
92 base::PostTaskAndReplyWithResult( 103 base::PostTaskAndReplyWithResult(
93 content::BrowserThread::GetBlockingPool() 104 content::BrowserThread::GetBlockingPool()
94 ->GetTaskRunnerWithShutdownBehavior( 105 ->GetTaskRunnerWithShutdownBehavior(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 web_ui()->CallJavascriptFunction("chrome.popular_sites_internals.receiveJson", 137 web_ui()->CallJavascriptFunction("chrome.popular_sites_internals.receiveJson",
127 base::StringValue(json)); 138 base::StringValue(json));
128 } 139 }
129 140
130 void PopularSitesInternalsMessageHandler::OnPopularSitesAvailable( 141 void PopularSitesInternalsMessageHandler::OnPopularSitesAvailable(
131 bool explicit_request, bool success) { 142 bool explicit_request, bool success) {
132 if (explicit_request) 143 if (explicit_request)
133 SendDownloadResult(success); 144 SendDownloadResult(success);
134 SendSites(); 145 SendSites();
135 } 146 }
OLDNEW
« no previous file with comments | « chrome/browser/android/ntp/popular_sites.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698