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 #include "content/browser/download/download_manager_impl.h" | 5 #include "content/browser/download/download_manager_impl.h" |
6 | 6 |
7 #include <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 using content::BrowserThread; | 45 using content::BrowserThread; |
46 using content::DownloadId; | 46 using content::DownloadId; |
47 using content::DownloadItem; | 47 using content::DownloadItem; |
48 using content::DownloadPersistentStoreInfo; | 48 using content::DownloadPersistentStoreInfo; |
49 using content::ResourceDispatcherHostImpl; | 49 using content::ResourceDispatcherHostImpl; |
50 using content::WebContents; | 50 using content::WebContents; |
51 | 51 |
52 namespace { | 52 namespace { |
53 | 53 |
54 // This is just used to remember which DownloadItems come from SavePage. | 54 // This is just used to remember which DownloadItems come from SavePage. |
55 class SavePageExternalData : public DownloadItem::ExternalData { | 55 class SavePageData : public base::SupportsUserData::Data { |
56 public: | 56 public: |
57 // A spoonful of syntactic sugar. | 57 // A spoonful of syntactic sugar. |
58 static bool Get(DownloadItem* item) { | 58 static bool Get(DownloadItem* item) { |
59 return item->GetExternalData(kKey) != NULL; | 59 return item->GetUserData(kKey) != NULL; |
60 } | 60 } |
61 | 61 |
62 explicit SavePageExternalData(DownloadItem* item) { | 62 explicit SavePageData(DownloadItem* item) { |
63 item->SetExternalData(kKey, this); | 63 item->SetUserData(kKey, this); |
64 } | 64 } |
65 | 65 |
66 virtual ~SavePageExternalData() {} | 66 virtual ~SavePageData() {} |
67 | 67 |
68 private: | 68 private: |
69 static const char kKey[]; | 69 static const char kKey[]; |
70 | 70 |
71 DISALLOW_COPY_AND_ASSIGN(SavePageExternalData); | 71 DISALLOW_COPY_AND_ASSIGN(SavePageData); |
72 }; | 72 }; |
73 | 73 |
74 const char SavePageExternalData::kKey[] = "DownloadItem SavePageExternalData"; | 74 const char SavePageData::kKey[] = "DownloadItem SavePageData"; |
75 | 75 |
76 void BeginDownload(content::DownloadUrlParameters* params) { | 76 void BeginDownload(content::DownloadUrlParameters* params) { |
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
78 // ResourceDispatcherHost{Base} is-not-a URLRequest::Delegate, and | 78 // ResourceDispatcherHost{Base} is-not-a URLRequest::Delegate, and |
79 // DownloadUrlParameters can-not include resource_dispatcher_host_impl.h, so | 79 // DownloadUrlParameters can-not include resource_dispatcher_host_impl.h, so |
80 // we must down cast. RDHI is the only subclass of RDH as of 2012 May 4. | 80 // we must down cast. RDHI is the only subclass of RDH as of 2012 May 4. |
81 scoped_ptr<net::URLRequest> request(new net::URLRequest( | 81 scoped_ptr<net::URLRequest> request(new net::URLRequest( |
82 params->url(), | 82 params->url(), |
83 NULL, | 83 NULL, |
84 params->resource_context()->GetRequestContext())); | 84 params->resource_context()->GetRequestContext())); |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 page_url, | 559 page_url, |
560 is_otr, | 560 is_otr, |
561 GetNextId(), | 561 GetNextId(), |
562 mime_type, | 562 mime_type, |
563 bound_net_log); | 563 bound_net_log); |
564 | 564 |
565 download->AddObserver(observer); | 565 download->AddObserver(observer); |
566 | 566 |
567 DCHECK(!ContainsKey(downloads_, download->GetId())); | 567 DCHECK(!ContainsKey(downloads_, download->GetId())); |
568 downloads_[download->GetId()] = download; | 568 downloads_[download->GetId()] = download; |
569 DCHECK(!SavePageExternalData::Get(download)); | 569 DCHECK(!SavePageData::Get(download)); |
570 new SavePageExternalData(download); | 570 new SavePageData(download); |
571 DCHECK(SavePageExternalData::Get(download)); | 571 DCHECK(SavePageData::Get(download)); |
572 | 572 |
573 // TODO(benjhayden): Fire OnDownloadCreated for SavePackage downloads when | 573 // TODO(benjhayden): Fire OnDownloadCreated for SavePackage downloads when |
574 // we're comfortable with the user interacting with them. | 574 // we're comfortable with the user interacting with them. |
575 // FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, download)); | 575 // FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, download)); |
576 | 576 |
577 // Will notify the observer in the callback. | 577 // Will notify the observer in the callback. |
578 if (delegate_) | 578 if (delegate_) |
579 delegate_->AddItemToPersistentStore(download); | 579 delegate_->AddItemToPersistentStore(download); |
580 | 580 |
581 return download; | 581 return download; |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 | 921 |
922 | 922 |
923 void DownloadManagerImpl::OnItemAddedToPersistentStore(int32 download_id, | 923 void DownloadManagerImpl::OnItemAddedToPersistentStore(int32 download_id, |
924 int64 db_handle) { | 924 int64 db_handle) { |
925 // It's valid that we don't find a matching item, i.e. on shutdown. | 925 // It's valid that we don't find a matching item, i.e. on shutdown. |
926 if (!ContainsKey(downloads_, download_id)) | 926 if (!ContainsKey(downloads_, download_id)) |
927 return; | 927 return; |
928 | 928 |
929 DownloadItemImpl* item = downloads_[download_id]; | 929 DownloadItemImpl* item = downloads_[download_id]; |
930 AddDownloadItemToHistory(item, db_handle); | 930 AddDownloadItemToHistory(item, db_handle); |
931 if (SavePageExternalData::Get(item)) { | 931 if (SavePageData::Get(item)) { |
932 OnSavePageItemAddedToPersistentStore(item); | 932 OnSavePageItemAddedToPersistentStore(item); |
933 } else { | 933 } else { |
934 OnDownloadItemAddedToPersistentStore(item); | 934 OnDownloadItemAddedToPersistentStore(item); |
935 } | 935 } |
936 } | 936 } |
937 | 937 |
938 // Once the new DownloadItem has been committed to the persistent store, | 938 // Once the new DownloadItem has been committed to the persistent store, |
939 // associate it with its db_handle (TODO(benjhayden) merge db_handle with id), | 939 // associate it with its db_handle (TODO(benjhayden) merge db_handle with id), |
940 // show it in the browser (TODO(benjhayden) the ui should observe us instead), | 940 // show it in the browser (TODO(benjhayden) the ui should observe us instead), |
941 // and notify observers (TODO(benjhayden) observers should be able to see the | 941 // and notify observers (TODO(benjhayden) observers should be able to see the |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 void DownloadManagerImpl::DownloadRenamedToFinalName( | 1115 void DownloadManagerImpl::DownloadRenamedToFinalName( |
1116 DownloadItemImpl* download) { | 1116 DownloadItemImpl* download) { |
1117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1118 // If the rename failed, we receive an OnDownloadInterrupted() call before we | 1118 // If the rename failed, we receive an OnDownloadInterrupted() call before we |
1119 // receive the DownloadRenamedToFinalName() call. | 1119 // receive the DownloadRenamedToFinalName() call. |
1120 if (delegate_) { | 1120 if (delegate_) { |
1121 delegate_->UpdatePathForItemInPersistentStore( | 1121 delegate_->UpdatePathForItemInPersistentStore( |
1122 download, download->GetFullPath()); | 1122 download, download->GetFullPath()); |
1123 } | 1123 } |
1124 } | 1124 } |
OLD | NEW |