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

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: fix BitmapFetcher destruction Created 5 years, 8 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/bitmap_fetcher/bitmap_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/base/load_flags.h"
16 #include "net/url_request/url_fetcher.h" 17 #include "net/url_request/url_request.h"
17 #include "net/url_request/url_request_context_getter.h"
18 #include "net/url_request/url_request_status.h"
19 18
20 using content::BrowserThread; 19 using content::BrowserThread;
21 using content::UtilityProcessHost; 20 using content::UtilityProcessHost;
22 21
23 namespace { 22 namespace {
24 23
25 const char kImageDecodeError[] = "Image decode failed"; 24 const char kImageDecodeError[] = "Image decode failed";
26 25
27 } // namespace 26 } // namespace
28 27
29 namespace extensions { 28 namespace extensions {
30 29
31 WebstoreInstallHelper::WebstoreInstallHelper( 30 WebstoreInstallHelper::WebstoreInstallHelper(
32 Delegate* delegate, 31 Delegate* delegate,
33 const std::string& id, 32 const std::string& id,
34 const std::string& manifest, 33 const std::string& manifest,
35 const GURL& icon_url, 34 const GURL& icon_url,
36 net::URLRequestContextGetter* context_getter) 35 net::URLRequestContextGetter* context_getter)
37 : ImageRequest( 36 : delegate_(delegate),
38 content::BrowserThread::GetMessageLoopProxyForThread(
39 content::BrowserThread::IO)),
40 delegate_(delegate),
41 id_(id), 37 id_(id),
42 manifest_(manifest), 38 manifest_(manifest),
43 icon_url_(icon_url), 39 icon_url_(icon_url),
44 context_getter_(context_getter), 40 context_getter_(context_getter),
45 icon_decode_complete_(false), 41 icon_decode_complete_(false),
46 manifest_parse_complete_(false), 42 manifest_parse_complete_(false),
47 parse_error_(Delegate::UNKNOWN_ERROR) { 43 parse_error_(Delegate::UNKNOWN_ERROR) {
48 } 44 }
49 45
50 WebstoreInstallHelper::~WebstoreInstallHelper() {} 46 WebstoreInstallHelper::~WebstoreInstallHelper() {}
51 47
52 void WebstoreInstallHelper::Start() { 48 void WebstoreInstallHelper::Start() {
53 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 49 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
54 50
55 if (icon_url_.is_empty()) 51 if (icon_url_.is_empty()) {
56 icon_decode_complete_ = true; 52 icon_decode_complete_ = true;
53 } else {
54 icon_fetcher_.reset(new chrome::BitmapFetcher(icon_url_, this));
55 icon_fetcher_->Start(
56 context_getter_, std::string(),
57 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE,
58 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES);
59 }
57 60
58 BrowserThread::PostTask( 61 BrowserThread::PostTask(
59 BrowserThread::IO, 62 BrowserThread::IO,
60 FROM_HERE, 63 FROM_HERE,
61 base::Bind(&WebstoreInstallHelper::StartWorkOnIOThread, this)); 64 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 } 65 }
75 66
76 void WebstoreInstallHelper::StartWorkOnIOThread() { 67 void WebstoreInstallHelper::StartWorkOnIOThread() {
77 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 68 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
78 utility_host_ = UtilityProcessHost::Create( 69 utility_host_ = UtilityProcessHost::Create(
79 this, base::MessageLoopProxy::current().get())->AsWeakPtr(); 70 this, base::MessageLoopProxy::current().get())->AsWeakPtr();
80 utility_host_->StartBatchMode(); 71 utility_host_->StartBatchMode();
81 72
82 utility_host_->Send(new ChromeUtilityMsg_ParseJSON(manifest_)); 73 utility_host_->Send(new ChromeUtilityMsg_ParseJSON(manifest_));
83 } 74 }
84 75
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) { 76 bool WebstoreInstallHelper::OnMessageReceived(const IPC::Message& message) {
106 bool handled = true; 77 bool handled = true;
107 IPC_BEGIN_MESSAGE_MAP(WebstoreInstallHelper, message) 78 IPC_BEGIN_MESSAGE_MAP(WebstoreInstallHelper, message)
108 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Succeeded, 79 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Succeeded,
109 OnJSONParseSucceeded) 80 OnJSONParseSucceeded)
110 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Failed, 81 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Failed,
111 OnJSONParseFailed) 82 OnJSONParseFailed)
112 IPC_MESSAGE_UNHANDLED(handled = false) 83 IPC_MESSAGE_UNHANDLED(handled = false)
113 IPC_END_MESSAGE_MAP() 84 IPC_END_MESSAGE_MAP()
114 return handled; 85 return handled;
115 } 86 }
116 87
117 void WebstoreInstallHelper::OnImageDecoded(const SkBitmap& decoded_image) { 88 void WebstoreInstallHelper::OnFetchComplete(const GURL& url,
118 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 89 const SkBitmap* image) {
119 icon_ = decoded_image; 90 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
91 if (image)
92 icon_ = *image;
120 icon_decode_complete_ = true; 93 icon_decode_complete_ = true;
121 ReportResultsIfComplete(); 94 if (icon_.empty()) {
122 } 95 error_ = kImageDecodeError;
123 96 parse_error_ = Delegate::ICON_ERROR;
124 void WebstoreInstallHelper::OnDecodeImageFailed() { 97 }
125 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 98 icon_fetcher_.reset();
126 icon_decode_complete_ = true; 99 BrowserThread::PostTask(
127 error_ = kImageDecodeError; 100 BrowserThread::IO,
128 parse_error_ = Delegate::ICON_ERROR; 101 FROM_HERE,
129 ReportResultsIfComplete(); 102 base::Bind(&WebstoreInstallHelper::ReportResultsIfComplete, this));
130 } 103 }
131 104
132 void WebstoreInstallHelper::OnJSONParseSucceeded( 105 void WebstoreInstallHelper::OnJSONParseSucceeded(
133 const base::ListValue& wrapper) { 106 const base::ListValue& wrapper) {
134 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 107 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
135 manifest_parse_complete_ = true; 108 manifest_parse_complete_ = true;
136 const base::Value* value = NULL; 109 const base::Value* value = NULL;
137 CHECK(wrapper.Get(0, &value)); 110 CHECK(wrapper.Get(0, &value));
138 if (value->IsType(base::Value::TYPE_DICTIONARY)) { 111 if (value->IsType(base::Value::TYPE_DICTIONARY)) {
139 parsed_manifest_.reset( 112 parsed_manifest_.reset(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 146
174 void WebstoreInstallHelper::ReportResultFromUIThread() { 147 void WebstoreInstallHelper::ReportResultFromUIThread() {
175 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 148 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
176 if (error_.empty() && parsed_manifest_) 149 if (error_.empty() && parsed_manifest_)
177 delegate_->OnWebstoreParseSuccess(id_, icon_, parsed_manifest_.release()); 150 delegate_->OnWebstoreParseSuccess(id_, icon_, parsed_manifest_.release());
178 else 151 else
179 delegate_->OnWebstoreParseFailure(id_, parse_error_, error_); 152 delegate_->OnWebstoreParseFailure(id_, parse_error_, error_);
180 } 153 }
181 154
182 } // namespace extensions 155 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698