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

Side by Side Diff: chrome/browser/download/download_service.cc

Issue 8135017: Refactor downloads into a ProfileKeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated latest rounds of comments from John. Created 9 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/download/download_service.h"
6
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/download/chrome_download_manager_delegate.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "content/browser/download/download_manager.h"
11
12 DownloadService::DownloadService(Profile* profile)
13 : download_manager_created_(false),
14 profile_(profile) {}
15
16 DownloadService::~DownloadService() {}
17
18 DownloadManager* DownloadService::GetDownloadManager() {
19 if (!download_manager_created_) {
20 // In case the delegate has already been set by
21 // SetDownloadManagerDelegateForTesting.
22 if (!manager_delegate_.get())
23 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_);
24 manager_ = new DownloadManager(
25 manager_delegate_.get(), g_browser_process->download_status_updater());
26 manager_->Init(profile_);
27 manager_delegate_->SetDownloadManager(manager_);
28 download_manager_created_ = true;
29 }
30 return manager_.get();
31 }
32
33 bool DownloadService::HasCreatedDownloadManager() {
34 return download_manager_created_;
35 }
36
37 void DownloadService::SetDownloadManagerDelegateForTesting(
38 ChromeDownloadManagerDelegate* new_delegate) {
39 // Guarantee everything is properly initialized.
40 GetDownloadManager();
41
42 manager_->SetDownloadManagerDelegate(new_delegate);
43 new_delegate->SetDownloadManager(manager_);
44 manager_delegate_ = new_delegate;
45 }
46
47 void DownloadService::Shutdown() {
48 if (manager_.get()) {
49 manager_->Shutdown();
50
51 // The manager reference can be released any time after shutdown;
52 // it will be destroyed when the last reference is released on the
53 // FILE thread.
54 // Resetting here will guarantee that any attempts to get the
55 // DownloadManager after shutdown will return null.
56 //
57 // TODO(rdsmith): Figure out how to guarantee when the last reference
58 // will be released and make DownloadManager not RefCountedThreadSafe<>.
59 manager_.release();
60 }
61 if (manager_delegate_.get())
62 manager_delegate_.release();
63 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_service.h ('k') | chrome/browser/download/download_service_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698