Index: chrome/browser/ui/webui/prefs_internals_source.cc |
diff --git a/chrome/browser/ui/webui/prefs_internals_source.cc b/chrome/browser/ui/webui/prefs_internals_source.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a8606d0f176b97207f272b4bc2bdda9e72e63128 |
--- /dev/null |
+++ b/chrome/browser/ui/webui/prefs_internals_source.cc |
@@ -0,0 +1,42 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/webui/prefs_internals_source.h" |
+ |
+#include <string> |
+ |
+#include "base/json/json_writer.h" |
+#include "base/memory/ref_counted_memory.h" |
+#include "base/values.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/common/url_constants.h" |
+#include "components/prefs/pref_service.h" |
+#include "content/public/browser/browser_thread.h" |
+ |
+PrefsInternalsSource::PrefsInternalsSource(Profile* profile) |
+ : profile_(profile) {} |
+ |
+PrefsInternalsSource::~PrefsInternalsSource() = default; |
+ |
+std::string PrefsInternalsSource::GetSource() const { |
+ return chrome::kChromeUIPrefsInternalsHost; |
+} |
+ |
+std::string PrefsInternalsSource::GetMimeType(const std::string& path) const { |
+ return "text/plain"; |
+} |
+ |
+void PrefsInternalsSource::StartDataRequest( |
+ const std::string& path, |
+ const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
+ const content::URLDataSource::GotDataCallback& callback) { |
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ std::string json; |
+ std::unique_ptr<base::DictionaryValue> prefs = |
+ profile_->GetPrefs()->GetPreferenceValues(); |
+ DCHECK(prefs); |
+ CHECK(base::JSONWriter::WriteWithOptions( |
+ *prefs, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json)); |
+ callback.Run(base::RefCountedString::TakeString(&json)); |
+} |