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 "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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 json->SetString(kDangerKey, DangerString(download_item->GetDangerType())); | 253 json->SetString(kDangerKey, DangerString(download_item->GetDangerType())); |
254 json->SetString(kStateKey, StateString(download_item->GetState())); | 254 json->SetString(kStateKey, StateString(download_item->GetState())); |
255 json->SetBoolean(kCanResumeKey, download_item->CanResume()); | 255 json->SetBoolean(kCanResumeKey, download_item->CanResume()); |
256 json->SetBoolean(kPausedKey, download_item->IsPaused()); | 256 json->SetBoolean(kPausedKey, download_item->IsPaused()); |
257 json->SetString(kMimeKey, download_item->GetMimeType()); | 257 json->SetString(kMimeKey, download_item->GetMimeType()); |
258 json->SetString(kStartTimeKey, TimeToISO8601(download_item->GetStartTime())); | 258 json->SetString(kStartTimeKey, TimeToISO8601(download_item->GetStartTime())); |
259 json->SetInteger(kBytesReceivedKey, download_item->GetReceivedBytes()); | 259 json->SetInteger(kBytesReceivedKey, download_item->GetReceivedBytes()); |
260 json->SetInteger(kTotalBytesKey, download_item->GetTotalBytes()); | 260 json->SetInteger(kTotalBytesKey, download_item->GetTotalBytes()); |
261 json->SetBoolean(kIncognitoKey, profile->IsOffTheRecord()); | 261 json->SetBoolean(kIncognitoKey, profile->IsOffTheRecord()); |
262 if (download_item->GetState() == DownloadItem::INTERRUPTED) { | 262 if (download_item->GetState() == DownloadItem::INTERRUPTED) { |
263 json->SetString(kErrorKey, content::InterruptReasonDebugString( | 263 json->SetString(kErrorKey, content::DownloadInterruptReasonToString( |
264 download_item->GetLastReason())); | 264 download_item->GetLastReason())); |
265 } else if (download_item->GetState() == DownloadItem::CANCELLED) { | 265 } else if (download_item->GetState() == DownloadItem::CANCELLED) { |
266 json->SetString(kErrorKey, content::InterruptReasonDebugString( | 266 json->SetString(kErrorKey, content::DownloadInterruptReasonToString( |
267 content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED)); | 267 content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED)); |
268 } | 268 } |
269 if (!download_item->GetEndTime().is_null()) | 269 if (!download_item->GetEndTime().is_null()) |
270 json->SetString(kEndTimeKey, TimeToISO8601(download_item->GetEndTime())); | 270 json->SetString(kEndTimeKey, TimeToISO8601(download_item->GetEndTime())); |
271 base::TimeDelta time_remaining; | 271 base::TimeDelta time_remaining; |
272 if (download_item->TimeRemaining(&time_remaining)) { | 272 if (download_item->TimeRemaining(&time_remaining)) { |
273 base::Time now = base::Time::Now(); | 273 base::Time now = base::Time::Now(); |
274 json->SetString(kEstimatedEndTimeKey, TimeToISO8601(now + time_remaining)); | 274 json->SetString(kEstimatedEndTimeKey, TimeToISO8601(now + time_remaining)); |
275 } | 275 } |
276 DownloadedByExtension* by_ext = DownloadedByExtension::Get(download_item); | 276 DownloadedByExtension* by_ext = DownloadedByExtension::Get(download_item); |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 manager->DownloadUrl(download_params.Pass()); | 1030 manager->DownloadUrl(download_params.Pass()); |
1031 RecordDownloadSource(DOWNLOAD_INITIATED_BY_EXTENSION); | 1031 RecordDownloadSource(DOWNLOAD_INITIATED_BY_EXTENSION); |
1032 RecordApiFunctions(DOWNLOADS_FUNCTION_DOWNLOAD); | 1032 RecordApiFunctions(DOWNLOADS_FUNCTION_DOWNLOAD); |
1033 return true; | 1033 return true; |
1034 } | 1034 } |
1035 | 1035 |
1036 void DownloadsDownloadFunction::OnStarted( | 1036 void DownloadsDownloadFunction::OnStarted( |
1037 const base::FilePath& creator_suggested_filename, | 1037 const base::FilePath& creator_suggested_filename, |
1038 downloads::FilenameConflictAction creator_conflict_action, | 1038 downloads::FilenameConflictAction creator_conflict_action, |
1039 DownloadItem* item, | 1039 DownloadItem* item, |
1040 net::Error error) { | 1040 content::DownloadInterruptReason interrupt_reason) { |
1041 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1041 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1042 VLOG(1) << __FUNCTION__ << " " << item << " " << error; | 1042 VLOG(1) << __FUNCTION__ << " " << item << " " << interrupt_reason; |
1043 if (item) { | 1043 if (item) { |
1044 DCHECK_EQ(net::OK, error); | 1044 DCHECK_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); |
1045 SetResult(new base::FundamentalValue(static_cast<int>(item->GetId()))); | 1045 SetResult(new base::FundamentalValue(static_cast<int>(item->GetId()))); |
1046 if (!creator_suggested_filename.empty()) { | 1046 if (!creator_suggested_filename.empty()) { |
1047 ExtensionDownloadsEventRouterData* data = | 1047 ExtensionDownloadsEventRouterData* data = |
1048 ExtensionDownloadsEventRouterData::Get(item); | 1048 ExtensionDownloadsEventRouterData::Get(item); |
1049 if (!data) { | 1049 if (!data) { |
1050 data = new ExtensionDownloadsEventRouterData( | 1050 data = new ExtensionDownloadsEventRouterData( |
1051 item, | 1051 item, |
1052 scoped_ptr<base::DictionaryValue>(new base::DictionaryValue())); | 1052 scoped_ptr<base::DictionaryValue>(new base::DictionaryValue())); |
1053 } | 1053 } |
1054 data->CreatorSuggestedFilename( | 1054 data->CreatorSuggestedFilename( |
1055 creator_suggested_filename, creator_conflict_action); | 1055 creator_suggested_filename, creator_conflict_action); |
1056 } | 1056 } |
1057 new DownloadedByExtension( | 1057 new DownloadedByExtension( |
1058 item, GetExtension()->id(), GetExtension()->name()); | 1058 item, GetExtension()->id(), GetExtension()->name()); |
1059 item->UpdateObservers(); | 1059 item->UpdateObservers(); |
1060 } else { | 1060 } else { |
1061 DCHECK_NE(net::OK, error); | 1061 DCHECK_NE(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); |
1062 error_ = net::ErrorToString(error); | 1062 error_ = content::DownloadInterruptReasonToString(interrupt_reason); |
1063 } | 1063 } |
1064 SendResponse(error_.empty()); | 1064 SendResponse(error_.empty()); |
1065 } | 1065 } |
1066 | 1066 |
1067 DownloadsSearchFunction::DownloadsSearchFunction() {} | 1067 DownloadsSearchFunction::DownloadsSearchFunction() {} |
1068 | 1068 |
1069 DownloadsSearchFunction::~DownloadsSearchFunction() {} | 1069 DownloadsSearchFunction::~DownloadsSearchFunction() {} |
1070 | 1070 |
1071 bool DownloadsSearchFunction::RunImpl() { | 1071 bool DownloadsSearchFunction::RunImpl() { |
1072 scoped_ptr<downloads::Search::Params> params( | 1072 scoped_ptr<downloads::Search::Params> params( |
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1876 extensions::UnloadedExtensionInfo* unloaded = | 1876 extensions::UnloadedExtensionInfo* unloaded = |
1877 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); | 1877 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); |
1878 std::set<const extensions::Extension*>::iterator iter = | 1878 std::set<const extensions::Extension*>::iterator iter = |
1879 shelf_disabling_extensions_.find(unloaded->extension); | 1879 shelf_disabling_extensions_.find(unloaded->extension); |
1880 if (iter != shelf_disabling_extensions_.end()) | 1880 if (iter != shelf_disabling_extensions_.end()) |
1881 shelf_disabling_extensions_.erase(iter); | 1881 shelf_disabling_extensions_.erase(iter); |
1882 break; | 1882 break; |
1883 } | 1883 } |
1884 } | 1884 } |
1885 } | 1885 } |
OLD | NEW |