| 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_
|
|
|