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 // Each download is represented by a DownloadItem, and all DownloadItems | 5 // Each download is represented by a DownloadItem, and all DownloadItems |
6 // are owned by the DownloadManager which maintains a global list of all | 6 // are owned by the DownloadManager which maintains a global list of all |
7 // downloads. DownloadItems are created when a user initiates a download, | 7 // downloads. DownloadItems are created when a user initiates a download, |
8 // and exist for the duration of the browser life time. | 8 // and exist for the duration of the browser life time. |
9 // | 9 // |
10 // Download observers: | 10 // Download observers: |
(...skipping 15 matching lines...) Expand all Loading... | |
26 #include "base/time.h" | 26 #include "base/time.h" |
27 #include "base/timer.h" | 27 #include "base/timer.h" |
28 #include "chrome/browser/download/download_request_handle.h" | 28 #include "chrome/browser/download/download_request_handle.h" |
29 #include "chrome/browser/download/download_state_info.h" | 29 #include "chrome/browser/download/download_state_info.h" |
30 #include "content/common/notification_observer.h" | 30 #include "content/common/notification_observer.h" |
31 #include "content/common/notification_registrar.h" | 31 #include "content/common/notification_registrar.h" |
32 #include "googleurl/src/gurl.h" | 32 #include "googleurl/src/gurl.h" |
33 | 33 |
34 class CrxInstaller; | 34 class CrxInstaller; |
35 class DownloadFileManager; | 35 class DownloadFileManager; |
36 class DownloadId; // See the bottom of this file. | |
36 class DownloadManager; | 37 class DownloadManager; |
37 struct DownloadCreateInfo; | 38 struct DownloadCreateInfo; |
38 struct DownloadHistoryInfo; | 39 struct DownloadHistoryInfo; |
39 | 40 |
40 // One DownloadItem per download. This is the model class that stores all the | 41 // One DownloadItem per download. This is the model class that stores all the |
41 // state for a download. Multiple views, such as a tab's download shelf and the | 42 // state for a download. Multiple views, such as a tab's download shelf and the |
42 // Destination tab's download view, may refer to a given DownloadItem. | 43 // Destination tab's download view, may refer to a given DownloadItem. |
43 // | 44 // |
44 // This is intended to be used only on the UI thread. | 45 // This is intended to be used only on the UI thread. |
45 class DownloadItem : public NotificationObserver { | 46 class DownloadItem : public NotificationObserver { |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 std::string content_disposition() const { return content_disposition_; } | 270 std::string content_disposition() const { return content_disposition_; } |
270 std::string mime_type() const { return mime_type_; } | 271 std::string mime_type() const { return mime_type_; } |
271 std::string original_mime_type() const { return original_mime_type_; } | 272 std::string original_mime_type() const { return original_mime_type_; } |
272 std::string referrer_charset() const { return referrer_charset_; } | 273 std::string referrer_charset() const { return referrer_charset_; } |
273 int64 total_bytes() const { return total_bytes_; } | 274 int64 total_bytes() const { return total_bytes_; } |
274 void set_total_bytes(int64 total_bytes) { | 275 void set_total_bytes(int64 total_bytes) { |
275 total_bytes_ = total_bytes; | 276 total_bytes_ = total_bytes; |
276 } | 277 } |
277 int64 received_bytes() const { return received_bytes_; } | 278 int64 received_bytes() const { return received_bytes_; } |
278 int32 id() const { return download_id_; } | 279 int32 id() const { return download_id_; } |
280 DownloadId gid() const; | |
279 base::Time start_time() const { return start_time_; } | 281 base::Time start_time() const { return start_time_; } |
280 void set_db_handle(int64 handle) { db_handle_ = handle; } | 282 void set_db_handle(int64 handle) { db_handle_ = handle; } |
281 int64 db_handle() const { return db_handle_; } | 283 int64 db_handle() const { return db_handle_; } |
282 bool is_paused() const { return is_paused_; } | 284 bool is_paused() const { return is_paused_; } |
283 bool open_when_complete() const { return open_when_complete_; } | 285 bool open_when_complete() const { return open_when_complete_; } |
284 void set_open_when_complete(bool open) { open_when_complete_ = open; } | 286 void set_open_when_complete(bool open) { open_when_complete_ = open; } |
285 bool file_externally_removed() const { return file_externally_removed_; } | 287 bool file_externally_removed() const { return file_externally_removed_; } |
286 SafetyState safety_state() const { return safety_state_; } | 288 SafetyState safety_state() const { return safety_state_; } |
287 // Why |safety_state_| is not SAFE. | 289 // Why |safety_state_| is not SAFE. |
288 DangerType GetDangerType() const; | 290 DangerType GetDangerType() const; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 // Do we actual open downloads when requested? For testing purposes | 478 // Do we actual open downloads when requested? For testing purposes |
477 // only. | 479 // only. |
478 bool open_enabled_; | 480 bool open_enabled_; |
479 | 481 |
480 // DownloadItem observes CRX installs it initiates. | 482 // DownloadItem observes CRX installs it initiates. |
481 NotificationRegistrar registrar_; | 483 NotificationRegistrar registrar_; |
482 | 484 |
483 DISALLOW_COPY_AND_ASSIGN(DownloadItem); | 485 DISALLOW_COPY_AND_ASSIGN(DownloadItem); |
484 }; | 486 }; |
485 | 487 |
488 // DownloadId combines per-profile Download ids with an indication of which | |
489 // profile in order to be globally unique. DownloadIds are not persistent across | |
490 // sessions. | |
491 class DownloadId { | |
Randy Smith (Not in Mondays)
2011/07/25 20:20:12
A download id seems like a "lower level" concept t
benjhayden
2011/07/27 19:40:54
Done.
| |
492 public: | |
493 explicit DownloadId(DownloadManager* m = NULL, int32 i = -1) | |
494 : manager_(m), | |
495 id_(i) { | |
496 } | |
497 | |
498 // per-profile and persistent | |
499 int32 id() const { return id_; } | |
500 | |
501 bool IsValid() const { return ((manager_ != NULL) && (id_ >= 0)); } | |
502 | |
503 bool operator==(const DownloadId& that) const { | |
Randy Smith (Not in Mondays)
2011/07/25 20:20:12
Chrome biases against creating full types (i.e. su
benjhayden
2011/07/27 19:40:54
Done.
| |
504 return ((that.id_ == id_) && | |
505 (that.manager_ == manager_)); | |
506 } | |
507 bool operator<(const DownloadId& that) const { | |
508 return ((manager_ < that.manager_) || | |
509 (id_ < that.id_)); | |
510 } | |
511 | |
512 size_t hash() const { | |
513 // The top half of manager is unlikely to be distinct, and the user is | |
514 // unlikely to have >64K downloads. If these assumptions are incorrect, then | |
515 // DownloadFileManager's hash_map might have a few collisions, but it will | |
516 // use operator== to safely disambiguate. | |
517 return reinterpret_cast<size_t>(manager_) + | |
518 (static_cast<size_t>(id_) << (4 * sizeof(size_t))); | |
519 } | |
520 | |
521 private: | |
522 // DownloadId is used mostly off the UI thread, so manager's methods can't be | |
523 // called, but the pointer can be compared. | |
524 DownloadManager* manager_; | |
525 | |
526 int32 id_; | |
527 | |
528 // Allow copy and assign. | |
529 }; | |
530 namespace __gnu_cxx { | |
Randy Smith (Not in Mondays)
2011/07/25 20:20:12
This looks like black magic, and it's specifically
benjhayden
2011/07/27 19:40:54
Switched to BASE_HASH_NAMESPACE to afford the othe
| |
531 template<> struct hash<DownloadId> { | |
532 size_t operator()(const DownloadId& did) const { | |
533 return did.hash(); | |
534 } | |
535 }; | |
536 } | |
537 | |
486 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 538 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
OLD | NEW |