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

Side by Side 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: Ready for review. 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 unified diff | Download patch
OLDNEW
(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 "components/wallpaper/wallpaper_color_calculator.h"
6
7 #include <string>
8 #include <utility>
9
10 #include "base/bind.h"
11 #include "base/task_runner.h"
12 #include "base/task_runner_util.h"
13
14 namespace wallpaper {
15
16 WallpaperColorCalculator::WallpaperColorCalculator(
17 const gfx::ImageSkia& image,
18 color_utils::LumaRange luma,
19 color_utils::SaturationRange saturation,
20 scoped_refptr<base::TaskRunner> task_runner)
21 : image_(image),
22 luma_(luma),
23 saturation_(saturation),
24 task_runner_(std::move(task_runner)),
25 weak_ptr_factory_(this) {}
26
27 WallpaperColorCalculator::~WallpaperColorCalculator() {}
28
29 void WallpaperColorCalculator::AddObserver(
30 WallpaperColorCalculatorObserver* observer) {
31 observers_.AddObserver(observer);
32 }
33
34 void WallpaperColorCalculator::RemoveObserver(
35 WallpaperColorCalculatorObserver* observer) {
36 observers_.RemoveObserver(observer);
37 }
38
39 bool WallpaperColorCalculator::StartCalculation() {
40 image_.MakeThreadSafe();
41 if (base::PostTaskAndReplyWithResult(
42 task_runner_.get(), FROM_HERE,
43 base::Bind(&color_utils::CalculateProminentColorOfBitmap,
44 *image_.bitmap(), luma_, saturation_),
45 base::Bind(&WallpaperColorCalculator::NotifyCalculationComplete,
46 weak_ptr_factory_.GetWeakPtr()))) {
47 return true;
48 }
49
50 LOG(WARNING) << "PostSequencedWorkerTask failed. "
51 << "Wallpaper promiment color may not be calculated.";
52
53 prominent_color_ = SK_ColorTRANSPARENT;
54 return false;
55 }
56
57 void WallpaperColorCalculator::SetTaskRunnerForTest(
58 scoped_refptr<base::TaskRunner> task_runner) {
59 task_runner_ = task_runner;
60 }
61
62 void WallpaperColorCalculator::NotifyCalculationComplete(
63 SkColor prominent_color) {
64 prominent_color_ = prominent_color;
65 for (auto& observer : observers_)
66 observer.OnColorCalculationComplete();
67 }
68
69 } // namespace wallpaper
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698