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

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: Merged to LKGR to run try bots. 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 SetDownloadManagerDelegate.
21 if (!manager_delegate_.get())
22 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_);
23 manager_ = new DownloadManager(
24 manager_delegate_.get(), g_browser_process->download_status_updater());
25 manager_->Init(profile_);
26 manager_delegate_->SetDownloadManager(manager_);
27 download_manager_created_ = true;
28 }
29 return manager_.get();
30 }
31
32 bool DownloadService::HasCreatedDownloadManager() {
33 return download_manager_created_;
34 }
35
36 void DownloadService::SetDownloadManagerDelegate(
37 ChromeDownloadManagerDelegate* new_delegate) {
38 manager_->set_delegate(new_delegate);
39 new_delegate->SetDownloadManager(manager_);
40 manager_delegate_ = new_delegate;
41 }
42
43 void DownloadService::Shutdown() {
44 if (manager_.get()) {
45 manager_->Shutdown();
46
47 // The manager reference can be released any time after shutdown;
48 // it will be destroyed when the last reference is released on the
49 // FILE thread.
50 // Resetting here will guarantee that any attempts to get the
51 // DownloadManager after shutdown will return null.
52 //
53 // TODO(rdsmith): Figure out how to guarantee when the last reference
54 // will be released and make DownloadManager not RefCountedThreadSafe<>.
55 manager_.release();
56 }
57 if (manager_delegate_.get())
58 manager_delegate_.release();
59 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698