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

Side by Side Diff: content/child/notifications/notification_image_loader.cc

Issue 1644083002: Fetch notification action icons and pass them through in resources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ActionIconBlink
Patch Set: Rebase. Created 4 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/child/notifications/notification_image_loader.h" 5 #include "content/child/notifications/notification_image_loader.h"
6 6
7 #include "base/bind.h"
8 #include "base/location.h"
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "base/thread_task_runner_handle.h" 10 #include "base/single_thread_task_runner.h"
9 #include "content/child/child_thread_impl.h"
10 #include "content/child/image_decoder.h" 11 #include "content/child/image_decoder.h"
11 #include "third_party/WebKit/public/platform/Platform.h" 12 #include "third_party/WebKit/public/platform/Platform.h"
12 #include "third_party/WebKit/public/platform/WebURL.h" 13 #include "third_party/WebKit/public/platform/WebURL.h"
13 #include "third_party/WebKit/public/platform/WebURLLoader.h" 14 #include "third_party/WebKit/public/platform/WebURLLoader.h"
14 #include "third_party/WebKit/public/platform/WebURLRequest.h" 15 #include "third_party/WebKit/public/platform/WebURLRequest.h"
15 #include "third_party/skia/include/core/SkBitmap.h" 16 #include "third_party/skia/include/core/SkBitmap.h"
16 17
17 using blink::WebURL; 18 using blink::WebURL;
18 using blink::WebURLError; 19 using blink::WebURLError;
19 using blink::WebURLLoader; 20 using blink::WebURLLoader;
20 using blink::WebURLRequest; 21 using blink::WebURLRequest;
21 22
22 namespace content { 23 namespace content {
23 24
24 NotificationImageLoader::NotificationImageLoader( 25 NotificationImageLoader::NotificationImageLoader(
25 const ImageLoadCompletedCallback& callback, 26 const ImageLoadCompletedCallback& callback,
26 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner) 27 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner,
28 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner)
27 : callback_(callback), 29 : callback_(callback),
28 worker_task_runner_(worker_task_runner), 30 worker_task_runner_(worker_task_runner),
29 notification_id_(0), 31 main_task_runner_(main_task_runner),
30 completed_(false) {} 32 completed_(false) {}
31 33
32 NotificationImageLoader::~NotificationImageLoader() { 34 NotificationImageLoader::~NotificationImageLoader() {
33 if (main_thread_task_runner_) 35 DCHECK(main_task_runner_->BelongsToCurrentThread());
34 DCHECK(main_thread_task_runner_->BelongsToCurrentThread());
35 } 36 }
36 37
37 void NotificationImageLoader::StartOnMainThread(int notification_id, 38 void NotificationImageLoader::StartOnMainThread(const GURL& image_url) {
38 const GURL& image_url) { 39 DCHECK(main_task_runner_->BelongsToCurrentThread());
39 DCHECK(ChildThreadImpl::current());
40 DCHECK(!url_loader_); 40 DCHECK(!url_loader_);
41 41
42 main_thread_task_runner_ = base::ThreadTaskRunnerHandle::Get();
43 notification_id_ = notification_id;
44
45 WebURL image_web_url(image_url); 42 WebURL image_web_url(image_url);
46 WebURLRequest request(image_web_url); 43 WebURLRequest request(image_web_url);
47 request.setRequestContext(WebURLRequest::RequestContextImage); 44 request.setRequestContext(WebURLRequest::RequestContextImage);
48 45
49 url_loader_.reset(blink::Platform::current()->createURLLoader()); 46 url_loader_.reset(blink::Platform::current()->createURLLoader());
50 url_loader_->loadAsynchronously(request, this); 47 url_loader_->loadAsynchronously(request, this);
51 } 48 }
52 49
53 void NotificationImageLoader::didReceiveData(WebURLLoader* loader, 50 void NotificationImageLoader::didReceiveData(WebURLLoader* loader,
54 const char* data, 51 const char* data,
(...skipping 22 matching lines...) Expand all
77 RunCallbackOnWorkerThread(); 74 RunCallbackOnWorkerThread();
78 } 75 }
79 76
80 void NotificationImageLoader::RunCallbackOnWorkerThread() { 77 void NotificationImageLoader::RunCallbackOnWorkerThread() {
81 url_loader_.reset(); 78 url_loader_.reset();
82 79
83 completed_ = true; 80 completed_ = true;
84 SkBitmap icon = GetDecodedImage(); 81 SkBitmap icon = GetDecodedImage();
85 82
86 if (worker_task_runner_->BelongsToCurrentThread()) { 83 if (worker_task_runner_->BelongsToCurrentThread()) {
87 callback_.Run(notification_id_, icon); 84 callback_.Run(icon);
88 } else { 85 } else {
89 worker_task_runner_->PostTask( 86 worker_task_runner_->PostTask(FROM_HERE, base::Bind(callback_, icon));
90 FROM_HERE, base::Bind(callback_, notification_id_, icon));
91 } 87 }
92 } 88 }
93 89
94 SkBitmap NotificationImageLoader::GetDecodedImage() const { 90 SkBitmap NotificationImageLoader::GetDecodedImage() const {
95 DCHECK(completed_); 91 DCHECK(completed_);
96 if (buffer_.empty()) 92 if (buffer_.empty())
97 return SkBitmap(); 93 return SkBitmap();
98 94
99 ImageDecoder decoder; 95 ImageDecoder decoder;
100 return decoder.Decode(&buffer_[0], buffer_.size()); 96 return decoder.Decode(&buffer_[0], buffer_.size());
101 } 97 }
102 98
103 void NotificationImageLoader::DeleteOnCorrectThread() const { 99 void NotificationImageLoader::DeleteOnCorrectThread() const {
104 if (!ChildThreadImpl::current()) { 100 if (!main_task_runner_->BelongsToCurrentThread()) {
105 main_thread_task_runner_->DeleteSoon(FROM_HERE, this); 101 main_task_runner_->DeleteSoon(FROM_HERE, this);
106 return; 102 return;
107 } 103 }
108 104
109 delete this; 105 delete this;
110 } 106 }
111 107
112 } // namespace content 108 } // namespace content
OLDNEW
« no previous file with comments | « content/child/notifications/notification_image_loader.h ('k') | content/child/notifications/notification_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698