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

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

Issue 10535026: Move creation and ownership of DownloadManager from the embedder to content. This matches all the o… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix cros compile 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
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 20 matching lines...) Expand all
31 #include "content/public/browser/download_save_info.h" 31 #include "content/public/browser/download_save_info.h"
32 #include "content/public/browser/download_url_parameters.h" 32 #include "content/public/browser/download_url_parameters.h"
33 #include "content/public/browser/navigation_controller.h" 33 #include "content/public/browser/navigation_controller.h"
34 #include "content/public/browser/navigation_entry.h" 34 #include "content/public/browser/navigation_entry.h"
35 #include "content/public/browser/notification_details.h" 35 #include "content/public/browser/notification_details.h"
36 #include "content/public/browser/notification_service.h" 36 #include "content/public/browser/notification_service.h"
37 #include "content/public/browser/notification_source.h" 37 #include "content/public/browser/notification_source.h"
38 #include "googleurl/src/gurl.h" 38 #include "googleurl/src/gurl.h"
39 #include "net/base/escape.h" 39 #include "net/base/escape.h"
40 40
41 using content::BrowserContext;
41 using content::BrowserThread; 42 using content::BrowserThread;
42 using content::DownloadId; 43 using content::DownloadId;
43 using content::DownloadItem; 44 using content::DownloadItem;
45 using content::DownloadManager;
44 using content::NavigationController; 46 using content::NavigationController;
45 using content::DownloadUrlParameters; 47 using content::DownloadUrlParameters;
46 48
47 namespace { 49 namespace {
48 50
49 using extensions::Extension; 51 using extensions::Extension;
50 52
51 // Key used to attach the Approval to the DownloadItem. 53 // Key used to attach the Approval to the DownloadItem.
52 const char kApprovalKey[] = "extensions.webstore_installer"; 54 const char kApprovalKey[] = "extensions.webstore_installer";
53 55
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 void WebstoreInstaller::Start() { 186 void WebstoreInstaller::Start() {
185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
186 AddRef(); // Balanced in ReportSuccess and ReportFailure. 188 AddRef(); // Balanced in ReportSuccess and ReportFailure.
187 189
188 if (!Extension::IdIsValid(id_)) { 190 if (!Extension::IdIsValid(id_)) {
189 ReportFailure(kInvalidIdError); 191 ReportFailure(kInvalidIdError);
190 return; 192 return;
191 } 193 }
192 194
193 FilePath download_path = DownloadPrefs::FromDownloadManager( 195 FilePath download_path = DownloadPrefs::FromDownloadManager(
194 profile_->GetDownloadManager())->download_path(); 196 BrowserContext::GetDownloadManager(profile_))->download_path();
195 BrowserThread::PostTask( 197 BrowserThread::PostTask(
196 BrowserThread::FILE, FROM_HERE, 198 BrowserThread::FILE, FROM_HERE,
197 base::Bind(&GetDownloadFilePath, download_path, id_, 199 base::Bind(&GetDownloadFilePath, download_path, id_,
198 base::Bind(&WebstoreInstaller::StartDownload, 200 base::Bind(&WebstoreInstaller::StartDownload,
199 base::Unretained(this)))); 201 base::Unretained(this))));
200 202
201 } 203 }
202 204
203 void WebstoreInstaller::Observe(int type, 205 void WebstoreInstaller::Observe(int type,
204 const content::NotificationSource& source, 206 const content::NotificationSource& source,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 } 259 }
258 260
259 void WebstoreInstaller::OnDownloadStarted(DownloadId id, net::Error error) { 261 void WebstoreInstaller::OnDownloadStarted(DownloadId id, net::Error error) {
260 if (error != net::OK) { 262 if (error != net::OK) {
261 ReportFailure(net::ErrorToString(error)); 263 ReportFailure(net::ErrorToString(error));
262 return; 264 return;
263 } 265 }
264 266
265 CHECK(id.IsValid()); 267 CHECK(id.IsValid());
266 268
267 content::DownloadManager* download_manager = profile_->GetDownloadManager(); 269 DownloadManager* download_manager =
270 BrowserContext::GetDownloadManager(profile_);
268 download_item_ = download_manager->GetActiveDownloadItem(id.local()); 271 download_item_ = download_manager->GetActiveDownloadItem(id.local());
269 download_item_->AddObserver(this); 272 download_item_->AddObserver(this);
270 if (approval_.get()) 273 if (approval_.get())
271 download_item_->SetExternalData(kApprovalKey, approval_.release()); 274 download_item_->SetExternalData(kApprovalKey, approval_.release());
272 } 275 }
273 276
274 void WebstoreInstaller::OnDownloadUpdated(DownloadItem* download) { 277 void WebstoreInstaller::OnDownloadUpdated(DownloadItem* download) {
275 CHECK_EQ(download_item_, download); 278 CHECK_EQ(download_item_, download);
276 279
277 switch (download->GetState()) { 280 switch (download->GetState()) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 // download system will then pass the crx to the CrxInstaller. 319 // download system will then pass the crx to the CrxInstaller.
317 download_util::RecordDownloadSource( 320 download_util::RecordDownloadSource(
318 download_util::INITIATED_BY_WEBSTORE_INSTALLER); 321 download_util::INITIATED_BY_WEBSTORE_INSTALLER);
319 scoped_ptr<DownloadUrlParameters> params( 322 scoped_ptr<DownloadUrlParameters> params(
320 DownloadUrlParameters::FromWebContents( 323 DownloadUrlParameters::FromWebContents(
321 controller_->GetWebContents(), download_url_, save_info)); 324 controller_->GetWebContents(), download_url_, save_info));
322 params->set_referrer( 325 params->set_referrer(
323 content::Referrer(controller_->GetActiveEntry()->GetURL(), 326 content::Referrer(controller_->GetActiveEntry()->GetURL(),
324 WebKit::WebReferrerPolicyDefault)); 327 WebKit::WebReferrerPolicyDefault));
325 params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, this)); 328 params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, this));
326 profile_->GetDownloadManager()->DownloadUrl(params.Pass()); 329 BrowserContext::GetDownloadManager(profile_)->DownloadUrl(params.Pass());
327 } 330 }
328 331
329 void WebstoreInstaller::ReportFailure(const std::string& error) { 332 void WebstoreInstaller::ReportFailure(const std::string& error) {
330 if (delegate_) { 333 if (delegate_) {
331 delegate_->OnExtensionInstallFailure(id_, error); 334 delegate_->OnExtensionInstallFailure(id_, error);
332 delegate_ = NULL; 335 delegate_ = NULL;
333 } 336 }
334 337
335 Release(); // Balanced in Start(). 338 Release(); // Balanced in Start().
336 } 339 }
337 340
338 void WebstoreInstaller::ReportSuccess() { 341 void WebstoreInstaller::ReportSuccess() {
339 if (delegate_) { 342 if (delegate_) {
340 delegate_->OnExtensionInstallSuccess(id_); 343 delegate_->OnExtensionInstallSuccess(id_);
341 delegate_ = NULL; 344 delegate_ = NULL;
342 } 345 }
343 346
344 Release(); // Balanced in Start(). 347 Release(); // Balanced in Start().
345 } 348 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698