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

Unified Diff: components/wallpaper/wallpaper_color_calculator.cc

Issue 2679133003: [ash-md] Wired in the Shelf color to be derived from the Wallpaper. (Closed)
Patch Set: Addressed nits. Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: components/wallpaper/wallpaper_color_calculator.cc
diff --git a/components/wallpaper/wallpaper_color_calculator.cc b/components/wallpaper/wallpaper_color_calculator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0096d5d19161120856ab32d3931036ce9db9d7ad
--- /dev/null
+++ b/components/wallpaper/wallpaper_color_calculator.cc
@@ -0,0 +1,77 @@
+// 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 "components/wallpaper/wallpaper_color_calculator.h"
+
+#include <string>
+#include <utility>
+
+#include "base/bind.h"
+#include "base/metrics/histogram_macros.h"
+#include "base/task_runner.h"
+#include "base/task_runner_util.h"
+
+namespace wallpaper {
+
+WallpaperColorCalculator::WallpaperColorCalculator(
+ const gfx::ImageSkia& image,
+ color_utils::LumaRange luma,
+ color_utils::SaturationRange saturation,
+ scoped_refptr<base::TaskRunner> task_runner)
+ : image_(image),
+ luma_(luma),
+ saturation_(saturation),
+ task_runner_(std::move(task_runner)),
+ weak_ptr_factory_(this) {}
+
+WallpaperColorCalculator::~WallpaperColorCalculator() {}
+
+void WallpaperColorCalculator::AddObserver(
+ WallpaperColorCalculatorObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void WallpaperColorCalculator::RemoveObserver(
+ WallpaperColorCalculatorObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+bool WallpaperColorCalculator::StartCalculation() {
+ start_calculation_time_ = base::Time::Now();
+
+ image_.MakeThreadSafe();
+ if (base::PostTaskAndReplyWithResult(
+ task_runner_.get(), FROM_HERE,
+ base::Bind(&color_utils::CalculateProminentColorOfBitmap,
+ *image_.bitmap(), luma_, saturation_),
+ base::Bind(&WallpaperColorCalculator::NotifyCalculationComplete,
+ weak_ptr_factory_.GetWeakPtr()))) {
+ return true;
+ }
+
+ LOG(WARNING) << "PostSequencedWorkerTask failed. "
+ << "Wallpaper promiment color may not be calculated.";
+
+ prominent_color_ = SK_ColorTRANSPARENT;
+ return false;
+}
+
+void WallpaperColorCalculator::SetTaskRunnerForTest(
+ scoped_refptr<base::TaskRunner> task_runner) {
+ task_runner_ = task_runner;
+}
+
+void WallpaperColorCalculator::NotifyCalculationComplete(
+ SkColor prominent_color) {
+ UMA_HISTOGRAM_MEDIUM_TIMES("Ash.Wallpaper.TimeSpentExtractingColors",
+ base::Time::Now() - start_calculation_time_);
+
+ prominent_color_ = prominent_color;
+ for (auto& observer : observers_)
+ observer.OnColorCalculationComplete();
+
+ // This could be deleted!
+}
+
+} // namespace wallpaper
« no previous file with comments | « components/wallpaper/wallpaper_color_calculator.h ('k') | components/wallpaper/wallpaper_color_calculator_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698