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

Side by Side Diff: content/browser/download/save_package.cc

Issue 7277073: Support for adding save page download items into downloads history. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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
« no previous file with comments | « content/browser/download/save_package.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "content/browser/download/save_package.h" 5 #include "content/browser/download/save_package.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/i18n/file_util_icu.h" 11 #include "base/i18n/file_util_icu.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/stl_util-inl.h" 14 #include "base/stl_util-inl.h"
15 #include "base/string_piece.h" 15 #include "base/string_piece.h"
16 #include "base/string_split.h" 16 #include "base/string_split.h"
17 #include "base/sys_string_conversions.h" 17 #include "base/sys_string_conversions.h"
18 #include "base/task.h" 18 #include "base/task.h"
19 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
20 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
21 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/download/download_history.h"
22 #include "chrome/browser/download/download_item.h" 23 #include "chrome/browser/download/download_item.h"
23 #include "chrome/browser/download/download_item_model.h" 24 #include "chrome/browser/download/download_item_model.h"
24 #include "chrome/browser/download/download_manager.h" 25 #include "chrome/browser/download/download_manager.h"
25 #include "chrome/browser/download/download_util.h" 26 #include "chrome/browser/download/download_util.h"
26 #include "chrome/browser/net/url_fixer_upper.h" 27 #include "chrome/browser/net/url_fixer_upper.h"
27 #include "chrome/browser/platform_util.h" 28 #include "chrome/browser/platform_util.h"
28 #include "chrome/browser/prefs/pref_member.h" 29 #include "chrome/browser/prefs/pref_member.h"
29 #include "chrome/browser/prefs/pref_service.h" 30 #include "chrome/browser/prefs/pref_service.h"
30 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/browser/tab_contents/tab_util.h" 32 #include "chrome/browser/tab_contents/tab_util.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 #else 119 #else
119 FILE_PATH_LITERAL("html"); 120 FILE_PATH_LITERAL("html");
120 #endif 121 #endif
121 122
122 SavePackage::SavePackage(TabContents* tab_contents, 123 SavePackage::SavePackage(TabContents* tab_contents,
123 SavePackageType save_type, 124 SavePackageType save_type,
124 const FilePath& file_full_path, 125 const FilePath& file_full_path,
125 const FilePath& directory_full_path) 126 const FilePath& directory_full_path)
126 : TabContentsObserver(tab_contents), 127 : TabContentsObserver(tab_contents),
127 file_manager_(NULL), 128 file_manager_(NULL),
129 download_manager_(NULL),
128 download_(NULL), 130 download_(NULL),
129 page_url_(GetUrlToBeSaved()), 131 page_url_(GetUrlToBeSaved()),
130 saved_main_file_path_(file_full_path), 132 saved_main_file_path_(file_full_path),
131 saved_main_directory_path_(directory_full_path), 133 saved_main_directory_path_(directory_full_path),
132 title_(tab_contents->GetTitle()), 134 title_(tab_contents->GetTitle()),
133 finished_(false), 135 finished_(false),
134 user_canceled_(false), 136 user_canceled_(false),
135 disk_error_occurred_(false), 137 disk_error_occurred_(false),
136 save_type_(save_type), 138 save_type_(save_type),
137 all_save_items_count_(0), 139 all_save_items_count_(0),
138 wait_state_(INITIALIZE), 140 wait_state_(INITIALIZE),
139 tab_id_(tab_contents->GetRenderProcessHost()->id()), 141 tab_id_(tab_contents->GetRenderProcessHost()->id()),
140 unique_id_(g_save_package_id++), 142 unique_id_(g_save_package_id++),
141 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { 143 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
142 DCHECK(page_url_.is_valid()); 144 DCHECK(page_url_.is_valid());
143 DCHECK(save_type_ == SAVE_AS_ONLY_HTML || 145 DCHECK(save_type_ == SAVE_AS_ONLY_HTML ||
144 save_type_ == SAVE_AS_COMPLETE_HTML); 146 save_type_ == SAVE_AS_COMPLETE_HTML);
145 DCHECK(!saved_main_file_path_.empty() && 147 DCHECK(!saved_main_file_path_.empty() &&
146 saved_main_file_path_.value().length() <= kMaxFilePathLength); 148 saved_main_file_path_.value().length() <= kMaxFilePathLength);
147 DCHECK(!saved_main_directory_path_.empty() && 149 DCHECK(!saved_main_directory_path_.empty() &&
148 saved_main_directory_path_.value().length() < kMaxFilePathLength); 150 saved_main_directory_path_.value().length() < kMaxFilePathLength);
149 InternalInit(); 151 InternalInit();
150 } 152 }
151 153
152 SavePackage::SavePackage(TabContents* tab_contents) 154 SavePackage::SavePackage(TabContents* tab_contents)
153 : TabContentsObserver(tab_contents), 155 : TabContentsObserver(tab_contents),
154 file_manager_(NULL), 156 file_manager_(NULL),
157 download_manager_(NULL),
155 download_(NULL), 158 download_(NULL),
156 page_url_(GetUrlToBeSaved()), 159 page_url_(GetUrlToBeSaved()),
157 title_(tab_contents->GetTitle()), 160 title_(tab_contents->GetTitle()),
158 finished_(false), 161 finished_(false),
159 user_canceled_(false), 162 user_canceled_(false),
160 disk_error_occurred_(false), 163 disk_error_occurred_(false),
161 save_type_(SAVE_TYPE_UNKNOWN), 164 save_type_(SAVE_TYPE_UNKNOWN),
162 all_save_items_count_(0), 165 all_save_items_count_(0),
163 wait_state_(INITIALIZE), 166 wait_state_(INITIALIZE),
164 tab_id_(tab_contents->GetRenderProcessHost()->id()), 167 tab_id_(tab_contents->GetRenderProcessHost()->id()),
165 unique_id_(g_save_package_id++), 168 unique_id_(g_save_package_id++),
166 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { 169 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
167 DCHECK(page_url_.is_valid()); 170 DCHECK(page_url_.is_valid());
168 InternalInit(); 171 InternalInit();
169 } 172 }
170 173
171 // This is for testing use. Set |finished_| as true because we don't want 174 // This is for testing use. Set |finished_| as true because we don't want
172 // method Cancel to be be called in destructor in test mode. 175 // method Cancel to be be called in destructor in test mode.
173 // We also don't call InternalInit(). 176 // We also don't call InternalInit().
174 SavePackage::SavePackage(TabContents* tab_contents, 177 SavePackage::SavePackage(TabContents* tab_contents,
175 const FilePath& file_full_path, 178 const FilePath& file_full_path,
176 const FilePath& directory_full_path) 179 const FilePath& directory_full_path)
177 : TabContentsObserver(tab_contents), 180 : TabContentsObserver(tab_contents),
178 file_manager_(NULL), 181 file_manager_(NULL),
182 download_manager_(NULL),
179 download_(NULL), 183 download_(NULL),
180 saved_main_file_path_(file_full_path), 184 saved_main_file_path_(file_full_path),
181 saved_main_directory_path_(directory_full_path), 185 saved_main_directory_path_(directory_full_path),
182 finished_(true), 186 finished_(true),
183 user_canceled_(false), 187 user_canceled_(false),
184 disk_error_occurred_(false), 188 disk_error_occurred_(false),
185 save_type_(SAVE_TYPE_UNKNOWN), 189 save_type_(SAVE_TYPE_UNKNOWN),
186 all_save_items_count_(0), 190 all_save_items_count_(0),
187 wait_state_(INITIALIZE), 191 wait_state_(INITIALIZE),
188 tab_id_(0), 192 tab_id_(0),
189 unique_id_(g_save_package_id++), 193 unique_id_(g_save_package_id++),
190 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { 194 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
191 } 195 }
192 196
193 SavePackage::~SavePackage() { 197 SavePackage::~SavePackage() {
194 // Stop receiving saving job's updates 198 // Stop receiving saving job's updates
195 if (!finished_ && !canceled()) { 199 if (!finished_ && !canceled()) {
196 // Unexpected quit. 200 // Unexpected quit.
197 Cancel(true); 201 Cancel(true);
198 } 202 }
199 203
204 // We should no longer be observing the DownloadManager at this point.
205 CHECK(!download_manager_);
206 CHECK(!download_);
207
200 DCHECK(all_save_items_count_ == (waiting_item_queue_.size() + 208 DCHECK(all_save_items_count_ == (waiting_item_queue_.size() +
201 completed_count() + 209 completed_count() +
202 in_process_count())); 210 in_process_count()));
203 // Free all SaveItems. 211 // Free all SaveItems.
204 while (!waiting_item_queue_.empty()) { 212 while (!waiting_item_queue_.empty()) {
205 // We still have some items which are waiting for start to save. 213 // We still have some items which are waiting for start to save.
206 SaveItem* save_item = waiting_item_queue_.front(); 214 SaveItem* save_item = waiting_item_queue_.front();
207 waiting_item_queue_.pop(); 215 waiting_item_queue_.pop();
208 delete save_item; 216 delete save_item;
209 } 217 }
210 218
211 STLDeleteValues(&saved_success_items_); 219 STLDeleteValues(&saved_success_items_);
212 STLDeleteValues(&in_progress_items_); 220 STLDeleteValues(&in_progress_items_);
213 STLDeleteValues(&saved_failed_items_); 221 STLDeleteValues(&saved_failed_items_);
214 222
215 // The DownloadItem is owned by DownloadManager.
216 download_ = NULL;
217
218 file_manager_ = NULL; 223 file_manager_ = NULL;
219 } 224 }
220 225
221 GURL SavePackage::GetUrlToBeSaved() { 226 GURL SavePackage::GetUrlToBeSaved() {
222 // Instead of using tab_contents_.GetURL here, we use url() 227 // Instead of using tab_contents_.GetURL here, we use url()
223 // (which is the "real" url of the page) 228 // (which is the "real" url of the page)
224 // from the NavigationEntry because it reflects its' origin 229 // from the NavigationEntry because it reflects its' origin
225 // rather than the displayed one (returned by GetURL) which may be 230 // rather than the displayed one (returned by GetURL) which may be
226 // different (like having "view-source:" on the front). 231 // different (like having "view-source:" on the front).
227 NavigationEntry* active_entry = 232 NavigationEntry* active_entry =
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 267
263 wait_state_ = START_PROCESS; 268 wait_state_ = START_PROCESS;
264 269
265 // Initialize the request context and resource dispatcher. 270 // Initialize the request context and resource dispatcher.
266 Profile* profile = tab_contents()->profile(); 271 Profile* profile = tab_contents()->profile();
267 if (!profile) { 272 if (!profile) {
268 NOTREACHED(); 273 NOTREACHED();
269 return false; 274 return false;
270 } 275 }
271 276
272 // Create the fake DownloadItem and display the view. 277 // Get the download manager and add ourselves as an observer.
273 DownloadManager* download_manager = 278 download_manager_ = tab_contents()->profile()->GetDownloadManager();
274 tab_contents()->profile()->GetDownloadManager(); 279 if (!download_manager_) {
275 download_ = new DownloadItem(download_manager, 280 NOTREACHED();
281 return false;
282 }
283
284 // Create the download item.
285 download_ = new DownloadItem(download_manager_,
276 saved_main_file_path_, 286 saved_main_file_path_,
277 page_url_, 287 page_url_,
278 profile->IsOffTheRecord()); 288 profile->IsOffTheRecord());
279 289
280 // Transfer the ownership to the download manager. We need the DownloadItem 290 // Transfer ownership to the download manager.
281 // to be alive as long as the Profile is alive. 291 download_manager_->SavePageDownloadStarted(download_);
282 download_manager->SavePageAsDownloadStarted(download_); 292 download_manager_->AddObserver(this);
283
284 tab_contents()->OnStartDownload(download_);
285 293
286 // Check save type and process the save page job. 294 // Check save type and process the save page job.
287 if (save_type_ == SAVE_AS_COMPLETE_HTML) { 295 if (save_type_ == SAVE_AS_COMPLETE_HTML) {
288 // Get directory 296 // Get directory
289 DCHECK(!saved_main_directory_path_.empty()); 297 DCHECK(!saved_main_directory_path_.empty());
290 GetAllSavableResourceLinksForCurrentPage(); 298 GetAllSavableResourceLinksForCurrentPage();
291 } else { 299 } else {
292 wait_state_ = NET_FILES; 300 wait_state_ = NET_FILES;
293 SaveFileCreateInfo::SaveFileSource save_source = page_url_.SchemeIsFile() ? 301 SaveFileCreateInfo::SaveFileSource save_source = page_url_.SchemeIsFile() ?
294 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : 302 SaveFileCreateInfo::SAVE_FILE_FROM_FILE :
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 BrowserThread::PostTask( 644 BrowserThread::PostTask(
637 BrowserThread::FILE, FROM_HERE, 645 BrowserThread::FILE, FROM_HERE,
638 NewRunnableMethod(file_manager_, 646 NewRunnableMethod(file_manager_,
639 &SaveFileManager::RemoveSavedFileFromFileMap, 647 &SaveFileManager::RemoveSavedFileFromFileMap,
640 save_ids)); 648 save_ids));
641 649
642 finished_ = true; 650 finished_ = true;
643 wait_state_ = FAILED; 651 wait_state_ = FAILED;
644 652
645 // Inform the DownloadItem we have canceled whole save page job. 653 // Inform the DownloadItem we have canceled whole save page job.
646 download_->Cancel(false); 654 if (download_) {
655 download_->Cancel(false);
656 FinalizeDownloadEntry();
657 }
647 } 658 }
648 659
649 void SavePackage::CheckFinish() { 660 void SavePackage::CheckFinish() {
650 if (in_process_count() || finished_) 661 if (in_process_count() || finished_)
651 return; 662 return;
652 663
653 FilePath dir = (save_type_ == SAVE_AS_COMPLETE_HTML && 664 FilePath dir = (save_type_ == SAVE_AS_COMPLETE_HTML &&
654 saved_success_items_.size() > 1) ? 665 saved_success_items_.size() > 1) ?
655 saved_main_directory_path_ : FilePath(); 666 saved_main_directory_path_ : FilePath();
656 667
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 for (SaveUrlItemMap::iterator it = saved_failed_items_.begin(); 700 for (SaveUrlItemMap::iterator it = saved_failed_items_.begin();
690 it != saved_failed_items_.end(); ++it) 701 it != saved_failed_items_.end(); ++it)
691 save_ids.push_back(it->second->save_id()); 702 save_ids.push_back(it->second->save_id());
692 703
693 BrowserThread::PostTask( 704 BrowserThread::PostTask(
694 BrowserThread::FILE, FROM_HERE, 705 BrowserThread::FILE, FROM_HERE,
695 NewRunnableMethod(file_manager_, 706 NewRunnableMethod(file_manager_,
696 &SaveFileManager::RemoveSavedFileFromFileMap, 707 &SaveFileManager::RemoveSavedFileFromFileMap,
697 save_ids)); 708 save_ids));
698 709
699 download_->OnAllDataSaved(all_save_items_count_); 710 if (download_) {
700 download_->MarkAsComplete(); 711 download_->OnAllDataSaved(all_save_items_count_);
712 download_->MarkAsComplete();
713 FinalizeDownloadEntry();
714 }
701 715
702 NotificationService::current()->Notify( 716 NotificationService::current()->Notify(
703 chrome::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, 717 chrome::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
704 Source<SavePackage>(this), 718 Source<SavePackage>(this),
705 Details<GURL>(&page_url_)); 719 Details<GURL>(&page_url_));
706 } 720 }
707 721
708 // Called for updating end state. 722 // Called for updating end state.
709 void SavePackage::SaveFinished(int32 save_id, int64 size, bool is_success) { 723 void SavePackage::SaveFinished(int32 save_id, int64 size, bool is_success) {
710 // Because we might have canceled this saving job before, 724 // Because we might have canceled this saving job before,
711 // so we might not find corresponding SaveItem. Just ignore it. 725 // so we might not find corresponding SaveItem. Just ignore it.
712 SaveItem* save_item = LookupItemInProcessBySaveId(save_id); 726 SaveItem* save_item = LookupItemInProcessBySaveId(save_id);
713 if (!save_item) 727 if (!save_item)
714 return; 728 return;
715 729
716 // Let SaveItem set end state. 730 // Let SaveItem set end state.
717 save_item->Finish(size, is_success); 731 save_item->Finish(size, is_success);
718 // Remove the associated save id and SavePackage. 732 // Remove the associated save id and SavePackage.
719 file_manager_->RemoveSaveFile(save_id, save_item->url(), this); 733 file_manager_->RemoveSaveFile(save_id, save_item->url(), this);
720 734
721 PutInProgressItemToSavedMap(save_item); 735 PutInProgressItemToSavedMap(save_item);
722 736
723 // Inform the DownloadItem to update UI. 737 // Inform the DownloadItem to update UI.
724 // We use the received bytes as number of saved files. 738 // We use the received bytes as number of saved files.
725 download_->Update(completed_count()); 739 if (download_)
740 download_->Update(completed_count());
726 741
727 if (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM && 742 if (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM &&
728 save_item->url() == page_url_ && !save_item->received_bytes()) { 743 save_item->url() == page_url_ && !save_item->received_bytes()) {
729 // If size of main HTML page is 0, treat it as disk error. 744 // If size of main HTML page is 0, treat it as disk error.
730 Cancel(false); 745 Cancel(false);
731 return; 746 return;
732 } 747 }
733 748
734 if (canceled()) { 749 if (canceled()) {
735 DCHECK(finished_); 750 DCHECK(finished_);
(...skipping 20 matching lines...) Expand all
756 return; 771 return;
757 } 772 }
758 SaveItem* save_item = it->second; 773 SaveItem* save_item = it->second;
759 774
760 save_item->Finish(0, false); 775 save_item->Finish(0, false);
761 776
762 PutInProgressItemToSavedMap(save_item); 777 PutInProgressItemToSavedMap(save_item);
763 778
764 // Inform the DownloadItem to update UI. 779 // Inform the DownloadItem to update UI.
765 // We use the received bytes as number of saved files. 780 // We use the received bytes as number of saved files.
766 download_->Update(completed_count()); 781 if (download_)
782 download_->Update(completed_count());
767 783
768 if (save_type_ == SAVE_AS_ONLY_HTML || 784 if (save_type_ == SAVE_AS_ONLY_HTML ||
769 save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM) { 785 save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM) {
770 // We got error when saving page. Treat it as disk error. 786 // We got error when saving page. Treat it as disk error.
771 Cancel(true); 787 Cancel(true);
772 } 788 }
773 789
774 if (canceled()) { 790 if (canceled()) {
775 DCHECK(finished_); 791 DCHECK(finished_);
776 return; 792 return;
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 const std::vector<GURL>& referrers_list, 1055 const std::vector<GURL>& referrers_list,
1040 const std::vector<GURL>& frames_list) { 1056 const std::vector<GURL>& frames_list) {
1041 if (wait_state_ != RESOURCES_LIST) 1057 if (wait_state_ != RESOURCES_LIST)
1042 return; 1058 return;
1043 1059
1044 DCHECK(resources_list.size() == referrers_list.size()); 1060 DCHECK(resources_list.size() == referrers_list.size());
1045 all_save_items_count_ = static_cast<int>(resources_list.size()) + 1061 all_save_items_count_ = static_cast<int>(resources_list.size()) +
1046 static_cast<int>(frames_list.size()); 1062 static_cast<int>(frames_list.size());
1047 1063
1048 // We use total bytes as the total number of files we want to save. 1064 // We use total bytes as the total number of files we want to save.
1049 download_->set_total_bytes(all_save_items_count_); 1065 if (download_)
1066 download_->set_total_bytes(all_save_items_count_);
1050 1067
1051 if (all_save_items_count_) { 1068 if (all_save_items_count_) {
1052 // Put all sub-resources to wait list. 1069 // Put all sub-resources to wait list.
1053 for (int i = 0; i < static_cast<int>(resources_list.size()); ++i) { 1070 for (int i = 0; i < static_cast<int>(resources_list.size()); ++i) {
1054 const GURL& u = resources_list[i]; 1071 const GURL& u = resources_list[i];
1055 DCHECK(u.is_valid()); 1072 DCHECK(u.is_valid());
1056 SaveFileCreateInfo::SaveFileSource save_source = u.SchemeIsFile() ? 1073 SaveFileCreateInfo::SaveFileSource save_source = u.SchemeIsFile() ?
1057 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : 1074 SaveFileCreateInfo::SAVE_FILE_FROM_FILE :
1058 SaveFileCreateInfo::SAVE_FILE_FROM_NET; 1075 SaveFileCreateInfo::SAVE_FILE_FROM_NET;
1059 SaveItem* save_item = new SaveItem(u, referrers_list[i], 1076 SaveItem* save_item = new SaveItem(u, referrers_list[i],
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 bool SavePackage::IsSavableContents(const std::string& contents_mime_type) { 1343 bool SavePackage::IsSavableContents(const std::string& contents_mime_type) {
1327 // WebKit creates Document object when MIME type is application/xhtml+xml, 1344 // WebKit creates Document object when MIME type is application/xhtml+xml,
1328 // so we also support this MIME type. 1345 // so we also support this MIME type.
1329 return contents_mime_type == "text/html" || 1346 return contents_mime_type == "text/html" ||
1330 contents_mime_type == "text/xml" || 1347 contents_mime_type == "text/xml" ||
1331 contents_mime_type == "application/xhtml+xml" || 1348 contents_mime_type == "application/xhtml+xml" ||
1332 contents_mime_type == "text/plain" || 1349 contents_mime_type == "text/plain" ||
1333 contents_mime_type == "text/css" || 1350 contents_mime_type == "text/css" ||
1334 net::IsSupportedJavascriptMimeType(contents_mime_type.c_str()); 1351 net::IsSupportedJavascriptMimeType(contents_mime_type.c_str());
1335 } 1352 }
1353
1354 void SavePackage::StopObservation() {
1355 DCHECK(download_);
1356 DCHECK(download_manager_);
1357 if (download_manager_)
1358 download_manager_->RemoveObserver(this);
1359 download_ = NULL;
1360 download_manager_ = NULL;
1361 }
1362
1363 void SavePackage::ModelChanged() {
1364 DCHECK(download_);
1365 DCHECK(download_manager_);
1366
1367 // Check if our item has been deleted (after it was added).
1368 if (download_->db_handle() != DownloadHistory::kUninitializedHandle
1369 && download_manager_->GetDownloadItem(download_->id()) == NULL)
Randy Smith (Not in Mondays) 2011/07/20 19:48:43 This is an ok way to do this, but the standard pat
achuithb 2011/07/20 21:39:00 That is much better. Thanks. Done.
1370 StopObservation();
1371 }
1372
1373 void SavePackage::ManagerGoingDown() {
1374 // No instances of SavePackage should exist during profile cleanup,
1375 // which is when the manager shuts down.
1376 NOTREACHED();
1377 StopObservation();
1378 }
1379
1380 void SavePackage::FinalizeDownloadEntry() {
1381 DCHECK(download_);
1382 DCHECK(download_manager_);
1383 download_manager_->SavePageDownloadFinished(download_);
1384 StopObservation();
1385 }
OLDNEW
« no previous file with comments | « content/browser/download/save_package.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698