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

Side by Side Diff: chrome/browser/download/download_path_reservation_tracker.cc

Issue 10665049: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 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
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 #include "chrome/browser/download/download_path_reservation_tracker.h" 5 #include "chrome/browser/download/download_path_reservation_tracker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 18 matching lines...) Expand all
29 public: 29 public:
30 DownloadItemObserver(DownloadItem& download_item, 30 DownloadItemObserver(DownloadItem& download_item,
31 base::Closure revoke, 31 base::Closure revoke,
32 base::Callback<void(const FilePath&)> update); 32 base::Callback<void(const FilePath&)> update);
33 33
34 private: 34 private:
35 virtual ~DownloadItemObserver(); 35 virtual ~DownloadItemObserver();
36 36
37 // DownloadItem::Observer 37 // DownloadItem::Observer
38 virtual void OnDownloadUpdated(DownloadItem* download) OVERRIDE; 38 virtual void OnDownloadUpdated(DownloadItem* download) OVERRIDE;
39 virtual void OnDownloadOpened(DownloadItem* download) OVERRIDE; 39 virtual void OnDownloadDestroyed(DownloadItem* download) OVERRIDE;
40 40
41 DownloadItem& download_item_; 41 DownloadItem& download_item_;
42 42
43 // Last known target path for the download. 43 // Last known target path for the download.
44 FilePath last_target_path_; 44 FilePath last_target_path_;
45 45
46 // Callback to invoke to revoke the path reseration. 46 // Callback to invoke to revoke the path reseration.
47 base::Closure revoke_callback_; 47 base::Closure revoke_callback_;
48 48
49 // Callback to invoke to update the path reservation. 49 // Callback to invoke to update the path reservation.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } 82 }
83 83
84 case DownloadItem::COMPLETE: 84 case DownloadItem::COMPLETE:
85 // If the download is complete, then it has already been renamed to the 85 // If the download is complete, then it has already been renamed to the
86 // final name. The existence of the file on disk is sufficient to prevent 86 // final name. The existence of the file on disk is sufficient to prevent
87 // conflicts from now on. 87 // conflicts from now on.
88 88
89 case DownloadItem::CANCELLED: 89 case DownloadItem::CANCELLED:
90 // We no longer need the reservation if the download is being removed. 90 // We no longer need the reservation if the download is being removed.
91 91
92 case DownloadItem::REMOVING:
93 // Ditto, but this case shouldn't happen in practice. We should have
94 // received another notification beforehand.
95
96 case DownloadItem::INTERRUPTED: 92 case DownloadItem::INTERRUPTED:
97 // The download filename will need to be re-generated when the download is 93 // The download filename will need to be re-generated when the download is
98 // restarted. Holding on to the reservation now would prevent the name 94 // restarted. Holding on to the reservation now would prevent the name
99 // from being used for a subsequent retry attempt. 95 // from being used for a subsequent retry attempt.
100 96
101 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, revoke_callback_); 97 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, revoke_callback_);
102 delete this; 98 delete this;
103 break; 99 break;
104 100
105 case DownloadItem::MAX_DOWNLOAD_STATE: 101 case DownloadItem::MAX_DOWNLOAD_STATE:
106 // Compiler appeasement. 102 // Compiler appeasement.
107 NOTREACHED(); 103 NOTREACHED();
108 } 104 }
109 } 105 }
110 106
111 void DownloadItemObserver::OnDownloadOpened(DownloadItem* download) { 107 void DownloadItemObserver::OnDownloadDestroyed(DownloadItem* download) {
112 // We shouldn't be tracking reservations for a download that has been 108 // This shouldn't happen. We should catch either COMPLETE, CANCELLED, or
113 // externally opened. The tracker should have detached itself when the 109 // INTERRUPTED first.
114 // download was complete. 110 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, revoke_callback_);
111 delete this;
115 } 112 }
116 113
117 } // namespace 114 } // namespace
118 115
119 // static 116 // static
120 void DownloadPathReservationTracker::GetReservedPath( 117 void DownloadPathReservationTracker::GetReservedPath(
121 DownloadItem& download_item, 118 DownloadItem& download_item,
122 const FilePath& target_path, 119 const FilePath& target_path,
123 const FilePath& default_path, 120 const FilePath& default_path,
124 bool uniquify_path, 121 bool uniquify_path,
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 reservations_.erase(download_id); 246 reservations_.erase(download_id);
250 } 247 }
251 248
252 // static 249 // static
253 DownloadPathReservationTracker* DownloadPathReservationTracker::GetInstance() { 250 DownloadPathReservationTracker* DownloadPathReservationTracker::GetInstance() {
254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
255 static base::LazyInstance<DownloadPathReservationTracker> 252 static base::LazyInstance<DownloadPathReservationTracker>
256 reservation_tracker = LAZY_INSTANCE_INITIALIZER; 253 reservation_tracker = LAZY_INSTANCE_INITIALIZER;
257 return reservation_tracker.Pointer(); 254 return reservation_tracker.Pointer();
258 } 255 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698