| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 const std::string& manifest, | 28 const std::string& manifest, |
| 29 const std::string& icon_data, | 29 const std::string& icon_data, |
| 30 const GURL& icon_url, | 30 const GURL& icon_url, |
| 31 net::URLRequestContextGetter* context_getter) | 31 net::URLRequestContextGetter* context_getter) |
| 32 : delegate_(delegate), | 32 : delegate_(delegate), |
| 33 id_(id), | 33 id_(id), |
| 34 manifest_(manifest), | 34 manifest_(manifest), |
| 35 icon_base64_data_(icon_data), | 35 icon_base64_data_(icon_data), |
| 36 icon_url_(icon_url), | 36 icon_url_(icon_url), |
| 37 context_getter_(context_getter), | 37 context_getter_(context_getter), |
| 38 utility_host_(NULL), | |
| 39 icon_decode_complete_(false), | 38 icon_decode_complete_(false), |
| 40 manifest_parse_complete_(false), | 39 manifest_parse_complete_(false), |
| 41 parse_error_(Delegate::UNKNOWN_ERROR) {} | 40 parse_error_(Delegate::UNKNOWN_ERROR) {} |
| 42 | 41 |
| 43 WebstoreInstallHelper::~WebstoreInstallHelper() {} | 42 WebstoreInstallHelper::~WebstoreInstallHelper() {} |
| 44 | 43 |
| 45 void WebstoreInstallHelper::Start() { | 44 void WebstoreInstallHelper::Start() { |
| 46 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 45 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 47 CHECK(icon_base64_data_.empty() || icon_url_.is_empty()); | 46 CHECK(icon_base64_data_.empty() || icon_url_.is_empty()); |
| 48 | 47 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 60 icon_url_, content::URLFetcher::GET, this)); | 59 icon_url_, content::URLFetcher::GET, this)); |
| 61 url_fetcher_->SetRequestContext(context_getter_); | 60 url_fetcher_->SetRequestContext(context_getter_); |
| 62 | 61 |
| 63 url_fetcher_->Start(); | 62 url_fetcher_->Start(); |
| 64 // We'll get called back in OnURLFetchComplete. | 63 // We'll get called back in OnURLFetchComplete. |
| 65 } | 64 } |
| 66 } | 65 } |
| 67 | 66 |
| 68 void WebstoreInstallHelper::StartWorkOnIOThread() { | 67 void WebstoreInstallHelper::StartWorkOnIOThread() { |
| 69 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 68 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 70 utility_host_ = new UtilityProcessHost(this, BrowserThread::IO); | 69 utility_host_ = |
| 70 (new UtilityProcessHost(this, BrowserThread::IO))->AsWeakPtr(); |
| 71 utility_host_->set_use_linux_zygote(true); | 71 utility_host_->set_use_linux_zygote(true); |
| 72 utility_host_->StartBatchMode(); | 72 utility_host_->StartBatchMode(); |
| 73 | 73 |
| 74 if (!icon_base64_data_.empty()) | 74 if (!icon_base64_data_.empty()) |
| 75 utility_host_->Send( | 75 utility_host_->Send( |
| 76 new ChromeUtilityMsg_DecodeImageBase64(icon_base64_data_)); | 76 new ChromeUtilityMsg_DecodeImageBase64(icon_base64_data_)); |
| 77 | 77 |
| 78 utility_host_->Send(new ChromeUtilityMsg_ParseJSON(manifest_)); | 78 utility_host_->Send(new ChromeUtilityMsg_ParseJSON(manifest_)); |
| 79 } | 79 } |
| 80 | 80 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 ReportResultsIfComplete(); | 165 ReportResultsIfComplete(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void WebstoreInstallHelper::ReportResultsIfComplete() { | 168 void WebstoreInstallHelper::ReportResultsIfComplete() { |
| 169 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 169 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 170 | 170 |
| 171 if (!icon_decode_complete_ || !manifest_parse_complete_) | 171 if (!icon_decode_complete_ || !manifest_parse_complete_) |
| 172 return; | 172 return; |
| 173 | 173 |
| 174 // The utility_host_ will take care of deleting itself after this call. | 174 // The utility_host_ will take care of deleting itself after this call. |
| 175 utility_host_->EndBatchMode(); | 175 if (utility_host_) { |
| 176 utility_host_ = NULL; | 176 utility_host_->EndBatchMode(); |
| 177 utility_host_.reset(); |
| 178 } |
| 177 | 179 |
| 178 BrowserThread::PostTask( | 180 BrowserThread::PostTask( |
| 179 BrowserThread::UI, | 181 BrowserThread::UI, |
| 180 FROM_HERE, | 182 FROM_HERE, |
| 181 base::Bind(&WebstoreInstallHelper::ReportResultFromUIThread, this)); | 183 base::Bind(&WebstoreInstallHelper::ReportResultFromUIThread, this)); |
| 182 } | 184 } |
| 183 | 185 |
| 184 void WebstoreInstallHelper::ReportResultFromUIThread() { | 186 void WebstoreInstallHelper::ReportResultFromUIThread() { |
| 185 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 187 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 186 if (error_.empty() && parsed_manifest_.get()) | 188 if (error_.empty() && parsed_manifest_.get()) |
| 187 delegate_->OnWebstoreParseSuccess(id_, icon_, parsed_manifest_.release()); | 189 delegate_->OnWebstoreParseSuccess(id_, icon_, parsed_manifest_.release()); |
| 188 else | 190 else |
| 189 delegate_->OnWebstoreParseFailure(id_, parse_error_, error_); | 191 delegate_->OnWebstoreParseFailure(id_, parse_error_, error_); |
| 190 } | 192 } |
| OLD | NEW |