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

Side by Side Diff: chrome/browser/extensions/webstore_install_helper.cc

Issue 865543002: WIP: Browser image decoding using Mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup and add DecodeImageBase64. Created 5 years, 11 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
« no previous file with comments | « chrome/browser/extensions/webstore_install_helper.h ('k') | chrome/browser/image_decoder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/extensions/webstore_install_helper.h" 5 #include "chrome/browser/extensions/webstore_install_helper.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/image_decoder.h"
11 #include "chrome/common/chrome_utility_messages.h" 12 #include "chrome/common/chrome_utility_messages.h"
12 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" 13 #include "chrome/common/extensions/chrome_utility_extensions_messages.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/utility_process_host.h" 15 #include "content/public/browser/utility_process_host.h"
16 #include "content/public/common/service_registry.h"
15 #include "net/base/load_flags.h" 17 #include "net/base/load_flags.h"
16 #include "net/url_request/url_fetcher.h" 18 #include "net/url_request/url_fetcher.h"
17 #include "net/url_request/url_request_context_getter.h" 19 #include "net/url_request/url_request_context_getter.h"
18 #include "net/url_request/url_request_status.h" 20 #include "net/url_request/url_request_status.h"
19 21
20 using content::BrowserThread; 22 using content::BrowserThread;
21 using content::UtilityProcessHost; 23 using content::UtilityProcessHost;
22 24
23 namespace { 25 namespace {
24 26
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 url_fetcher_->SetRequestContext(context_getter_); 68 url_fetcher_->SetRequestContext(context_getter_);
67 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | 69 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
68 net::LOAD_DO_NOT_SEND_COOKIES); 70 net::LOAD_DO_NOT_SEND_COOKIES);
69 71
70 url_fetcher_->Start(); 72 url_fetcher_->Start();
71 // We'll get called back in OnURLFetchComplete. 73 // We'll get called back in OnURLFetchComplete.
72 } 74 }
73 } 75 }
74 76
75 void WebstoreInstallHelper::StartWorkOnIOThread() { 77 void WebstoreInstallHelper::StartWorkOnIOThread() {
78 LOG(INFO) << "WebstoreInstallHelper::StartWorkOnIOThread";
76 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 79 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
77 utility_host_ = UtilityProcessHost::Create( 80 utility_host_ = UtilityProcessHost::Create(
78 this, base::MessageLoopProxy::current().get())->AsWeakPtr(); 81 this, base::MessageLoopProxy::current().get())->AsWeakPtr();
82 utility_host_->StartMojoMode();
79 utility_host_->StartBatchMode(); 83 utility_host_->StartBatchMode();
84 content::ServiceRegistry* service_registry =
85 utility_host_->GetServiceRegistry();
86 service_registry->ConnectToRemoteService(&image_decoder_);
80 87
81 if (!icon_base64_data_.empty()) 88 if (!icon_base64_data_.empty()) {
82 utility_host_->Send( 89 LOG(INFO) << "DecodeImageBase64";
83 new ChromeUtilityMsg_DecodeImageBase64(icon_base64_data_)); 90 image_decoder_->DecodeImageBase64(
91 icon_base64_data_,
92 base::Bind(&WebstoreInstallHelper::OnDecodeImageDone, this));
93 }
84 94
85 utility_host_->Send(new ChromeUtilityMsg_ParseJSON(manifest_)); 95 utility_host_->Send(new ChromeUtilityMsg_ParseJSON(manifest_));
86 } 96 }
87 97
88 void WebstoreInstallHelper::OnURLFetchComplete( 98 void WebstoreInstallHelper::OnURLFetchComplete(
89 const net::URLFetcher* source) { 99 const net::URLFetcher* source) {
90 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 100 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
91 CHECK(source == url_fetcher_.get()); 101 CHECK(source == url_fetcher_.get());
92 int response_code = 102 int response_code =
93 source->GetStatus().is_success() ? source->GetResponseCode() : 0; 103 source->GetStatus().is_success() ? source->GetResponseCode() : 0;
94 if (!source->GetStatus().is_success() || 104 if (!source->GetStatus().is_success() ||
95 response_code / 100 == 4 || response_code / 100 == 5) { 105 response_code / 100 == 4 || response_code / 100 == 5) {
96 BrowserThread::PostTask( 106 BrowserThread::PostTask(
97 BrowserThread::IO, 107 BrowserThread::IO,
98 FROM_HERE, 108 FROM_HERE,
99 base::Bind(&WebstoreInstallHelper::OnDecodeImageFailed, this)); 109 base::Bind(&WebstoreInstallHelper::OnDecodeImageDone,
110 this,
111 false,
112 nullptr));
100 } else { 113 } else {
101 std::string response_data; 114 std::string response_data;
102 source->GetResponseAsString(&response_data); 115 source->GetResponseAsString(&response_data);
103 fetched_icon_data_.insert(fetched_icon_data_.begin(), 116 fetched_icon_data_.insert(fetched_icon_data_.begin(),
104 response_data.begin(), 117 response_data.begin(),
105 response_data.end()); 118 response_data.end());
106 BrowserThread::PostTask( 119 BrowserThread::PostTask(
107 BrowserThread::IO, 120 BrowserThread::IO,
108 FROM_HERE, 121 FROM_HERE,
109 base::Bind(&WebstoreInstallHelper::StartFetchedImageDecode, this)); 122 base::Bind(&WebstoreInstallHelper::StartFetchedImageDecode, this));
110 } 123 }
111 url_fetcher_.reset(); 124 url_fetcher_.reset();
112 } 125 }
113 126
114 void WebstoreInstallHelper::StartFetchedImageDecode() { 127 void WebstoreInstallHelper::StartFetchedImageDecode() {
115 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 128 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
116 CHECK(utility_host_.get()); 129 CHECK(utility_host_.get());
117 utility_host_->Send(new ChromeUtilityMsg_DecodeImage(fetched_icon_data_, 130 image_decoder_->DecodeImage(
118 false)); 131 mojo::Array<uint8_t>::From(fetched_icon_data_),
132 false,
133 false,
134 base::Bind(&WebstoreInstallHelper::OnDecodeImageDone, this));
119 } 135 }
120 136
121 137
122 bool WebstoreInstallHelper::OnMessageReceived(const IPC::Message& message) { 138 bool WebstoreInstallHelper::OnMessageReceived(const IPC::Message& message) {
123 bool handled = true; 139 bool handled = true;
124 IPC_BEGIN_MESSAGE_MAP(WebstoreInstallHelper, message) 140 IPC_BEGIN_MESSAGE_MAP(WebstoreInstallHelper, message)
125 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DecodeImage_Succeeded,
126 OnDecodeImageSucceeded)
127 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DecodeImage_Failed,
128 OnDecodeImageFailed)
129 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Succeeded, 141 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Succeeded,
130 OnJSONParseSucceeded) 142 OnJSONParseSucceeded)
131 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Failed, 143 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Failed,
132 OnJSONParseFailed) 144 OnJSONParseFailed)
133 IPC_MESSAGE_UNHANDLED(handled = false) 145 IPC_MESSAGE_UNHANDLED(handled = false)
134 IPC_END_MESSAGE_MAP() 146 IPC_END_MESSAGE_MAP()
135 return handled; 147 return handled;
136 } 148 }
137 149
138 150 void WebstoreInstallHelper::OnDecodeImageDone(bool success,
139 void WebstoreInstallHelper::OnDecodeImageSucceeded( 151 content::ImageDataPtr image) {
140 const SkBitmap& decoded_image) { 152 LOG(INFO) << "WebstoreInstallHelper::OnDecodeImageDone: " << success;
141 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 153 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
142 icon_ = decoded_image; 154 if (success && image) {
155 icon_ = image.To<SkBitmap>();
156 } else {
157 error_ = kImageDecodeError;
158 parse_error_ = Delegate::ICON_ERROR;
159 }
143 icon_decode_complete_ = true; 160 icon_decode_complete_ = true;
144 ReportResultsIfComplete(); 161 ReportResultsIfComplete();
145 } 162 }
146 163
147 void WebstoreInstallHelper::OnDecodeImageFailed() {
148 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
149 icon_decode_complete_ = true;
150 error_ = kImageDecodeError;
151 parse_error_ = Delegate::ICON_ERROR;
152 ReportResultsIfComplete();
153 }
154
155 void WebstoreInstallHelper::OnJSONParseSucceeded( 164 void WebstoreInstallHelper::OnJSONParseSucceeded(
156 const base::ListValue& wrapper) { 165 const base::ListValue& wrapper) {
157 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 166 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
158 manifest_parse_complete_ = true; 167 manifest_parse_complete_ = true;
159 const base::Value* value = NULL; 168 const base::Value* value = NULL;
160 CHECK(wrapper.Get(0, &value)); 169 CHECK(wrapper.Get(0, &value));
161 if (value->IsType(base::Value::TYPE_DICTIONARY)) { 170 if (value->IsType(base::Value::TYPE_DICTIONARY)) {
162 parsed_manifest_.reset( 171 parsed_manifest_.reset(
163 static_cast<const base::DictionaryValue*>(value)->DeepCopy()); 172 static_cast<const base::DictionaryValue*>(value)->DeepCopy());
164 } else { 173 } else {
(...skipping 14 matching lines...) Expand all
179 void WebstoreInstallHelper::ReportResultsIfComplete() { 188 void WebstoreInstallHelper::ReportResultsIfComplete() {
180 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 189 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
181 190
182 if (!icon_decode_complete_ || !manifest_parse_complete_) 191 if (!icon_decode_complete_ || !manifest_parse_complete_)
183 return; 192 return;
184 193
185 // The utility_host_ will take care of deleting itself after this call. 194 // The utility_host_ will take care of deleting itself after this call.
186 if (utility_host_.get()) { 195 if (utility_host_.get()) {
187 utility_host_->EndBatchMode(); 196 utility_host_->EndBatchMode();
188 utility_host_.reset(); 197 utility_host_.reset();
198 image_decoder_.reset();
189 } 199 }
190 200
191 BrowserThread::PostTask( 201 BrowserThread::PostTask(
192 BrowserThread::UI, 202 BrowserThread::UI,
193 FROM_HERE, 203 FROM_HERE,
194 base::Bind(&WebstoreInstallHelper::ReportResultFromUIThread, this)); 204 base::Bind(&WebstoreInstallHelper::ReportResultFromUIThread, this));
195 } 205 }
196 206
197 void WebstoreInstallHelper::ReportResultFromUIThread() { 207 void WebstoreInstallHelper::ReportResultFromUIThread() {
198 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 208 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
199 if (error_.empty() && parsed_manifest_) 209 if (error_.empty() && parsed_manifest_)
200 delegate_->OnWebstoreParseSuccess(id_, icon_, parsed_manifest_.release()); 210 delegate_->OnWebstoreParseSuccess(id_, icon_, parsed_manifest_.release());
201 else 211 else
202 delegate_->OnWebstoreParseFailure(id_, parse_error_, error_); 212 delegate_->OnWebstoreParseFailure(id_, parse_error_, error_);
203 } 213 }
204 214
205 } // namespace extensions 215 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/webstore_install_helper.h ('k') | chrome/browser/image_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698