OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/webui/prefs_internals_source.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/json/json_writer.h" |
| 10 #include "base/memory/ref_counted_memory.h" |
| 11 #include "base/values.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/url_constants.h" |
| 14 #include "components/prefs/pref_service.h" |
| 15 #include "content/public/browser/browser_thread.h" |
| 16 |
| 17 PrefsInternalsSource::PrefsInternalsSource(Profile* profile) |
| 18 : profile_(profile) {} |
| 19 |
| 20 PrefsInternalsSource::~PrefsInternalsSource() = default; |
| 21 |
| 22 std::string PrefsInternalsSource::GetSource() const { |
| 23 return chrome::kChromeUIPrefsInternalsHost; |
| 24 } |
| 25 |
| 26 std::string PrefsInternalsSource::GetMimeType(const std::string& path) const { |
| 27 return "text/plain"; |
| 28 } |
| 29 |
| 30 void PrefsInternalsSource::StartDataRequest( |
| 31 const std::string& path, |
| 32 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
| 33 const content::URLDataSource::GotDataCallback& callback) { |
| 34 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 35 std::string json; |
| 36 std::unique_ptr<base::DictionaryValue> prefs = |
| 37 profile_->GetPrefs()->GetPreferenceValues(); |
| 38 DCHECK(prefs); |
| 39 CHECK(base::JSONWriter::WriteWithOptions( |
| 40 *prefs, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json)); |
| 41 callback.Run(base::RefCountedString::TakeString(&json)); |
| 42 } |
OLD | NEW |