OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/download/download_service.h" | 5 #include "chrome/browser/download/download_service.h" |
6 | 6 |
7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 8 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
9 #include "chrome/browser/download/download_service_factory.h" | 9 #include "chrome/browser/download/download_service_factory.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
12 #include "content/browser/download/download_manager.h" | 12 #include "content/browser/download/download_manager.h" |
13 #include "content/browser/download/download_id_factory.h" | |
13 | 14 |
14 DownloadService::DownloadService(Profile* profile) | 15 DownloadService::DownloadService(Profile* profile) |
15 : download_manager_created_(false), | 16 : download_manager_created_(false), |
16 profile_(profile) {} | 17 profile_(profile) { |
18 if (profile_->IsOffTheRecord()) { | |
19 id_factory_ = DownloadServiceFactory::GetForProfile( | |
20 profile_->GetOriginalProfile())->GetDownloadIdFactory(); | |
21 } else { | |
22 id_factory_ = new DownloadIdFactory(this); | |
23 } | |
24 } | |
17 | 25 |
18 DownloadService::~DownloadService() {} | 26 DownloadService::~DownloadService() {} |
19 | 27 |
28 DownloadIdFactory* DownloadService::GetDownloadIdFactory() const { | |
29 return id_factory_.get(); | |
30 } | |
31 | |
20 DownloadManager* DownloadService::GetDownloadManager() { | 32 DownloadManager* DownloadService::GetDownloadManager() { |
21 if (!download_manager_created_) { | 33 if (!download_manager_created_) { |
22 // In case the delegate has already been set by | 34 // In case the delegate has already been set by |
23 // SetDownloadManagerDelegateForTesting. | 35 // SetDownloadManagerDelegateForTesting. |
24 if (!manager_delegate_.get()) | 36 if (!manager_delegate_.get()) |
25 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); | 37 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); |
26 manager_ = new DownloadManager( | 38 manager_ = new DownloadManager( |
27 manager_delegate_.get(), g_browser_process->download_status_updater()); | 39 manager_delegate_.get(), |
40 GetDownloadIdFactory(), | |
Randy Smith (Not in Mondays)
2011/10/27 18:01:44
nit, suggestion: When they're equally brief with t
benjhayden
2011/10/27 19:04:41
Done.
| |
41 g_browser_process->download_status_updater()); | |
28 manager_->Init(profile_); | 42 manager_->Init(profile_); |
29 manager_delegate_->SetDownloadManager(manager_); | 43 manager_delegate_->SetDownloadManager(manager_); |
30 download_manager_created_ = true; | 44 download_manager_created_ = true; |
31 } | 45 } |
32 return manager_.get(); | 46 return manager_.get(); |
33 } | 47 } |
34 | 48 |
35 bool DownloadService::HasCreatedDownloadManager() { | 49 bool DownloadService::HasCreatedDownloadManager() { |
36 return download_manager_created_; | 50 return download_manager_created_; |
37 } | 51 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 // Resetting here will guarantee that any attempts to get the | 91 // Resetting here will guarantee that any attempts to get the |
78 // DownloadManager after shutdown will return null. | 92 // DownloadManager after shutdown will return null. |
79 // | 93 // |
80 // TODO(rdsmith): Figure out how to guarantee when the last reference | 94 // TODO(rdsmith): Figure out how to guarantee when the last reference |
81 // will be released and make DownloadManager not RefCountedThreadSafe<>. | 95 // will be released and make DownloadManager not RefCountedThreadSafe<>. |
82 manager_.release(); | 96 manager_.release(); |
83 } | 97 } |
84 if (manager_delegate_.get()) | 98 if (manager_delegate_.get()) |
85 manager_delegate_.release(); | 99 manager_delegate_.release(); |
86 } | 100 } |
OLD | NEW |