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

Unified Diff: chrome/browser/download/download_extension_api.cc

Issue 9425014: Fix most of the downloads api in incognito profiles (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: style Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/download/download_extension_api.cc
diff --git a/chrome/browser/download/download_extension_api.cc b/chrome/browser/download/download_extension_api.cc
index cdf0193ff2ef33882e4c8323ea762f597ede8def..0550179ccfda345cebd842cbe1588ed592c090ec 100644
--- a/chrome/browser/download/download_extension_api.cc
+++ b/chrome/browser/download/download_extension_api.cc
@@ -93,6 +93,7 @@ const char kHeaderValueKey[] = "value";
const char kHeaderBinaryValueKey[] = "binaryValue";
const char kHeadersKey[] = "headers";
const char kIdKey[] = "id";
+const char kIncognito[] = "incognito";
const char kLimitKey[] = "limit";
const char kMethodKey[] = "method";
const char kMimeKey[] = "mime";
@@ -196,6 +197,7 @@ scoped_ptr<base::DictionaryValue> DownloadItemToJSON(DownloadItem* item) {
(item->GetStartTime() - base::Time::UnixEpoch()).InMilliseconds());
json->SetInteger(kBytesReceivedKey, item->GetReceivedBytes());
json->SetInteger(kTotalBytesKey, item->GetTotalBytes());
+ json->SetBoolean(kIncognito, item->IsOtr());
if (item->GetState() == DownloadItem::INTERRUPTED) {
json->SetInteger(kErrorKey, static_cast<int>(item->GetLastReason()));
} else if (item->GetState() == DownloadItem::CANCELLED) {
@@ -307,6 +309,31 @@ bool IsNotTemporaryDownloadFilter(const DownloadItem& item) {
return !item.IsTemporary();
}
+void GetManagers(
+ Profile* profile,
+ bool include_incognito,
+ DownloadManager** manager, DownloadManager** incognito_manager) {
+ *manager = DownloadServiceFactory::GetForProfile(profile)->
+ GetDownloadManager();
+ *incognito_manager = NULL;
+ if (include_incognito && profile->HasOffTheRecordProfile())
+ *incognito_manager = DownloadServiceFactory::GetForProfile(profile->
+ GetOffTheRecordProfile())->GetDownloadManager();
+}
+
+DownloadItem* GetActiveItemInternal(
+ Profile* profile,
+ bool include_incognito,
+ int id) {
+ DownloadManager* manager = NULL;
+ DownloadManager* incognito_manager = NULL;
+ GetManagers(profile, include_incognito, &manager, &incognito_manager);
+ DownloadItem* download_item = manager->GetActiveDownloadItem(id);
+ if (!download_item && incognito_manager)
+ download_item = incognito_manager->GetActiveDownloadItem(id);
+ return download_item;
+}
+
} // namespace
bool DownloadsFunctionInterface::RunImplImpl(
@@ -334,6 +361,10 @@ SyncDownloadsFunction::function() const {
return function_;
}
+DownloadItem* SyncDownloadsFunction::GetActiveItem(int download_id) {
+ return GetActiveItemInternal(profile(), include_incognito(), download_id);
+}
+
AsyncDownloadsFunction::AsyncDownloadsFunction(
DownloadsFunctionInterface::DownloadsFunctionName function)
: function_(function) {
@@ -350,6 +381,10 @@ AsyncDownloadsFunction::function() const {
return function_;
}
+DownloadItem* AsyncDownloadsFunction::GetActiveItem(int download_id) {
+ return GetActiveItemInternal(profile(), include_incognito(), download_id);
+}
+
DownloadsDownloadFunction::DownloadsDownloadFunction()
: AsyncDownloadsFunction(DOWNLOADS_FUNCTION_DOWNLOAD) {
}
@@ -632,15 +667,21 @@ bool DownloadsSearchFunction::ParseOrderBy(const base::Value& order_by_value) {
}
bool DownloadsSearchFunction::RunInternal() {
+ DownloadManager* manager = NULL;
+ DownloadManager* incognito_manager = NULL;
+ GetManagers(profile(), include_incognito(), &manager, &incognito_manager);
DownloadQuery::DownloadVector all_items, cpp_results;
- DownloadManager* manager = DownloadServiceFactory::GetForProfile(profile())
- ->GetDownloadManager();
if (has_get_id_) {
DownloadItem* item = manager->GetDownloadItem(get_id_);
- if (item != NULL)
+ if (!item && incognito_manager)
+ item = incognito_manager->GetDownloadItem(get_id_);
+ if (item)
all_items.push_back(item);
} else {
manager->GetAllDownloads(FilePath(FILE_PATH_LITERAL("")), &all_items);
+ if (incognito_manager)
+ incognito_manager->GetAllDownloads(
+ FilePath(FILE_PATH_LITERAL("")), &all_items);
}
query_->Search(all_items.begin(), all_items.end(), &cpp_results);
base::ListValue* json_results = new base::ListValue();
@@ -666,13 +707,8 @@ bool DownloadsPauseFunction::ParseArgs() {
}
bool DownloadsPauseFunction::RunInternal() {
- DownloadManager* download_manager =
- DownloadServiceFactory::GetForProfile(profile())->GetDownloadManager();
- DownloadItem* download_item =
- download_manager->GetActiveDownloadItem(download_id_);
- DCHECK(!download_item || download_item->IsInProgress());
-
- if (!download_item) {
+ DownloadItem* download_item = GetActiveItem(download_id_);
+ if ((download_item == NULL) || !download_item->IsInProgress()) {
// This could be due to an invalid download ID, or it could be due to the
// download not being currently active.
error_ = download_extension_errors::kInvalidOperationError;
@@ -696,13 +732,8 @@ bool DownloadsResumeFunction::ParseArgs() {
}
bool DownloadsResumeFunction::RunInternal() {
- DownloadManager* download_manager =
- DownloadServiceFactory::GetForProfile(profile())->GetDownloadManager();
- DownloadItem* download_item =
- download_manager->GetActiveDownloadItem(download_id_);
- DCHECK(!download_item || download_item->IsInProgress());
-
- if (!download_item) {
+ DownloadItem* download_item = GetActiveItem(download_id_);
+ if (download_item == NULL) {
// This could be due to an invalid download ID, or it could be due to the
// download not being currently active.
error_ = download_extension_errors::kInvalidOperationError;
@@ -726,12 +757,8 @@ bool DownloadsCancelFunction::ParseArgs() {
}
bool DownloadsCancelFunction::RunInternal() {
- DownloadManager* download_manager =
- DownloadServiceFactory::GetForProfile(profile())->GetDownloadManager();
- DownloadItem* download_item =
- download_manager->GetActiveDownloadItem(download_id_);
-
- if (download_item)
+ DownloadItem* download_item = GetActiveItem(download_id_);
+ if (download_item != NULL)
download_item->Cancel(true);
// |download_item| can be NULL if the download ID was invalid or if the
// download is not currently active. Either way, we don't consider it a
@@ -862,10 +889,13 @@ bool DownloadsGetFileIconFunction::ParseArgs() {
DCHECK(icon_size_ == 16 || icon_size_ == 32);
}
- DownloadManager* download_manager =
- DownloadServiceFactory::GetForProfile(profile())->GetDownloadManager();
- DownloadItem* download_item = download_manager->GetDownloadItem(dl_id);
- if (download_item == NULL) {
+ DownloadManager* manager = NULL;
+ DownloadManager* incognito_manager = NULL;
+ GetManagers(profile(), include_incognito(), &manager, &incognito_manager);
+ DownloadItem* download_item = manager->GetDownloadItem(dl_id);
+ if (!download_item && incognito_manager)
+ download_item = incognito_manager->GetDownloadItem(dl_id);
+ if (!download_item) {
// The DownloadItem is is added to history when the path is determined. If
// the download is not in history, then we don't have a path / final
// filename and no icon.
« no previous file with comments | « chrome/browser/download/download_extension_api.h ('k') | chrome/browser/download/download_extension_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698