OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DOWNLOAD_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DOWNLOAD_HANDLER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DOWNLOAD_HANDLER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DOWNLOAD_HANDLER_H_ |
7 | 7 |
8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "chrome/browser/chromeos/drive/file_errors.h" | 10 #include "chrome/browser/chromeos/drive/file_errors.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 explicit DownloadHandler(FileSystemInterface* file_system); | 30 explicit DownloadHandler(FileSystemInterface* file_system); |
31 virtual ~DownloadHandler(); | 31 virtual ~DownloadHandler(); |
32 | 32 |
33 // Utility method to get DownloadHandler with profile. | 33 // Utility method to get DownloadHandler with profile. |
34 static DownloadHandler* GetForProfile(Profile* profile); | 34 static DownloadHandler* GetForProfile(Profile* profile); |
35 | 35 |
36 // Become an observer of DownloadManager. | 36 // Become an observer of DownloadManager. |
37 void Initialize(content::DownloadManager* download_manager, | 37 void Initialize(content::DownloadManager* download_manager, |
38 const base::FilePath& drive_tmp_download_path); | 38 const base::FilePath& drive_tmp_download_path); |
39 | 39 |
| 40 // In addition to the DownloadManager passed to Initialize(), observe another |
| 41 // download manager. This should be called only for the DownloadManager of the |
| 42 // incognito version of the profile where |file_system_| resides. |
| 43 void ObserveIncognitoDownloadManager( |
| 44 content::DownloadManager* download_manager); |
| 45 |
40 // Callback used to return results from SubstituteDriveDownloadPath. | 46 // Callback used to return results from SubstituteDriveDownloadPath. |
41 // TODO(hashimoto): Report error with a FileError. crbug.com/171345 | 47 // TODO(hashimoto): Report error with a FileError. crbug.com/171345 |
42 typedef base::Callback<void(const base::FilePath&)> | 48 typedef base::Callback<void(const base::FilePath&)> |
43 SubstituteDriveDownloadPathCallback; | 49 SubstituteDriveDownloadPathCallback; |
44 | 50 |
45 void SubstituteDriveDownloadPath( | 51 void SubstituteDriveDownloadPath( |
46 const base::FilePath& drive_path, | 52 const base::FilePath& drive_path, |
47 content::DownloadItem* download, | 53 content::DownloadItem* download, |
48 const SubstituteDriveDownloadPathCallback& callback); | 54 const SubstituteDriveDownloadPathCallback& callback); |
49 | 55 |
(...skipping 18 matching lines...) Expand all Loading... |
68 const content::CheckForFileExistenceCallback& callback); | 74 const content::CheckForFileExistenceCallback& callback); |
69 | 75 |
70 private: | 76 private: |
71 // AllDownloadItemNotifier::Observer overrides: | 77 // AllDownloadItemNotifier::Observer overrides: |
72 virtual void OnDownloadCreated(content::DownloadManager* manager, | 78 virtual void OnDownloadCreated(content::DownloadManager* manager, |
73 content::DownloadItem* download) OVERRIDE; | 79 content::DownloadItem* download) OVERRIDE; |
74 virtual void OnDownloadUpdated(content::DownloadManager* manager, | 80 virtual void OnDownloadUpdated(content::DownloadManager* manager, |
75 content::DownloadItem* download) OVERRIDE; | 81 content::DownloadItem* download) OVERRIDE; |
76 | 82 |
77 // Removes the download. | 83 // Removes the download. |
78 void RemoveDownload(int id); | 84 void RemoveDownload(void* manager_id, int id); |
79 | 85 |
80 // Callback for FileSystem::CreateDirectory(). | 86 // Callback for FileSystem::CreateDirectory(). |
81 // Used to implement SubstituteDriveDownloadPath(). | 87 // Used to implement SubstituteDriveDownloadPath(). |
82 void OnCreateDirectory(const SubstituteDriveDownloadPathCallback& callback, | 88 void OnCreateDirectory(const SubstituteDriveDownloadPathCallback& callback, |
83 FileError error); | 89 FileError error); |
84 | 90 |
85 // Starts the upload of a downloaded/downloading file. | 91 // Starts the upload of a downloaded/downloading file. |
86 void UploadDownloadItem(content::DownloadItem* download); | 92 void UploadDownloadItem(content::DownloadManager* manager, |
| 93 content::DownloadItem* download); |
87 | 94 |
88 // Sets |cache_file_path| as user data of the download item specified by |id|. | 95 // Sets |cache_file_path| as user data of the download item specified by |id|. |
89 void SetCacheFilePath(int id, | 96 void SetCacheFilePath(void* manager_id, |
| 97 int id, |
90 const base::FilePath* cache_file_path, | 98 const base::FilePath* cache_file_path, |
91 FileError error); | 99 FileError error); |
92 | 100 |
| 101 // Gets a download manager, given a |manager_id| casted from the pointer to |
| 102 // the manager. This is used to validate the manager that may be deleted while |
| 103 // asynchronous task posting. Returns NULL if the manager is already gone. |
| 104 content::DownloadManager* GetDownloadManager(void* manager_id); |
| 105 |
93 FileSystemInterface* file_system_; // Owned by DriveIntegrationService. | 106 FileSystemInterface* file_system_; // Owned by DriveIntegrationService. |
94 // Observe the DownloadManager for new downloads. | 107 // Observe the DownloadManager for new downloads. |
95 scoped_ptr<AllDownloadItemNotifier> notifier_; | 108 scoped_ptr<AllDownloadItemNotifier> notifier_; |
| 109 scoped_ptr<AllDownloadItemNotifier> notifier_incognito_; |
96 | 110 |
97 // Temporary download location directory. | 111 // Temporary download location directory. |
98 base::FilePath drive_tmp_download_path_; | 112 base::FilePath drive_tmp_download_path_; |
99 | 113 |
100 // Note: This should remain the last member so it'll be destroyed and | 114 // Note: This should remain the last member so it'll be destroyed and |
101 // invalidate its weak pointers before any other members are destroyed. | 115 // invalidate its weak pointers before any other members are destroyed. |
102 base::WeakPtrFactory<DownloadHandler> weak_ptr_factory_; | 116 base::WeakPtrFactory<DownloadHandler> weak_ptr_factory_; |
103 | 117 |
104 DISALLOW_COPY_AND_ASSIGN(DownloadHandler); | 118 DISALLOW_COPY_AND_ASSIGN(DownloadHandler); |
105 }; | 119 }; |
106 | 120 |
107 } // namespace drive | 121 } // namespace drive |
108 | 122 |
109 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DOWNLOAD_HANDLER_H_ | 123 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DOWNLOAD_HANDLER_H_ |
OLD | NEW |