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/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "content/browser/download/download_id_factory.h" |
10 #include "content/browser/download/download_manager.h" | 12 #include "content/browser/download/download_manager.h" |
11 | 13 |
12 DownloadService::DownloadService(Profile* profile) | 14 DownloadService::DownloadService(Profile* profile) |
13 : download_manager_created_(false), | 15 : download_manager_created_(false), |
14 profile_(profile) {} | 16 profile_(profile) { |
| 17 if (profile_->IsOffTheRecord()) { |
| 18 id_factory_ = DownloadServiceFactory::GetForProfile( |
| 19 profile_->GetOriginalProfile())->GetDownloadIdFactory(); |
| 20 } else { |
| 21 id_factory_ = new DownloadIdFactory(this); |
| 22 } |
| 23 } |
15 | 24 |
16 DownloadService::~DownloadService() {} | 25 DownloadService::~DownloadService() {} |
17 | 26 |
| 27 DownloadIdFactory* DownloadService::GetDownloadIdFactory() const { |
| 28 return id_factory_.get(); |
| 29 } |
| 30 |
18 DownloadManager* DownloadService::GetDownloadManager() { | 31 DownloadManager* DownloadService::GetDownloadManager() { |
19 if (!download_manager_created_) { | 32 if (!download_manager_created_) { |
20 // In case the delegate has already been set by | 33 // In case the delegate has already been set by |
21 // SetDownloadManagerDelegateForTesting. | 34 // SetDownloadManagerDelegateForTesting. |
22 if (!manager_delegate_.get()) | 35 if (!manager_delegate_.get()) |
23 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); | 36 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); |
24 manager_ = new DownloadManager( | 37 manager_ = new DownloadManager( |
25 manager_delegate_.get(), g_browser_process->download_status_updater()); | 38 manager_delegate_.get(), |
| 39 id_factory_.get(), |
| 40 g_browser_process->download_status_updater()); |
26 manager_->Init(profile_); | 41 manager_->Init(profile_); |
27 manager_delegate_->SetDownloadManager(manager_); | 42 manager_delegate_->SetDownloadManager(manager_); |
28 download_manager_created_ = true; | 43 download_manager_created_ = true; |
29 } | 44 } |
30 return manager_.get(); | 45 return manager_.get(); |
31 } | 46 } |
32 | 47 |
33 bool DownloadService::HasCreatedDownloadManager() { | 48 bool DownloadService::HasCreatedDownloadManager() { |
34 return download_manager_created_; | 49 return download_manager_created_; |
35 } | 50 } |
(...skipping 18 matching lines...) Expand all Loading... |
54 // Resetting here will guarantee that any attempts to get the | 69 // Resetting here will guarantee that any attempts to get the |
55 // DownloadManager after shutdown will return null. | 70 // DownloadManager after shutdown will return null. |
56 // | 71 // |
57 // TODO(rdsmith): Figure out how to guarantee when the last reference | 72 // TODO(rdsmith): Figure out how to guarantee when the last reference |
58 // will be released and make DownloadManager not RefCountedThreadSafe<>. | 73 // will be released and make DownloadManager not RefCountedThreadSafe<>. |
59 manager_.release(); | 74 manager_.release(); |
60 } | 75 } |
61 if (manager_delegate_.get()) | 76 if (manager_delegate_.get()) |
62 manager_delegate_.release(); | 77 manager_delegate_.release(); |
63 } | 78 } |
OLD | NEW |