| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/system_info_ui.h" | 5 #include "chrome/browser/ui/webui/system_info_ui.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
| 20 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "base/values.h" | 22 #include "base/values.h" |
| 23 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 int render_frame_id, | 57 int render_frame_id, |
| 58 const content::URLDataSource::GotDataCallback& callback) override; | 58 const content::URLDataSource::GotDataCallback& callback) override; |
| 59 std::string GetMimeType(const std::string&) const override { | 59 std::string GetMimeType(const std::string&) const override { |
| 60 return "text/html"; | 60 return "text/html"; |
| 61 } | 61 } |
| 62 bool ShouldAddContentSecurityPolicy() const override { return false; } | 62 bool ShouldAddContentSecurityPolicy() const override { return false; } |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 ~SystemInfoUIHTMLSource() override {} | 65 ~SystemInfoUIHTMLSource() override {} |
| 66 | 66 |
| 67 void SysInfoComplete(scoped_ptr<SystemLogsResponse> response); | 67 void SysInfoComplete(std::unique_ptr<SystemLogsResponse> response); |
| 68 void RequestComplete(); | 68 void RequestComplete(); |
| 69 void WaitForData(); | 69 void WaitForData(); |
| 70 | 70 |
| 71 // Stored data from StartDataRequest() | 71 // Stored data from StartDataRequest() |
| 72 std::string path_; | 72 std::string path_; |
| 73 content::URLDataSource::GotDataCallback callback_; | 73 content::URLDataSource::GotDataCallback callback_; |
| 74 | 74 |
| 75 scoped_ptr<SystemLogsResponse> response_; | 75 std::unique_ptr<SystemLogsResponse> response_; |
| 76 base::WeakPtrFactory<SystemInfoUIHTMLSource> weak_ptr_factory_; | 76 base::WeakPtrFactory<SystemInfoUIHTMLSource> weak_ptr_factory_; |
| 77 DISALLOW_COPY_AND_ASSIGN(SystemInfoUIHTMLSource); | 77 DISALLOW_COPY_AND_ASSIGN(SystemInfoUIHTMLSource); |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 // The handler for Javascript messages related to the "system" view. | 80 // The handler for Javascript messages related to the "system" view. |
| 81 class SystemInfoHandler : public WebUIMessageHandler, | 81 class SystemInfoHandler : public WebUIMessageHandler, |
| 82 public base::SupportsWeakPtr<SystemInfoHandler> { | 82 public base::SupportsWeakPtr<SystemInfoHandler> { |
| 83 public: | 83 public: |
| 84 SystemInfoHandler(); | 84 SystemInfoHandler(); |
| 85 ~SystemInfoHandler() override; | 85 ~SystemInfoHandler() override; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 109 int render_frame_id, | 109 int render_frame_id, |
| 110 const content::URLDataSource::GotDataCallback& callback) { | 110 const content::URLDataSource::GotDataCallback& callback) { |
| 111 path_ = path; | 111 path_ = path; |
| 112 callback_ = callback; | 112 callback_ = callback; |
| 113 | 113 |
| 114 AboutSystemLogsFetcher* fetcher = new AboutSystemLogsFetcher(); | 114 AboutSystemLogsFetcher* fetcher = new AboutSystemLogsFetcher(); |
| 115 fetcher->Fetch(base::Bind(&SystemInfoUIHTMLSource::SysInfoComplete, | 115 fetcher->Fetch(base::Bind(&SystemInfoUIHTMLSource::SysInfoComplete, |
| 116 weak_ptr_factory_.GetWeakPtr())); | 116 weak_ptr_factory_.GetWeakPtr())); |
| 117 } | 117 } |
| 118 | 118 |
| 119 | |
| 120 void SystemInfoUIHTMLSource::SysInfoComplete( | 119 void SystemInfoUIHTMLSource::SysInfoComplete( |
| 121 scoped_ptr<SystemLogsResponse> sys_info) { | 120 std::unique_ptr<SystemLogsResponse> sys_info) { |
| 122 response_ = std::move(sys_info); | 121 response_ = std::move(sys_info); |
| 123 RequestComplete(); | 122 RequestComplete(); |
| 124 } | 123 } |
| 125 | 124 |
| 126 void SystemInfoUIHTMLSource::RequestComplete() { | 125 void SystemInfoUIHTMLSource::RequestComplete() { |
| 127 base::DictionaryValue strings; | 126 base::DictionaryValue strings; |
| 128 strings.SetString("title", l10n_util::GetStringUTF16(IDS_ABOUT_SYS_TITLE)); | 127 strings.SetString("title", l10n_util::GetStringUTF16(IDS_ABOUT_SYS_TITLE)); |
| 129 strings.SetString("description", | 128 strings.SetString("description", |
| 130 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_DESC)); | 129 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_DESC)); |
| 131 strings.SetString("tableTitle", | 130 strings.SetString("tableTitle", |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 188 |
| 190 SystemInfoUI::SystemInfoUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 189 SystemInfoUI::SystemInfoUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 191 SystemInfoHandler* handler = new SystemInfoHandler(); | 190 SystemInfoHandler* handler = new SystemInfoHandler(); |
| 192 web_ui->AddMessageHandler(handler); | 191 web_ui->AddMessageHandler(handler); |
| 193 SystemInfoUIHTMLSource* html_source = new SystemInfoUIHTMLSource(); | 192 SystemInfoUIHTMLSource* html_source = new SystemInfoUIHTMLSource(); |
| 194 | 193 |
| 195 // Set up the chrome://system/ source. | 194 // Set up the chrome://system/ source. |
| 196 Profile* profile = Profile::FromWebUI(web_ui); | 195 Profile* profile = Profile::FromWebUI(web_ui); |
| 197 content::URLDataSource::Add(profile, html_source); | 196 content::URLDataSource::Add(profile, html_source); |
| 198 } | 197 } |
| OLD | NEW |