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

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

Issue 855513002: Add/resurrect support for bundles of WebStore items. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@testext_bundle
Patch Set: remove icon_data Created 5 years, 9 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 (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/safe_image_fetcher.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"
15 #include "net/base/load_flags.h"
16 #include "net/url_request/url_fetcher.h"
17 #include "net/url_request/url_request_context_getter.h"
18 #include "net/url_request/url_request_status.h"
19 16
20 using content::BrowserThread; 17 using content::BrowserThread;
21 using content::UtilityProcessHost; 18 using content::UtilityProcessHost;
22 19
23 namespace { 20 namespace {
24 21
25 const char kImageDecodeError[] = "Image decode failed"; 22 const char kImageDecodeError[] = "Image decode failed";
26 23
27 } // namespace 24 } // namespace
28 25
29 namespace extensions { 26 namespace extensions {
30 27
31 WebstoreInstallHelper::WebstoreInstallHelper( 28 WebstoreInstallHelper::WebstoreInstallHelper(
32 Delegate* delegate, 29 Delegate* delegate,
33 const std::string& id, 30 const std::string& id,
34 const std::string& manifest, 31 const std::string& manifest,
35 const GURL& icon_url, 32 const GURL& icon_url,
36 net::URLRequestContextGetter* context_getter) 33 net::URLRequestContextGetter* context_getter)
37 : ImageRequest( 34 : delegate_(delegate),
38 content::BrowserThread::GetMessageLoopProxyForThread(
39 content::BrowserThread::IO)),
40 delegate_(delegate),
41 id_(id), 35 id_(id),
42 manifest_(manifest), 36 manifest_(manifest),
43 icon_url_(icon_url), 37 icon_url_(icon_url),
44 context_getter_(context_getter), 38 context_getter_(context_getter),
45 icon_decode_complete_(false), 39 icon_decode_complete_(false),
46 manifest_parse_complete_(false), 40 manifest_parse_complete_(false),
47 parse_error_(Delegate::UNKNOWN_ERROR) { 41 parse_error_(Delegate::UNKNOWN_ERROR) {
48 } 42 }
49 43
50 WebstoreInstallHelper::~WebstoreInstallHelper() {} 44 WebstoreInstallHelper::~WebstoreInstallHelper() {}
51 45
52 void WebstoreInstallHelper::Start() { 46 void WebstoreInstallHelper::Start() {
53 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 47 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
54 48
55 if (icon_url_.is_empty()) 49 if (icon_url_.is_empty()) {
56 icon_decode_complete_ = true; 50 icon_decode_complete_ = true;
51 } else {
52 icon_fetcher_.reset(new SafeImageFetcher(
53 icon_url_, context_getter_,
54 base::Bind(&WebstoreInstallHelper::OnIconFetched,
55 base::Unretained(this))));
asargent_no_longer_on_chrome 2015/03/26 18:12:50 I don't think you want base::Unretained here, righ
Marc Treib 2015/03/27 11:52:12 Done.
56 }
57 57
58 BrowserThread::PostTask( 58 BrowserThread::PostTask(
59 BrowserThread::IO, 59 BrowserThread::IO,
60 FROM_HERE, 60 FROM_HERE,
61 base::Bind(&WebstoreInstallHelper::StartWorkOnIOThread, this)); 61 base::Bind(&WebstoreInstallHelper::StartWorkOnIOThread, this));
62
63 if (!icon_url_.is_empty()) {
64 CHECK(context_getter_);
65 url_fetcher_.reset(net::URLFetcher::Create(
66 icon_url_, net::URLFetcher::GET, this));
67 url_fetcher_->SetRequestContext(context_getter_);
68 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
69 net::LOAD_DO_NOT_SEND_COOKIES);
70
71 url_fetcher_->Start();
72 // We'll get called back in OnURLFetchComplete.
73 }
74 } 62 }
75 63
76 void WebstoreInstallHelper::StartWorkOnIOThread() { 64 void WebstoreInstallHelper::StartWorkOnIOThread() {
77 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 65 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
78 utility_host_ = UtilityProcessHost::Create( 66 utility_host_ = UtilityProcessHost::Create(
79 this, base::MessageLoopProxy::current().get())->AsWeakPtr(); 67 this, base::MessageLoopProxy::current().get())->AsWeakPtr();
80 utility_host_->StartBatchMode(); 68 utility_host_->StartBatchMode();
81 69
82 utility_host_->Send(new ChromeUtilityMsg_ParseJSON(manifest_)); 70 utility_host_->Send(new ChromeUtilityMsg_ParseJSON(manifest_));
83 } 71 }
84 72
85 void WebstoreInstallHelper::OnURLFetchComplete(
86 const net::URLFetcher* source) {
87 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
88 CHECK(source == url_fetcher_.get());
89 int response_code =
90 source->GetStatus().is_success() ? source->GetResponseCode() : 0;
91 if (!source->GetStatus().is_success() ||
92 response_code / 100 == 4 || response_code / 100 == 5) {
93 BrowserThread::PostTask(
94 BrowserThread::IO, FROM_HERE,
95 base::Bind(&WebstoreInstallHelper::OnDecodeImageFailed, this));
96 } else {
97 std::string response_data;
98 source->GetResponseAsString(&response_data);
99
100 ImageDecoder::Start(this, response_data);
101 }
102 url_fetcher_.reset();
103 }
104
105 bool WebstoreInstallHelper::OnMessageReceived(const IPC::Message& message) { 73 bool WebstoreInstallHelper::OnMessageReceived(const IPC::Message& message) {
106 bool handled = true; 74 bool handled = true;
107 IPC_BEGIN_MESSAGE_MAP(WebstoreInstallHelper, message) 75 IPC_BEGIN_MESSAGE_MAP(WebstoreInstallHelper, message)
108 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Succeeded, 76 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Succeeded,
109 OnJSONParseSucceeded) 77 OnJSONParseSucceeded)
110 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Failed, 78 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Failed,
111 OnJSONParseFailed) 79 OnJSONParseFailed)
112 IPC_MESSAGE_UNHANDLED(handled = false) 80 IPC_MESSAGE_UNHANDLED(handled = false)
113 IPC_END_MESSAGE_MAP() 81 IPC_END_MESSAGE_MAP()
114 return handled; 82 return handled;
115 } 83 }
116 84
117 void WebstoreInstallHelper::OnImageDecoded(const SkBitmap& decoded_image) { 85 void WebstoreInstallHelper::OnIconFetched(const SkBitmap& icon) {
118 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 86 icon_ = icon;
119 icon_ = decoded_image;
120 icon_decode_complete_ = true; 87 icon_decode_complete_ = true;
121 ReportResultsIfComplete(); 88 if (icon_.empty()) {
122 } 89 error_ = kImageDecodeError;
123 90 parse_error_ = Delegate::ICON_ERROR;
124 void WebstoreInstallHelper::OnDecodeImageFailed() { 91 }
125 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 92 BrowserThread::PostTask(
126 icon_decode_complete_ = true; 93 BrowserThread::IO,
127 error_ = kImageDecodeError; 94 FROM_HERE,
128 parse_error_ = Delegate::ICON_ERROR; 95 base::Bind(&WebstoreInstallHelper::ReportResultsIfComplete, this));
129 ReportResultsIfComplete();
130 } 96 }
131 97
132 void WebstoreInstallHelper::OnJSONParseSucceeded( 98 void WebstoreInstallHelper::OnJSONParseSucceeded(
133 const base::ListValue& wrapper) { 99 const base::ListValue& wrapper) {
134 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 100 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
135 manifest_parse_complete_ = true; 101 manifest_parse_complete_ = true;
136 const base::Value* value = NULL; 102 const base::Value* value = NULL;
137 CHECK(wrapper.Get(0, &value)); 103 CHECK(wrapper.Get(0, &value));
138 if (value->IsType(base::Value::TYPE_DICTIONARY)) { 104 if (value->IsType(base::Value::TYPE_DICTIONARY)) {
139 parsed_manifest_.reset( 105 parsed_manifest_.reset(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 139
174 void WebstoreInstallHelper::ReportResultFromUIThread() { 140 void WebstoreInstallHelper::ReportResultFromUIThread() {
175 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 141 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
176 if (error_.empty() && parsed_manifest_) 142 if (error_.empty() && parsed_manifest_)
177 delegate_->OnWebstoreParseSuccess(id_, icon_, parsed_manifest_.release()); 143 delegate_->OnWebstoreParseSuccess(id_, icon_, parsed_manifest_.release());
178 else 144 else
179 delegate_->OnWebstoreParseFailure(id_, parse_error_, error_); 145 delegate_->OnWebstoreParseFailure(id_, parse_error_, error_);
180 } 146 }
181 147
182 } // namespace extensions 148 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698