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

Unified Diff: chrome/browser/download/download_query.h

Issue 7192016: chrome.experimental.downloads (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: DownloadQuery, single DownloadMap Created 9 years, 6 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
« no previous file with comments | « chrome/browser/download/download_prefs.cc ('k') | chrome/browser/download/download_query.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/download_query.h
diff --git a/chrome/browser/download/download_query.h b/chrome/browser/download/download_query.h
new file mode 100644
index 0000000000000000000000000000000000000000..f391e9acb19d67f131d4c88afb1bccf60a420c70
--- /dev/null
+++ b/chrome/browser/download/download_query.h
@@ -0,0 +1,82 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_QUERY_H_
+#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_QUERY_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "base/callback.h"
+#include "chrome/browser/download/download_item.h"
+
+class DictionaryValue;
+class ListValue;
+
+namespace download_util {
+// Used to search for DownloadItems.
+//
+// std::vector<DownloadItem*> results;
+// std::string error_msg;
+// scoped_ptr<ListValue> json_results(new ListValue());
+// bool FilterOutOddDownloads(DownloadItem* item) {
+// CHECK(item);
+// return 0 == (item->id() % 2);
+// }
+// download_manager->Search(DownloadQuery().
+// filter_func(base::Bind(&FilterOutOddDownloads))->
+// filenameRegex(".*foo.*")->
+// urlRegex(".*foo.*"),
+// &results, &error_msg, json_results.get());
+class DownloadQuery {
+ public:
+ typedef base::Callback<bool(DownloadItem*)> FilterType;
+
+ DownloadQuery();
+
+ explicit DownloadQuery(const DictionaryValue& json);
+
+ ~DownloadQuery() {}
+
+ // Modify items in-place to sort, filter, and limit.
+ // If results is non-NULL, convert the results to json in it.
+ // Return true iff the query is well-formed. Return false and set error_msg if
+ // query is malformed.
+ bool Search(std::vector<DownloadItem*>* items,
+ std::string* error_msg = NULL,
+ ListValue* results = NULL) const;
+
+ // Chainable settors set a field to a value and return |this|.
+ DownloadQuery* filter_func(FilterType func);
+ DownloadQuery* state_enum(DownloadItem::DownloadState dstate);
+ DownloadQuery* danger_enum(DownloadItem::DangerType danger_type);
+#define Boolean bool
+#define Integer int
+#define String std::string
+#define FIELD(name, type) \
+ protected: bool has_ ## name ## _; \
+ protected: type name ## _; \
+ public: DownloadQuery* name(type value) { \
+ name ## _ = value; \
+ has_ ## name ## _ = true; \
+ return this; \
+ }
+#include "chrome/browser/download/download_query_fields.h"
+#undef FIELD
+#undef Boolean
+#undef Integer
+#undef String
+
+ protected:
+ FilterType filter_func_;
+ bool has_state_enum_;
+ DownloadItem::DownloadState state_enum_;
+ bool has_danger_enum_;
+ DownloadItem::DangerType danger_enum_;
+ // Allow copy and assign.
+};
+} // namespace download_util
+
+#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_QUERY_H_
« no previous file with comments | « chrome/browser/download/download_prefs.cc ('k') | chrome/browser/download/download_query.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698