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

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

Issue 2392693002: Rewrite simple uses of base::ListValue::Append(base::Value*) on CrOS. (Closed)
Patch Set: headers 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/options/chromeos/display_options_handler.h" 5 #include "chrome/browser/ui/webui/options/chromeos/display_options_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory>
10 #include <string> 11 #include <string>
12 #include <utility>
11 13
12 #include "ash/common/strings/grit/ash_strings.h" 14 #include "ash/common/strings/grit/ash_strings.h"
13 #include "ash/display/display_configuration_controller.h" 15 #include "ash/display/display_configuration_controller.h"
14 #include "ash/display/display_manager.h" 16 #include "ash/display/display_manager.h"
15 #include "ash/display/resolution_notification_controller.h" 17 #include "ash/display/resolution_notification_controller.h"
16 #include "ash/display/window_tree_host_manager.h" 18 #include "ash/display/window_tree_host_manager.h"
17 #include "ash/screen_util.h" 19 #include "ash/screen_util.h"
18 #include "ash/shell.h" 20 #include "ash/shell.h"
19 #include "base/bind.h" 21 #include "base/bind.h"
20 #include "base/command_line.h" 22 #include "base/command_line.h"
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 display_mode = ash::DisplayManager::UNIFIED; 318 display_mode = ash::DisplayManager::UNIFIED;
317 else 319 else
318 display_mode = ash::DisplayManager::EXTENDED; 320 display_mode = ash::DisplayManager::EXTENDED;
319 base::FundamentalValue mode(static_cast<int>(display_mode)); 321 base::FundamentalValue mode(static_cast<int>(display_mode));
320 322
321 int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 323 int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
322 std::unique_ptr<base::ListValue> js_displays(new base::ListValue); 324 std::unique_ptr<base::ListValue> js_displays(new base::ListValue);
323 for (const display::Display& display : displays) { 325 for (const display::Display& display : displays) {
324 const display::ManagedDisplayInfo& display_info = 326 const display::ManagedDisplayInfo& display_info =
325 display_manager->GetDisplayInfo(display.id()); 327 display_manager->GetDisplayInfo(display.id());
326 base::DictionaryValue* js_display = new base::DictionaryValue(); 328 std::unique_ptr<base::DictionaryValue> js_display(
329 new base::DictionaryValue());
327 js_display->SetString("id", base::Int64ToString(display.id())); 330 js_display->SetString("id", base::Int64ToString(display.id()));
328 js_display->SetString("name", 331 js_display->SetString("name",
329 display_manager->GetDisplayNameForId(display.id())); 332 display_manager->GetDisplayNameForId(display.id()));
330 base::DictionaryValue* display_bounds = 333 base::DictionaryValue* display_bounds =
331 ConvertBoundsToValue(display.bounds()); 334 ConvertBoundsToValue(display.bounds());
332 js_display->Set("bounds", display_bounds); 335 js_display->Set("bounds", display_bounds);
333 js_display->SetBoolean("isPrimary", display.id() == primary_id); 336 js_display->SetBoolean("isPrimary", display.id() == primary_id);
334 js_display->SetBoolean("isInternal", display.IsInternal()); 337 js_display->SetBoolean("isInternal", display.IsInternal());
335 js_display->SetInteger("rotation", display.RotationAsDegree()); 338 js_display->SetInteger("rotation", display.RotationAsDegree());
336 339
337 base::ListValue* js_resolutions = new base::ListValue(); 340 base::ListValue* js_resolutions = new base::ListValue();
338 for (const scoped_refptr<display::ManagedDisplayMode>& display_mode : 341 for (const scoped_refptr<display::ManagedDisplayMode>& display_mode :
339 display_info.display_modes()) { 342 display_info.display_modes()) {
340 js_resolutions->Append( 343 js_resolutions->Append(
341 ConvertDisplayModeToValue(display.id(), display_mode)); 344 ConvertDisplayModeToValue(display.id(), display_mode));
342 } 345 }
343 js_display->Set("resolutions", js_resolutions); 346 js_display->Set("resolutions", js_resolutions);
344 347
345 js_display->SetInteger("colorProfileId", display_info.color_profile()); 348 js_display->SetInteger("colorProfileId", display_info.color_profile());
346 base::ListValue* available_color_profiles = new base::ListValue(); 349 base::ListValue* available_color_profiles = new base::ListValue();
347 for (const auto& color_profile : display_info.available_color_profiles()) { 350 for (const auto& color_profile : display_info.available_color_profiles()) {
348 const base::string16 profile_name = GetColorProfileName(color_profile); 351 const base::string16 profile_name = GetColorProfileName(color_profile);
349 if (profile_name.empty()) 352 if (profile_name.empty())
350 continue; 353 continue;
351 base::DictionaryValue* color_profile_dict = new base::DictionaryValue(); 354 std::unique_ptr<base::DictionaryValue> color_profile_dict(
355 new base::DictionaryValue());
352 color_profile_dict->SetInteger("profileId", color_profile); 356 color_profile_dict->SetInteger("profileId", color_profile);
353 color_profile_dict->SetString("name", profile_name); 357 color_profile_dict->SetString("name", profile_name);
354 available_color_profiles->Append(color_profile_dict); 358 available_color_profiles->Append(std::move(color_profile_dict));
355 } 359 }
356 js_display->Set("availableColorProfiles", available_color_profiles); 360 js_display->Set("availableColorProfiles", available_color_profiles);
357 361
358 if (display_manager->GetNumDisplays() > 1) { 362 if (display_manager->GetNumDisplays() > 1) {
359 const display::DisplayPlacement placement = 363 const display::DisplayPlacement placement =
360 display_manager->GetCurrentDisplayLayout().FindPlacementById( 364 display_manager->GetCurrentDisplayLayout().FindPlacementById(
361 display.id()); 365 display.id());
362 if (placement.display_id != display::Display::kInvalidDisplayID) { 366 if (placement.display_id != display::Display::kInvalidDisplayID) {
363 js_display->SetString( 367 js_display->SetString(
364 "parentId", base::Int64ToString(placement.parent_display_id)); 368 "parentId", base::Int64ToString(placement.parent_display_id));
365 js_display->SetInteger("layoutType", placement.position); 369 js_display->SetInteger("layoutType", placement.position);
366 js_display->SetInteger("offset", placement.offset); 370 js_display->SetInteger("offset", placement.offset);
367 } 371 }
368 } 372 }
369 373
370 js_displays->Append(js_display); 374 js_displays->Append(std::move(js_display));
371 } 375 }
372 376
373 web_ui()->CallJavascriptFunctionUnsafe( 377 web_ui()->CallJavascriptFunctionUnsafe(
374 "options.DisplayOptions.setDisplayInfo", mode, *js_displays); 378 "options.DisplayOptions.setDisplayInfo", mode, *js_displays);
375 } 379 }
376 380
377 void DisplayOptionsHandler::UpdateDisplaySettingsEnabled() { 381 void DisplayOptionsHandler::UpdateDisplaySettingsEnabled() {
378 // TODO(mash) Support Chrome display settings in Mash. crbug.com/548429 382 // TODO(mash) Support Chrome display settings in Mash. crbug.com/548429
379 if (chrome::IsRunningInMash()) 383 if (chrome::IsRunningInMash())
380 return; 384 return;
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 bool enable = false; 580 bool enable = false;
577 if (!args->GetBoolean(0, &enable)) 581 if (!args->GetBoolean(0, &enable))
578 NOTREACHED(); 582 NOTREACHED();
579 583
580 GetDisplayManager()->SetDefaultMultiDisplayModeForCurrentDisplays( 584 GetDisplayManager()->SetDefaultMultiDisplayModeForCurrentDisplays(
581 enable ? ash::DisplayManager::UNIFIED : ash::DisplayManager::EXTENDED); 585 enable ? ash::DisplayManager::UNIFIED : ash::DisplayManager::EXTENDED);
582 } 586 }
583 587
584 } // namespace options 588 } // namespace options
585 } // namespace chromeos 589 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698