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

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

Issue 10453039: Debug crash in WebstoreInstaller::StartDownload() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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_installer.h" 5 #include "chrome/browser/extensions/webstore_installer.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 const std::string& id, 165 const std::string& id,
166 scoped_ptr<Approval> approval, 166 scoped_ptr<Approval> approval,
167 int flags) 167 int flags)
168 : profile_(profile), 168 : profile_(profile),
169 delegate_(delegate), 169 delegate_(delegate),
170 controller_(controller), 170 controller_(controller),
171 id_(id), 171 id_(id),
172 download_item_(NULL), 172 download_item_(NULL),
173 flags_(flags), 173 flags_(flags),
174 approval_(approval.release()) { 174 approval_(approval.release()) {
175 // TODO(benjhayden): Change this CHECK to DCHECK after http://crbug.com/126013
176 CHECK(controller_);
175 download_url_ = GetWebstoreInstallURL(id, flags & FLAG_INLINE_INSTALL ? 177 download_url_ = GetWebstoreInstallURL(id, flags & FLAG_INLINE_INSTALL ?
176 kInlineInstallSource : kDefaultInstallSource); 178 kInlineInstallSource : kDefaultInstallSource);
177 179
178 registrar_.Add(this, chrome::NOTIFICATION_CRX_INSTALLER_DONE, 180 registrar_.Add(this, chrome::NOTIFICATION_CRX_INSTALLER_DONE,
179 content::NotificationService::AllSources()); 181 content::NotificationService::AllSources());
180 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, 182 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
181 content::Source<Profile>(profile->GetOriginalProfile())); 183 content::Source<Profile>(profile->GetOriginalProfile()));
182 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, 184 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR,
183 content::Source<CrxInstaller>(NULL)); 185 content::Source<CrxInstaller>(NULL));
184 } 186 }
185 187
186 void WebstoreInstaller::Start() { 188 void WebstoreInstaller::Start() {
187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
188 AddRef(); // Balanced in ReportSuccess and ReportFailure. 190 AddRef(); // Balanced in ReportSuccess and ReportFailure.
189 191
190 if (!Extension::IdIsValid(id_)) { 192 if (!Extension::IdIsValid(id_)) {
191 ReportFailure(kInvalidIdError); 193 ReportFailure(kInvalidIdError);
192 return; 194 return;
193 } 195 }
194 196
195 FilePath download_path = DownloadPrefs::FromDownloadManager( 197 FilePath download_path = DownloadPrefs::FromDownloadManager(
196 BrowserContext::GetDownloadManager(profile_))->download_path(); 198 BrowserContext::GetDownloadManager(profile_))->download_path();
197 BrowserThread::PostTask( 199 BrowserThread::PostTask(
198 BrowserThread::FILE, FROM_HERE, 200 BrowserThread::FILE, FROM_HERE,
199 base::Bind(&GetDownloadFilePath, download_path, id_, 201 base::Bind(&GetDownloadFilePath, download_path, id_,
200 base::Bind(&WebstoreInstaller::StartDownload, 202 base::Bind(&WebstoreInstaller::StartDownload, this)));
201 base::Unretained(this))));
202
203 } 203 }
204 204
205 void WebstoreInstaller::Observe(int type, 205 void WebstoreInstaller::Observe(int type,
206 const content::NotificationSource& source, 206 const content::NotificationSource& source,
207 const content::NotificationDetails& details) { 207 const content::NotificationDetails& details) {
208 switch (type) { 208 switch (type) {
209 case chrome::NOTIFICATION_CRX_INSTALLER_DONE: { 209 case chrome::NOTIFICATION_CRX_INSTALLER_DONE: {
210 const Extension* extension = 210 const Extension* extension =
211 content::Details<const Extension>(details).ptr(); 211 content::Details<const Extension>(details).ptr();
212 CrxInstaller* installer = content::Source<CrxInstaller>(source).ptr(); 212 CrxInstaller* installer = content::Source<CrxInstaller>(source).ptr();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 299 }
300 } 300 }
301 301
302 void WebstoreInstaller::OnDownloadOpened(DownloadItem* download) { 302 void WebstoreInstaller::OnDownloadOpened(DownloadItem* download) {
303 CHECK_EQ(download_item_, download); 303 CHECK_EQ(download_item_, download);
304 } 304 }
305 305
306 void WebstoreInstaller::StartDownload(const FilePath& file) { 306 void WebstoreInstaller::StartDownload(const FilePath& file) {
307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
308 308
309 if (file.empty()) { 309 if (file.empty() || !controller_->GetWebContents()) {
310 ReportFailure(kDownloadDirectoryError); 310 ReportFailure(kDownloadDirectoryError);
311 return; 311 return;
312 } 312 }
313 313
314 content::DownloadSaveInfo save_info; 314 content::DownloadSaveInfo save_info;
315 save_info.file_path = file; 315 save_info.file_path = file;
316 316
317 // The download url for the given extension is contained in |download_url_|. 317 // The download url for the given extension is contained in |download_url_|.
318 // We will navigate the current tab to this url to start the download. The 318 // We will navigate the current tab to this url to start the download. The
319 // download system will then pass the crx to the CrxInstaller. 319 // download system will then pass the crx to the CrxInstaller.
320 download_util::RecordDownloadSource( 320 download_util::RecordDownloadSource(
321 download_util::INITIATED_BY_WEBSTORE_INSTALLER); 321 download_util::INITIATED_BY_WEBSTORE_INSTALLER);
322 scoped_ptr<DownloadUrlParameters> params( 322 scoped_ptr<DownloadUrlParameters> params(
323 DownloadUrlParameters::FromWebContents( 323 DownloadUrlParameters::FromWebContents(
324 controller_->GetWebContents(), download_url_, save_info)); 324 controller_->GetWebContents(), download_url_, save_info));
325 params->set_referrer( 325 if (controller_->GetActiveEntry())
326 content::Referrer(controller_->GetActiveEntry()->GetURL(), 326 params->set_referrer(
327 WebKit::WebReferrerPolicyDefault)); 327 content::Referrer(controller_->GetActiveEntry()->GetURL(),
328 WebKit::WebReferrerPolicyDefault));
328 params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, this)); 329 params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, this));
329 BrowserContext::GetDownloadManager(profile_)->DownloadUrl(params.Pass()); 330 BrowserContext::GetDownloadManager(profile_)->DownloadUrl(params.Pass());
330 } 331 }
331 332
332 void WebstoreInstaller::ReportFailure(const std::string& error) { 333 void WebstoreInstaller::ReportFailure(const std::string& error) {
333 if (delegate_) { 334 if (delegate_) {
334 delegate_->OnExtensionInstallFailure(id_, error); 335 delegate_->OnExtensionInstallFailure(id_, error);
335 delegate_ = NULL; 336 delegate_ = NULL;
336 } 337 }
337 338
338 Release(); // Balanced in Start(). 339 Release(); // Balanced in Start().
339 } 340 }
340 341
341 void WebstoreInstaller::ReportSuccess() { 342 void WebstoreInstaller::ReportSuccess() {
342 if (delegate_) { 343 if (delegate_) {
343 delegate_->OnExtensionInstallSuccess(id_); 344 delegate_->OnExtensionInstallSuccess(id_);
344 delegate_ = NULL; 345 delegate_ = NULL;
345 } 346 }
346 347
347 Release(); // Balanced in Start(). 348 Release(); // Balanced in Start().
348 } 349 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698