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

Side by Side Diff: components/arc/intent_helper/arc_intent_helper_bridge.cc

Issue 2061183002: arc: IPC method to set custom wallpaper. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add next IDs. Created 4 years, 6 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/arc/intent_helper/arc_intent_helper_bridge.h" 5 #include "components/arc/intent_helper/arc_intent_helper_bridge.h"
6 6
7 #include <memory>
8 #include <utility>
7 #include <vector> 9 #include <vector>
8 10
9 #include "ash/desktop_background/user_wallpaper_delegate.h" 11 #include "ash/desktop_background/user_wallpaper_delegate.h"
10 #include "ash/new_window_delegate.h" 12 #include "ash/new_window_delegate.h"
11 #include "ash/shell.h" 13 #include "ash/shell.h"
12 #include "ash/shell_delegate.h" 14 #include "ash/shell_delegate.h"
15 #include "base/bind.h"
13 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/task_runner_util.h"
14 #include "components/arc/intent_helper/activity_icon_loader.h" 18 #include "components/arc/intent_helper/activity_icon_loader.h"
15 #include "components/arc/intent_helper/link_handler_model_impl.h" 19 #include "components/arc/intent_helper/link_handler_model_impl.h"
20 #include "components/arc/set_wallpaper_delegate.h"
16 #include "ui/base/layout.h" 21 #include "ui/base/layout.h"
22 #include "ui/gfx/codec/jpeg_codec.h"
17 #include "url/gurl.h" 23 #include "url/gurl.h"
18 24
19 namespace arc { 25 namespace arc {
20 26
27 namespace {
28
29 gfx::ImageSkia DecodeJpegImage(mojo::Array<uint8_t> jpeg_data) {
30 std::unique_ptr<SkBitmap> bitmap = gfx::JPEGCodec::Decode(
Yusuke Sato 2016/06/15 16:12:49 qq: Is it safe/allowed to decode an arbitrary jpeg
Shuhei Takahashi 2016/06/15 18:14:37 Good point, maybe we must use ImageDecoder instead
31 static_cast<const unsigned char*>(&jpeg_data.storage()[0]),
32 jpeg_data.size());
33 bitmap->setImmutable();
34 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(*bitmap);
35 image.MakeThreadSafe();
36 return std::move(image);
37 }
38
39 } // namespace
40
21 ArcIntentHelperBridge::ArcIntentHelperBridge( 41 ArcIntentHelperBridge::ArcIntentHelperBridge(
22 ArcBridgeService* bridge_service, 42 ArcBridgeService* bridge_service,
23 const scoped_refptr<ActivityIconLoader>& icon_loader) 43 const scoped_refptr<ActivityIconLoader>& icon_loader,
24 : ArcService(bridge_service), binding_(this), icon_loader_(icon_loader) { 44 const scoped_refptr<base::TaskRunner>& blocking_task_runner,
45 std::unique_ptr<SetWallpaperDelegate> set_wallpaper_delegate)
46 : ArcService(bridge_service),
47 binding_(this),
48 icon_loader_(icon_loader),
49 blocking_task_runner_(blocking_task_runner),
50 set_wallpaper_delegate_(std::move(set_wallpaper_delegate)),
51 weak_factory_(this) {
52 DCHECK(thread_checker_.CalledOnValidThread());
25 arc_bridge_service()->AddObserver(this); 53 arc_bridge_service()->AddObserver(this);
26 } 54 }
27 55
28 ArcIntentHelperBridge::~ArcIntentHelperBridge() { 56 ArcIntentHelperBridge::~ArcIntentHelperBridge() {
57 DCHECK(thread_checker_.CalledOnValidThread());
29 arc_bridge_service()->RemoveObserver(this); 58 arc_bridge_service()->RemoveObserver(this);
30 } 59 }
31 60
32 void ArcIntentHelperBridge::OnIntentHelperInstanceReady() { 61 void ArcIntentHelperBridge::OnIntentHelperInstanceReady() {
62 DCHECK(thread_checker_.CalledOnValidThread());
33 ash::Shell::GetInstance()->set_link_handler_model_factory(this); 63 ash::Shell::GetInstance()->set_link_handler_model_factory(this);
34 arc_bridge_service()->intent_helper_instance()->Init( 64 arc_bridge_service()->intent_helper_instance()->Init(
35 binding_.CreateInterfacePtrAndBind()); 65 binding_.CreateInterfacePtrAndBind());
36 } 66 }
37 67
38 void ArcIntentHelperBridge::OnIntentHelperInstanceClosed() { 68 void ArcIntentHelperBridge::OnIntentHelperInstanceClosed() {
69 DCHECK(thread_checker_.CalledOnValidThread());
39 ash::Shell::GetInstance()->set_link_handler_model_factory(nullptr); 70 ash::Shell::GetInstance()->set_link_handler_model_factory(nullptr);
40 } 71 }
41 72
42 void ArcIntentHelperBridge::OnIconInvalidated( 73 void ArcIntentHelperBridge::OnIconInvalidated(
43 const mojo::String& package_name) { 74 const mojo::String& package_name) {
75 DCHECK(thread_checker_.CalledOnValidThread());
44 icon_loader_->InvalidateIcons(package_name); 76 icon_loader_->InvalidateIcons(package_name);
45 } 77 }
46 78
47 void ArcIntentHelperBridge::OnOpenDownloads() { 79 void ArcIntentHelperBridge::OnOpenDownloads() {
80 DCHECK(thread_checker_.CalledOnValidThread());
48 // TODO(607411): If the FileManager is not yet open this will open to 81 // TODO(607411): If the FileManager is not yet open this will open to
49 // downloads by default, which is what we want. However if it is open it will 82 // downloads by default, which is what we want. However if it is open it will
50 // simply be brought to the forgeground without forcibly being navigated to 83 // simply be brought to the forgeground without forcibly being navigated to
51 // downloads, which is probably not ideal. 84 // downloads, which is probably not ideal.
52 ash::Shell::GetInstance()->new_window_delegate()->OpenFileManager(); 85 ash::Shell::GetInstance()->new_window_delegate()->OpenFileManager();
53 } 86 }
54 87
55 void ArcIntentHelperBridge::OnOpenUrl(const mojo::String& url) { 88 void ArcIntentHelperBridge::OnOpenUrl(const mojo::String& url) {
89 DCHECK(thread_checker_.CalledOnValidThread());
56 GURL gurl(url.get()); 90 GURL gurl(url.get());
57 ash::Shell::GetInstance()->delegate()->OpenUrl(gurl); 91 ash::Shell::GetInstance()->delegate()->OpenUrl(gurl);
58 } 92 }
59 93
60 void ArcIntentHelperBridge::OpenWallpaperPicker() { 94 void ArcIntentHelperBridge::OpenWallpaperPicker() {
95 DCHECK(thread_checker_.CalledOnValidThread());
61 ash::Shell::GetInstance()->user_wallpaper_delegate()->OpenSetWallpaperPage(); 96 ash::Shell::GetInstance()->user_wallpaper_delegate()->OpenSetWallpaperPage();
62 } 97 }
63 98
99 void ArcIntentHelperBridge::SetWallpaper(mojo::Array<uint8_t> jpeg_data) {
100 DCHECK(thread_checker_.CalledOnValidThread());
101 base::PostTaskAndReplyWithResult(
102 blocking_task_runner_.get(), FROM_HERE,
103 base::Bind(&DecodeJpegImage, base::Passed(std::move(jpeg_data))),
104 base::Bind(&ArcIntentHelperBridge::SetImageAsWallpaper,
105 weak_factory_.GetWeakPtr()));
106 }
107
64 std::unique_ptr<ash::LinkHandlerModel> ArcIntentHelperBridge::CreateModel( 108 std::unique_ptr<ash::LinkHandlerModel> ArcIntentHelperBridge::CreateModel(
65 const GURL& url) { 109 const GURL& url) {
66 std::unique_ptr<LinkHandlerModelImpl> impl( 110 std::unique_ptr<LinkHandlerModelImpl> impl(
Yusuke Sato 2016/06/15 16:45:01 You can add the same DCHECK here if you want. It's
Shuhei Takahashi 2016/06/15 18:14:37 Done.
67 new LinkHandlerModelImpl(icon_loader_)); 111 new LinkHandlerModelImpl(icon_loader_));
68 if (!impl->Init(url)) 112 if (!impl->Init(url))
69 return nullptr; 113 return nullptr;
70 return std::move(impl); 114 return std::move(impl);
71 } 115 }
72 116
117 void ArcIntentHelperBridge::SetImageAsWallpaper(gfx::ImageSkia image) {
118 DCHECK(thread_checker_.CalledOnValidThread());
119 set_wallpaper_delegate_->SetWallpaper(image);
120 }
121
73 } // namespace arc 122 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698