Chromium Code Reviews| Index: ash/display/display_color_manager_chromeos.cc | 
| diff --git a/ash/display/display_color_manager_chromeos.cc b/ash/display/display_color_manager_chromeos.cc | 
| index 1241978958018acff967d30fbfd9dcb2d0c961dd..e4d8a9a0162c921b37902964670961105c88b28e 100644 | 
| --- a/ash/display/display_color_manager_chromeos.cc | 
| +++ b/ash/display/display_color_manager_chromeos.cc | 
| @@ -6,40 +6,45 @@ | 
| #include <utility> | 
| -#include "base/bind.h" | 
| -#include "base/bind_helpers.h" | 
| -#include "base/command_line.h" | 
| -#include "base/files/file_path.h" | 
| #include "base/files/file_util.h" | 
| -#include "base/format_macros.h" | 
| -#include "base/logging.h" | 
| #include "base/message_loop/message_loop.h" | 
| -#include "base/path_service.h" | 
| -#include "base/stl_util.h" | 
| -#include "base/strings/stringprintf.h" | 
| #include "base/task_runner_util.h" | 
| -#include "base/threading/sequenced_worker_pool.h" | 
| -#include "chromeos/chromeos_paths.h" | 
| +#include "components/quirks_client/quirks_client.h" | 
| #include "third_party/qcms/src/qcms.h" | 
| -#include "ui/display/types/display_snapshot.h" | 
| #include "ui/display/types/gamma_ramp_rgb_entry.h" | 
| -#include "ui/display/types/native_display_delegate.h" | 
| -#include "ui/gfx/display.h" | 
| -#include "ui/gfx/screen.h" | 
| namespace ash { | 
| namespace { | 
| -bool ParseFile(const base::FilePath& path, | 
| - DisplayColorManager::ColorCalibrationData* data) { | 
| - if (!base::PathExists(path)) // No icc file for this display; not an error. | 
| - return false; | 
| +void DoNothing(base::FilePath) {} | 
| + | 
| +scoped_ptr<DisplayColorManager::ColorCalibrationData> ParseDisplayProfile( | 
| + const int64_t display_id, | 
| + const int64_t product_id) { | 
| + // TODO(glevin): At some point, we may want to add a callback, and apply the | 
| + // icc file as soon as it's downloaded. For now, we'll only apply it if it | 
| + // exists at startup, and try to download it for next time if it doesn't. | 
| + base::FilePath path = quirks_client::QuirksClient::RequestIccProfilePath( | 
| + product_id, base::Bind(DoNothing)); | 
| + std::string product_string = | 
| + quirks_client::QuirksClient::IdToHexString(product_id); | 
| + if (path.empty()) { | 
| + VLOG(1) << "No icc file found with product id: " << product_string | 
| + << " for display id: " << display_id; | 
| + return nullptr; | 
| + } | 
| + | 
| + VLOG(1) << "Loading ICC file " << path.value() | 
| + << " for display id: " << display_id | 
| + << " with product id: " << product_string; | 
| + | 
| + DCHECK(base::PathExists(path)); // Quirks Client should ensure this. | 
| qcms_profile* display_profile = qcms_profile_from_path(path.value().c_str()); | 
| if (!display_profile) { | 
| LOG(WARNING) << "Unable to load ICC file: " << path.value(); | 
| - return false; | 
| + return nullptr; | 
| } | 
| size_t vcgt_channel_length = | 
| @@ -47,7 +52,7 @@ bool ParseFile(const base::FilePath& path, | 
| if (!vcgt_channel_length) { | 
| LOG(WARNING) << "No vcgt table in ICC file: " << path.value(); | 
| qcms_profile_release(display_profile); | 
| - return false; | 
| + return nullptr; | 
| } | 
| std::vector<uint16_t> vcgt_data; | 
| @@ -55,9 +60,11 @@ bool ParseFile(const base::FilePath& path, | 
| if (!qcms_profile_get_vcgt_rgb_channels(display_profile, &vcgt_data[0])) { | 
| LOG(WARNING) << "Unable to get vcgt data"; | 
| qcms_profile_release(display_profile); | 
| - return false; | 
| + return nullptr; | 
| } | 
| + scoped_ptr<DisplayColorManager::ColorCalibrationData> data( | 
| + new DisplayColorManager::ColorCalibrationData()); | 
| data->lut.resize(vcgt_channel_length); | 
| for (size_t i = 0; i < vcgt_channel_length; ++i) { | 
| data->lut[i].r = vcgt_data[i]; | 
| @@ -65,16 +72,8 @@ bool ParseFile(const base::FilePath& path, | 
| data->lut[i].b = vcgt_data[(vcgt_channel_length * 2) + i]; | 
| } | 
| qcms_profile_release(display_profile); | 
| - return true; | 
| -} | 
| - | 
| -base::FilePath PathForDisplaySnapshot(const ui::DisplaySnapshot* snapshot) { | 
| - base::FilePath path; | 
| - CHECK( | 
| - PathService::Get(chromeos::DIR_DEVICE_COLOR_CALIBRATION_PROFILES, &path)); | 
| - path = path.Append( | 
| - base::StringPrintf("%08" PRIx64 ".icc", snapshot->product_id())); | 
| - return path; | 
| + VLOG(1) << "Gamma data successfully read from icc file"; | 
| + return data; | 
| } | 
| } // namespace | 
| @@ -119,28 +118,21 @@ void DisplayColorManager::LoadCalibrationForDisplay( | 
| return; | 
| } | 
| - base::FilePath path = PathForDisplaySnapshot(display); | 
| - VLOG(1) << "Loading ICC file " << path.value() | 
| - << " for display id: " << display->display_id() | 
| - << " with product id: " << display->product_id(); | 
| - | 
| - scoped_ptr<ColorCalibrationData> data(new ColorCalibrationData()); | 
| - base::Callback<bool(void)> request( | 
| - base::Bind(&ParseFile, path, base::Unretained(data.get()))); | 
| + base::Callback<scoped_ptr<DisplayColorManager::ColorCalibrationData>(void)> | 
| 
 
stevenjb
2016/02/11 00:05:55
The DisplayColorManager:: is not needed here.
 
Greg Levin
2016/02/12 04:48:04
|request| variable removed and callback inlined, a
 
 | 
| + request(base::Bind(&ParseDisplayProfile, display->display_id(), | 
| + display->product_id())); | 
| base::PostTaskAndReplyWithResult( | 
| blocking_pool_, FROM_HERE, request, | 
| base::Bind(&DisplayColorManager::UpdateCalibrationData, AsWeakPtr(), | 
| - display->display_id(), display->product_id(), | 
| - base::Passed(std::move(data)))); | 
| + display->display_id(), display->product_id())); | 
| } | 
| void DisplayColorManager::UpdateCalibrationData( | 
| int64_t display_id, | 
| int64_t product_id, | 
| - scoped_ptr<ColorCalibrationData> data, | 
| - bool success) { | 
| + scoped_ptr<DisplayColorManager::ColorCalibrationData> data) { | 
| 
 
stevenjb
2016/02/11 00:05:55
DisplayColorManager:: not needed
 
Greg Levin
2016/02/12 04:48:04
Done.
 
 | 
| DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); | 
| - if (success) { | 
| + if (data) { | 
| // The map takes over ownership of the underlying memory. | 
| calibration_map_[product_id] = data.release(); | 
| ApplyDisplayColorCalibration(display_id, product_id); |