| OLD | NEW |
| 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/browser_process.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/search_engines/template_url_service_factory.h" | 18 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 18 #include "components/url_formatter/url_fixer.h" | 19 #include "components/url_formatter/url_fixer.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/web_ui.h" | 21 #include "content/public/browser/web_ui.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 std::string ReadFileToString(const base::FilePath& path) { | 25 std::string ReadFileToString(const base::FilePath& path) { |
| 25 std::string result; | 26 std::string result; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 53 void PopularSitesInternalsMessageHandler::HandleRegisterForEvents( | 54 void PopularSitesInternalsMessageHandler::HandleRegisterForEvents( |
| 54 const base::ListValue* args) { | 55 const base::ListValue* args) { |
| 55 DCHECK(args->empty()); | 56 DCHECK(args->empty()); |
| 56 | 57 |
| 57 std::string country; | 58 std::string country; |
| 58 std::string version; | 59 std::string version; |
| 59 Profile* profile = Profile::FromWebUI(web_ui()); | 60 Profile* profile = Profile::FromWebUI(web_ui()); |
| 60 popular_sites_.reset(new PopularSites( | 61 popular_sites_.reset(new PopularSites( |
| 61 profile->GetPrefs(), | 62 profile->GetPrefs(), |
| 62 TemplateURLServiceFactory::GetForProfile(profile), | 63 TemplateURLServiceFactory::GetForProfile(profile), |
| 64 g_browser_process->variations_service(), |
| 63 profile->GetRequestContext(), | 65 profile->GetRequestContext(), |
| 64 country, version, false, | 66 country, version, false, |
| 65 base::Bind(&PopularSitesInternalsMessageHandler::OnPopularSitesAvailable, | 67 base::Bind(&PopularSitesInternalsMessageHandler::OnPopularSitesAvailable, |
| 66 base::Unretained(this), false))); | 68 base::Unretained(this), false))); |
| 67 } | 69 } |
| 68 | 70 |
| 69 void PopularSitesInternalsMessageHandler::HandleDownload( | 71 void PopularSitesInternalsMessageHandler::HandleDownload( |
| 70 const base::ListValue* args) { | 72 const base::ListValue* args) { |
| 71 DCHECK_EQ(3u, args->GetSize()); | 73 DCHECK_EQ(3u, args->GetSize()); |
| 72 Profile* profile = Profile::FromWebUI(web_ui()); | 74 Profile* profile = Profile::FromWebUI(web_ui()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 84 url_formatter::FixupURL(url, std::string()), callback)); | 86 url_formatter::FixupURL(url, std::string()), callback)); |
| 85 return; | 87 return; |
| 86 } | 88 } |
| 87 std::string country; | 89 std::string country; |
| 88 args->GetString(1, &country); | 90 args->GetString(1, &country); |
| 89 std::string version; | 91 std::string version; |
| 90 args->GetString(2, &version); | 92 args->GetString(2, &version); |
| 91 popular_sites_.reset(new PopularSites( | 93 popular_sites_.reset(new PopularSites( |
| 92 profile->GetPrefs(), | 94 profile->GetPrefs(), |
| 93 TemplateURLServiceFactory::GetForProfile(profile), | 95 TemplateURLServiceFactory::GetForProfile(profile), |
| 96 g_browser_process->variations_service(), |
| 94 profile->GetRequestContext(), | 97 profile->GetRequestContext(), |
| 95 country, version, true, callback)); | 98 country, version, true, callback)); |
| 96 } | 99 } |
| 97 | 100 |
| 98 void PopularSitesInternalsMessageHandler::HandleViewJson( | 101 void PopularSitesInternalsMessageHandler::HandleViewJson( |
| 99 const base::ListValue* args) { | 102 const base::ListValue* args) { |
| 100 DCHECK_EQ(0u, args->GetSize()); | 103 DCHECK_EQ(0u, args->GetSize()); |
| 101 | 104 |
| 102 const base::FilePath& path = popular_sites_->local_path(); | 105 const base::FilePath& path = popular_sites_->local_path(); |
| 103 base::PostTaskAndReplyWithResult( | 106 base::PostTaskAndReplyWithResult( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 web_ui()->CallJavascriptFunction("chrome.popular_sites_internals.receiveJson", | 140 web_ui()->CallJavascriptFunction("chrome.popular_sites_internals.receiveJson", |
| 138 base::StringValue(json)); | 141 base::StringValue(json)); |
| 139 } | 142 } |
| 140 | 143 |
| 141 void PopularSitesInternalsMessageHandler::OnPopularSitesAvailable( | 144 void PopularSitesInternalsMessageHandler::OnPopularSitesAvailable( |
| 142 bool explicit_request, bool success) { | 145 bool explicit_request, bool success) { |
| 143 if (explicit_request) | 146 if (explicit_request) |
| 144 SendDownloadResult(success); | 147 SendDownloadResult(success); |
| 145 SendSites(); | 148 SendSites(); |
| 146 } | 149 } |
| OLD | NEW |