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

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api.cc

Issue 114193009: [Download] Return DownloadInterruptReason from OnStartedCallback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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/extensions/api/downloads/downloads_api.h" 5 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cctype> 8 #include <cctype>
9 #include <iterator> 9 #include <iterator>
10 #include <set> 10 #include <set>
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 json->SetString(kDangerKey, DangerString(download_item->GetDangerType())); 255 json->SetString(kDangerKey, DangerString(download_item->GetDangerType()));
256 json->SetString(kStateKey, StateString(download_item->GetState())); 256 json->SetString(kStateKey, StateString(download_item->GetState()));
257 json->SetBoolean(kCanResumeKey, download_item->CanResume()); 257 json->SetBoolean(kCanResumeKey, download_item->CanResume());
258 json->SetBoolean(kPausedKey, download_item->IsPaused()); 258 json->SetBoolean(kPausedKey, download_item->IsPaused());
259 json->SetString(kMimeKey, download_item->GetMimeType()); 259 json->SetString(kMimeKey, download_item->GetMimeType());
260 json->SetString(kStartTimeKey, TimeToISO8601(download_item->GetStartTime())); 260 json->SetString(kStartTimeKey, TimeToISO8601(download_item->GetStartTime()));
261 json->SetInteger(kBytesReceivedKey, download_item->GetReceivedBytes()); 261 json->SetInteger(kBytesReceivedKey, download_item->GetReceivedBytes());
262 json->SetInteger(kTotalBytesKey, download_item->GetTotalBytes()); 262 json->SetInteger(kTotalBytesKey, download_item->GetTotalBytes());
263 json->SetBoolean(kIncognitoKey, profile->IsOffTheRecord()); 263 json->SetBoolean(kIncognitoKey, profile->IsOffTheRecord());
264 if (download_item->GetState() == DownloadItem::INTERRUPTED) { 264 if (download_item->GetState() == DownloadItem::INTERRUPTED) {
265 json->SetString(kErrorKey, content::InterruptReasonDebugString( 265 json->SetString(kErrorKey,
266 download_item->GetLastReason())); 266 content::DownloadInterruptReasonToString(
267 download_item->GetLastReason()));
267 } else if (download_item->GetState() == DownloadItem::CANCELLED) { 268 } else if (download_item->GetState() == DownloadItem::CANCELLED) {
268 json->SetString(kErrorKey, content::InterruptReasonDebugString( 269 json->SetString(kErrorKey,
269 content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED)); 270 content::DownloadInterruptReasonToString(
271 content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED));
270 } 272 }
271 if (!download_item->GetEndTime().is_null()) 273 if (!download_item->GetEndTime().is_null())
272 json->SetString(kEndTimeKey, TimeToISO8601(download_item->GetEndTime())); 274 json->SetString(kEndTimeKey, TimeToISO8601(download_item->GetEndTime()));
273 base::TimeDelta time_remaining; 275 base::TimeDelta time_remaining;
274 if (download_item->TimeRemaining(&time_remaining)) { 276 if (download_item->TimeRemaining(&time_remaining)) {
275 base::Time now = base::Time::Now(); 277 base::Time now = base::Time::Now();
276 json->SetString(kEstimatedEndTimeKey, TimeToISO8601(now + time_remaining)); 278 json->SetString(kEstimatedEndTimeKey, TimeToISO8601(now + time_remaining));
277 } 279 }
278 DownloadedByExtension* by_ext = DownloadedByExtension::Get(download_item); 280 DownloadedByExtension* by_ext = DownloadedByExtension::Get(download_item);
279 if (by_ext) { 281 if (by_ext) {
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 manager->DownloadUrl(download_params.Pass()); 1034 manager->DownloadUrl(download_params.Pass());
1033 RecordDownloadSource(DOWNLOAD_INITIATED_BY_EXTENSION); 1035 RecordDownloadSource(DOWNLOAD_INITIATED_BY_EXTENSION);
1034 RecordApiFunctions(DOWNLOADS_FUNCTION_DOWNLOAD); 1036 RecordApiFunctions(DOWNLOADS_FUNCTION_DOWNLOAD);
1035 return true; 1037 return true;
1036 } 1038 }
1037 1039
1038 void DownloadsDownloadFunction::OnStarted( 1040 void DownloadsDownloadFunction::OnStarted(
1039 const base::FilePath& creator_suggested_filename, 1041 const base::FilePath& creator_suggested_filename,
1040 downloads::FilenameConflictAction creator_conflict_action, 1042 downloads::FilenameConflictAction creator_conflict_action,
1041 DownloadItem* item, 1043 DownloadItem* item,
1042 net::Error error) { 1044 content::DownloadInterruptReason interrupt_reason) {
1043 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1045 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1044 VLOG(1) << __FUNCTION__ << " " << item << " " << error; 1046 VLOG(1) << __FUNCTION__ << " " << item << " " << interrupt_reason;
1045 if (item) { 1047 if (item) {
1046 DCHECK_EQ(net::OK, error); 1048 DCHECK_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason);
1047 SetResult(new base::FundamentalValue(static_cast<int>(item->GetId()))); 1049 SetResult(new base::FundamentalValue(static_cast<int>(item->GetId())));
1048 if (!creator_suggested_filename.empty()) { 1050 if (!creator_suggested_filename.empty()) {
1049 ExtensionDownloadsEventRouterData* data = 1051 ExtensionDownloadsEventRouterData* data =
1050 ExtensionDownloadsEventRouterData::Get(item); 1052 ExtensionDownloadsEventRouterData::Get(item);
1051 if (!data) { 1053 if (!data) {
1052 data = new ExtensionDownloadsEventRouterData( 1054 data = new ExtensionDownloadsEventRouterData(
1053 item, 1055 item,
1054 scoped_ptr<base::DictionaryValue>(new base::DictionaryValue())); 1056 scoped_ptr<base::DictionaryValue>(new base::DictionaryValue()));
1055 } 1057 }
1056 data->CreatorSuggestedFilename( 1058 data->CreatorSuggestedFilename(
1057 creator_suggested_filename, creator_conflict_action); 1059 creator_suggested_filename, creator_conflict_action);
1058 } 1060 }
1059 new DownloadedByExtension( 1061 new DownloadedByExtension(
1060 item, GetExtension()->id(), GetExtension()->name()); 1062 item, GetExtension()->id(), GetExtension()->name());
1061 item->UpdateObservers(); 1063 item->UpdateObservers();
1062 } else { 1064 } else {
1063 DCHECK_NE(net::OK, error); 1065 DCHECK_NE(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason);
1064 error_ = net::ErrorToString(error); 1066 error_ = content::DownloadInterruptReasonToString(interrupt_reason);
1065 } 1067 }
1066 SendResponse(error_.empty()); 1068 SendResponse(error_.empty());
1067 } 1069 }
1068 1070
1069 DownloadsSearchFunction::DownloadsSearchFunction() {} 1071 DownloadsSearchFunction::DownloadsSearchFunction() {}
1070 1072
1071 DownloadsSearchFunction::~DownloadsSearchFunction() {} 1073 DownloadsSearchFunction::~DownloadsSearchFunction() {}
1072 1074
1073 bool DownloadsSearchFunction::RunImpl() { 1075 bool DownloadsSearchFunction::RunImpl() {
1074 scoped_ptr<downloads::Search::Params> params( 1076 scoped_ptr<downloads::Search::Params> params(
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
1904 extensions::UnloadedExtensionInfo* unloaded = 1906 extensions::UnloadedExtensionInfo* unloaded =
1905 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); 1907 content::Details<extensions::UnloadedExtensionInfo>(details).ptr();
1906 std::set<const extensions::Extension*>::iterator iter = 1908 std::set<const extensions::Extension*>::iterator iter =
1907 shelf_disabling_extensions_.find(unloaded->extension); 1909 shelf_disabling_extensions_.find(unloaded->extension);
1908 if (iter != shelf_disabling_extensions_.end()) 1910 if (iter != shelf_disabling_extensions_.end())
1909 shelf_disabling_extensions_.erase(iter); 1911 shelf_disabling_extensions_.erase(iter);
1910 break; 1912 break;
1911 } 1913 }
1912 } 1914 }
1913 } 1915 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698