blob: b513199b5240c030bad678ec033083b1012ac2af (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_
#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_
#pragma once
#include <vector>
#include "base/basictypes.h"
#include "base/callback_forward.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/profiles/profile_keyed_service.h"
class ChromeDownloadManagerDelegate;
class Profile;
namespace content {
class DownloadManager;
}
// Owning class for DownloadManager (content) and
// ChromeDownloadManagerDelegate (chrome)
class DownloadService : public ProfileKeyedService {
public:
explicit DownloadService(Profile* profile);
virtual ~DownloadService();
// Register a callback to be called whenever the DownloadManager is created.
typedef base::Callback<void(content::DownloadManager*)>
OnManagerCreatedCallback;
void OnManagerCreated(const OnManagerCreatedCallback& cb);
// Get the download manager. Creates the download manager if
// it does not already exist.
content::DownloadManager* GetDownloadManager();
// Has a download manager been created? (By calling above function.)
bool HasCreatedDownloadManager();
// Number of downloads associated with this instance of the service.
int DownloadCount() const;
// Number of downloads associated with all profiles.
static int DownloadCountAllProfiles();
// Sets the DownloadManagerDelegate associated with this object and
// its DownloadManager. Takes ownership of |delegate|, and destroys
// the previous delegate. For testing.
void SetDownloadManagerDelegateForTesting(
ChromeDownloadManagerDelegate* delegate);
// Will be called to release references on other services as part
// of Profile shutdown.
virtual void Shutdown() OVERRIDE;
private:
bool download_manager_created_;
Profile* profile_;
// Both of these objects are owned by this class.
// DownloadManager is RefCountedThreadSafe because of references
// from DownloadFile objects on the FILE thread, and may need to be
// kept alive until those objects are deleted.
// ChromeDownloadManagerDelegate may be the target of callbacks from
// the history service/DB thread and must be kept alive for those
// callbacks.
scoped_refptr<content::DownloadManager> manager_;
scoped_refptr<ChromeDownloadManagerDelegate> manager_delegate_;
std::vector<OnManagerCreatedCallback> on_manager_created_callbacks_;
DISALLOW_COPY_AND_ASSIGN(DownloadService);
};
#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_
|