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

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

Issue 10665049: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 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
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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 result->profile = profile; 160 result->profile = profile;
161 result->parsed_manifest = parsed_manifest.Pass(); 161 result->parsed_manifest = parsed_manifest.Pass();
162 result->skip_install_dialog = true; 162 result->skip_install_dialog = true;
163 return result.Pass(); 163 return result.Pass();
164 } 164 }
165 165
166 WebstoreInstaller::Approval::~Approval() {} 166 WebstoreInstaller::Approval::~Approval() {}
167 167
168 const WebstoreInstaller::Approval* WebstoreInstaller::GetAssociatedApproval( 168 const WebstoreInstaller::Approval* WebstoreInstaller::GetAssociatedApproval(
169 const DownloadItem& download) { 169 const DownloadItem& download) {
170 return static_cast<const Approval*>(download.GetExternalData(kApprovalKey)); 170 return static_cast<const Approval*>(download.GetUserData(kApprovalKey));
171 } 171 }
172 172
173 WebstoreInstaller::WebstoreInstaller(Profile* profile, 173 WebstoreInstaller::WebstoreInstaller(Profile* profile,
174 Delegate* delegate, 174 Delegate* delegate,
175 NavigationController* controller, 175 NavigationController* controller,
176 const std::string& id, 176 const std::string& id,
177 scoped_ptr<Approval> approval, 177 scoped_ptr<Approval> approval,
178 int flags) 178 int flags)
179 : profile_(profile), 179 : profile_(profile),
180 delegate_(delegate), 180 delegate_(delegate),
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 return; 275 return;
276 } 276 }
277 277
278 CHECK(id.IsValid()); 278 CHECK(id.IsValid());
279 279
280 DownloadManager* download_manager = 280 DownloadManager* download_manager =
281 BrowserContext::GetDownloadManager(profile_); 281 BrowserContext::GetDownloadManager(profile_);
282 download_item_ = download_manager->GetActiveDownloadItem(id.local()); 282 download_item_ = download_manager->GetActiveDownloadItem(id.local());
283 download_item_->AddObserver(this); 283 download_item_->AddObserver(this);
284 if (approval_.get()) 284 if (approval_.get())
285 download_item_->SetExternalData(kApprovalKey, approval_.release()); 285 download_item_->SetUserData(kApprovalKey, approval_.release());
286 } 286 }
287 287
288 void WebstoreInstaller::OnDownloadUpdated(DownloadItem* download) { 288 void WebstoreInstaller::OnDownloadUpdated(DownloadItem* download) {
289 CHECK_EQ(download_item_, download); 289 CHECK_EQ(download_item_, download);
290 290
291 switch (download->GetState()) { 291 switch (download->GetState()) {
292 case DownloadItem::CANCELLED: 292 case DownloadItem::CANCELLED:
293 ReportFailure(kDownloadCanceledError); 293 ReportFailure(kDownloadCanceledError);
294 break; 294 break;
295 case DownloadItem::INTERRUPTED: 295 case DownloadItem::INTERRUPTED:
296 ReportFailure(kDownloadInterruptedError); 296 ReportFailure(kDownloadInterruptedError);
297 break; 297 break;
298 case DownloadItem::REMOVING:
299 download_item_->RemoveObserver(this);
300 download_item_ = NULL;
301 break;
302 case DownloadItem::COMPLETE: 298 case DownloadItem::COMPLETE:
303 // Wait for other notifications if the download is really an extension. 299 // Wait for other notifications if the download is really an extension.
304 if (!download_crx_util::IsExtensionDownload(*download)) 300 if (!download_crx_util::IsExtensionDownload(*download))
305 ReportFailure(kInvalidDownloadError); 301 ReportFailure(kInvalidDownloadError);
306 break; 302 break;
307 default: 303 default:
308 // Continue listening if the download is not in one of the above states. 304 // Continue listening if the download is not in one of the above states.
309 break; 305 break;
310 } 306 }
311 } 307 }
312 308
313 void WebstoreInstaller::OnDownloadOpened(DownloadItem* download) { 309 void WebstoreInstaller::OnDownloadDestroyed(DownloadItem* download) {
314 CHECK_EQ(download_item_, download); 310 CHECK_EQ(download_item_, download);
311 download_item_->RemoveObserver(this);
312 download_item_ = NULL;
315 } 313 }
316 314
317 void WebstoreInstaller::StartDownload(const FilePath& file) { 315 void WebstoreInstaller::StartDownload(const FilePath& file) {
318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
319 317
320 if (file.empty() || !controller_->GetWebContents()) { 318 if (file.empty() || !controller_->GetWebContents()) {
321 ReportFailure(kDownloadDirectoryError); 319 ReportFailure(kDownloadDirectoryError);
322 return; 320 return;
323 } 321 }
324 322
(...skipping 28 matching lines...) Expand all
353 void WebstoreInstaller::ReportSuccess() { 351 void WebstoreInstaller::ReportSuccess() {
354 if (delegate_) { 352 if (delegate_) {
355 delegate_->OnExtensionInstallSuccess(id_); 353 delegate_->OnExtensionInstallSuccess(id_);
356 delegate_ = NULL; 354 delegate_ = NULL;
357 } 355 }
358 356
359 Release(); // Balanced in Start(). 357 Release(); // Balanced in Start().
360 } 358 }
361 359
362 } // namespace extensions 360 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698