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

Side by Side Diff: chrome/browser/ui/webui/chromeos/drive_internals_ui.cc

Issue 2392693002: Rewrite simple uses of base::ListValue::Append(base::Value*) on CrOS. (Closed)
Patch Set: MakeUnique Created 4 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chromeos/drive_internals_ui.h" 5 #include "chrome/browser/ui/webui/chromeos/drive_internals_ui.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory>
11 #include <utility>
12
10 #include "base/bind.h" 13 #include "base/bind.h"
11 #include "base/files/file_enumerator.h" 14 #include "base/files/file_enumerator.h"
12 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
13 #include "base/format_macros.h" 16 #include "base/format_macros.h"
14 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ptr_util.h"
15 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
16 #include "base/path_service.h" 20 #include "base/path_service.h"
17 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
18 #include "base/sys_info.h" 22 #include "base/sys_info.h"
19 #include "chrome/browser/chromeos/drive/debug_info_collector.h" 23 #include "chrome/browser/chromeos/drive/debug_info_collector.h"
20 #include "chrome/browser/chromeos/drive/drive_integration_service.h" 24 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
21 #include "chrome/browser/chromeos/drive/file_system_util.h" 25 #include "chrome/browser/chromeos/drive/file_system_util.h"
22 #include "chrome/browser/chromeos/file_manager/path_util.h" 26 #include "chrome/browser/chromeos/file_manager/path_util.h"
23 #include "chrome/browser/drive/drive_notification_manager_factory.h" 27 #include "chrome/browser/drive/drive_notification_manager_factory.h"
24 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 return "error"; 197 return "error";
194 default: // Treat all other higher severities as ERROR. 198 default: // Treat all other higher severities as ERROR.
195 return "error"; 199 return "error";
196 } 200 }
197 } 201 }
198 202
199 // Appends {'key': key, 'value': value} dictionary to the |list|. 203 // Appends {'key': key, 'value': value} dictionary to the |list|.
200 void AppendKeyValue(base::ListValue* list, 204 void AppendKeyValue(base::ListValue* list,
201 const std::string& key, 205 const std::string& key,
202 const std::string& value) { 206 const std::string& value) {
203 base::DictionaryValue* dict = new base::DictionaryValue; 207 auto dict = base::MakeUnique<base::DictionaryValue>();
204 dict->SetString("key", key); 208 dict->SetString("key", key);
205 dict->SetString("value", value); 209 dict->SetString("value", value);
206 list->Append(dict); 210 list->Append(std::move(dict));
207 } 211 }
208 212
209 // Class to handle messages from chrome://drive-internals. 213 // Class to handle messages from chrome://drive-internals.
210 class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { 214 class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
211 public: 215 public:
212 DriveInternalsWebUIHandler() 216 DriveInternalsWebUIHandler()
213 : last_sent_event_id_(-1), 217 : last_sent_event_id_(-1),
214 weak_ptr_factory_(this) { 218 weak_ptr_factory_(this) {
215 } 219 }
216 220
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 return; 349 return;
346 } 350 }
347 DCHECK(parsed_app_list); 351 DCHECK(parsed_app_list);
348 352
349 base::DictionaryValue app_list; 353 base::DictionaryValue app_list;
350 app_list.SetString("etag", parsed_app_list->etag()); 354 app_list.SetString("etag", parsed_app_list->etag());
351 355
352 base::ListValue* items = new base::ListValue(); 356 base::ListValue* items = new base::ListValue();
353 for (size_t i = 0; i < parsed_app_list->items().size(); ++i) { 357 for (size_t i = 0; i < parsed_app_list->items().size(); ++i) {
354 const google_apis::AppResource* app = parsed_app_list->items()[i]; 358 const google_apis::AppResource* app = parsed_app_list->items()[i];
355 base::DictionaryValue* app_data = new base::DictionaryValue(); 359 auto app_data = base::MakeUnique<base::DictionaryValue>();
356 app_data->SetString("name", app->name()); 360 app_data->SetString("name", app->name());
357 app_data->SetString("application_id", app->application_id()); 361 app_data->SetString("application_id", app->application_id());
358 app_data->SetString("object_type", app->object_type()); 362 app_data->SetString("object_type", app->object_type());
359 app_data->SetBoolean("supports_create", app->supports_create()); 363 app_data->SetBoolean("supports_create", app->supports_create());
360 364
361 items->Append(app_data); 365 items->Append(std::move(app_data));
362 } 366 }
363 app_list.Set("items", items); 367 app_list.Set("items", items);
364 368
365 web_ui()->CallJavascriptFunctionUnsafe("updateAppList", app_list); 369 web_ui()->CallJavascriptFunctionUnsafe("updateAppList", app_list);
366 } 370 }
367 371
368 void DriveInternalsWebUIHandler::RegisterMessages() { 372 void DriveInternalsWebUIHandler::RegisterMessages() {
369 web_ui()->RegisterMessageCallback( 373 web_ui()->RegisterMessageCallback(
370 "pageLoaded", 374 "pageLoaded",
371 base::Bind(&DriveInternalsWebUIHandler::OnPageLoaded, 375 base::Bind(&DriveInternalsWebUIHandler::OnPageLoaded,
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 drive::JobListInterface* job_list) { 643 drive::JobListInterface* job_list) {
640 DCHECK_CURRENTLY_ON(BrowserThread::UI); 644 DCHECK_CURRENTLY_ON(BrowserThread::UI);
641 DCHECK(job_list); 645 DCHECK(job_list);
642 646
643 std::vector<drive::JobInfo> info_list = job_list->GetJobInfoList(); 647 std::vector<drive::JobInfo> info_list = job_list->GetJobInfoList();
644 648
645 base::ListValue in_flight_operations; 649 base::ListValue in_flight_operations;
646 for (size_t i = 0; i < info_list.size(); ++i) { 650 for (size_t i = 0; i < info_list.size(); ++i) {
647 const drive::JobInfo& info = info_list[i]; 651 const drive::JobInfo& info = info_list[i];
648 652
649 base::DictionaryValue* dict = new base::DictionaryValue; 653 auto dict = base::MakeUnique<base::DictionaryValue>();
650 dict->SetInteger("id", info.job_id); 654 dict->SetInteger("id", info.job_id);
651 dict->SetString("type", drive::JobTypeToString(info.job_type)); 655 dict->SetString("type", drive::JobTypeToString(info.job_type));
652 dict->SetString("file_path", info.file_path.AsUTF8Unsafe()); 656 dict->SetString("file_path", info.file_path.AsUTF8Unsafe());
653 dict->SetString("state", drive::JobStateToString(info.state)); 657 dict->SetString("state", drive::JobStateToString(info.state));
654 dict->SetDouble("progress_current", info.num_completed_bytes); 658 dict->SetDouble("progress_current", info.num_completed_bytes);
655 dict->SetDouble("progress_total", info.num_total_bytes); 659 dict->SetDouble("progress_total", info.num_total_bytes);
656 in_flight_operations.Append(dict); 660 in_flight_operations.Append(std::move(dict));
657 } 661 }
658 web_ui()->CallJavascriptFunctionUnsafe("updateInFlightOperations", 662 web_ui()->CallJavascriptFunctionUnsafe("updateInFlightOperations",
659 in_flight_operations); 663 in_flight_operations);
660 } 664 }
661 665
662 void DriveInternalsWebUIHandler::UpdateGCacheContentsSection() { 666 void DriveInternalsWebUIHandler::UpdateGCacheContentsSection() {
663 DCHECK_CURRENTLY_ON(BrowserThread::UI); 667 DCHECK_CURRENTLY_ON(BrowserThread::UI);
664 668
665 // Start updating the GCache contents section. 669 // Start updating the GCache contents section.
666 Profile* profile = Profile::FromWebUI(web_ui()); 670 Profile* profile = Profile::FromWebUI(web_ui());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 integration_service->event_logger()->GetHistory(); 747 integration_service->event_logger()->GetHistory();
744 748
745 base::ListValue list; 749 base::ListValue list;
746 for (size_t i = 0; i < log.size(); ++i) { 750 for (size_t i = 0; i < log.size(); ++i) {
747 // Skip events which were already sent. 751 // Skip events which were already sent.
748 if (log[i].id <= last_sent_event_id_) 752 if (log[i].id <= last_sent_event_id_)
749 continue; 753 continue;
750 754
751 std::string severity = SeverityToString(log[i].severity); 755 std::string severity = SeverityToString(log[i].severity);
752 756
753 base::DictionaryValue* dict = new base::DictionaryValue; 757 auto dict = base::MakeUnique<base::DictionaryValue>();
754 dict->SetString("key", 758 dict->SetString("key",
755 google_apis::util::FormatTimeAsStringLocaltime(log[i].when)); 759 google_apis::util::FormatTimeAsStringLocaltime(log[i].when));
756 dict->SetString("value", "[" + severity + "] " + log[i].what); 760 dict->SetString("value", "[" + severity + "] " + log[i].what);
757 dict->SetString("class", "log-" + severity); 761 dict->SetString("class", "log-" + severity);
758 list.Append(dict); 762 list.Append(std::move(dict));
759 last_sent_event_id_ = log[i].id; 763 last_sent_event_id_ = log[i].id;
760 } 764 }
761 if (!list.empty()) 765 if (!list.empty())
762 web_ui()->CallJavascriptFunctionUnsafe("updateEventLog", list); 766 web_ui()->CallJavascriptFunctionUnsafe("updateEventLog", list);
763 } 767 }
764 768
765 void DriveInternalsWebUIHandler::UpdatePathConfigurationsSection() { 769 void DriveInternalsWebUIHandler::UpdatePathConfigurationsSection() {
766 DCHECK_CURRENTLY_ON(BrowserThread::UI); 770 DCHECK_CURRENTLY_ON(BrowserThread::UI);
767 771
768 Profile* const profile = Profile::FromWebUI(web_ui()); 772 Profile* const profile = Profile::FromWebUI(web_ui());
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 content::WebUIDataSource::Create(chrome::kChromeUIDriveInternalsHost); 901 content::WebUIDataSource::Create(chrome::kChromeUIDriveInternalsHost);
898 source->AddResourcePath("drive_internals.css", IDR_DRIVE_INTERNALS_CSS); 902 source->AddResourcePath("drive_internals.css", IDR_DRIVE_INTERNALS_CSS);
899 source->AddResourcePath("drive_internals.js", IDR_DRIVE_INTERNALS_JS); 903 source->AddResourcePath("drive_internals.js", IDR_DRIVE_INTERNALS_JS);
900 source->SetDefaultResource(IDR_DRIVE_INTERNALS_HTML); 904 source->SetDefaultResource(IDR_DRIVE_INTERNALS_HTML);
901 905
902 Profile* profile = Profile::FromWebUI(web_ui); 906 Profile* profile = Profile::FromWebUI(web_ui);
903 content::WebUIDataSource::Add(profile, source); 907 content::WebUIDataSource::Add(profile, source);
904 } 908 }
905 909
906 } // namespace chromeos 910 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698