DownloadsSearchFunction implements chrome.experimental.downloads.search() using DownloadQuery.

BUG=12133


Review URL: http://codereview.chromium.org/8917019

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119085 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/browser/download/download_manager_impl.cc b/content/browser/download/download_manager_impl.cc
index d391e56..cc8d55c8 100644
--- a/content/browser/download/download_manager_impl.cc
+++ b/content/browser/download/download_manager_impl.cc
@@ -32,6 +32,7 @@
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/content_browser_client.h"
 #include "content/public/browser/download_manager_delegate.h"
+#include "content/public/browser/download_query.h"
 #include "content/public/browser/notification_service.h"
 #include "content/public/browser/notification_types.h"
 #include "content/public/browser/render_process_host.h"
@@ -84,6 +85,30 @@
       *context);
 }
 
+class MapValueIteratorAdapter {
+ public:
+  explicit MapValueIteratorAdapter(
+      base::hash_map<int64, DownloadItem*>::const_iterator iter)
+    : iter_(iter) {
+  }
+  ~MapValueIteratorAdapter() {}
+
+  DownloadItem* operator*() { return iter_->second; }
+
+  MapValueIteratorAdapter& operator++() {
+    ++iter_;
+    return *this;
+  }
+
+  bool operator!=(const MapValueIteratorAdapter& that) const {
+    return iter_ != that.iter_;
+  }
+
+ private:
+  base::hash_map<int64, DownloadItem*>::const_iterator iter_;
+  // Allow copy and assign.
+};
+
 }  // namespace
 
 namespace content {
@@ -229,6 +254,12 @@
   }
 }
 
+void DownloadManagerImpl::SearchByQuery(const content::DownloadQuery& query,
+                                        DownloadVector* results) {
+  query.Search(MapValueIteratorAdapter(history_downloads_.begin()),
+               MapValueIteratorAdapter(history_downloads_.end()), results);
+}
+
 void DownloadManagerImpl::SearchDownloads(const string16& query,
                                           DownloadVector* result) {
   string16 query_lower(base::i18n::ToLower(query));
diff --git a/content/browser/download/download_manager_impl.h b/content/browser/download/download_manager_impl.h
index f323856..3a3253b 100644
--- a/content/browser/download/download_manager_impl.h
+++ b/content/browser/download/download_manager_impl.h
@@ -25,6 +25,10 @@
 class DownloadIdFactory;
 class DownloadStatusUpdater;
 
+namespace content {
+class DownloadQuery;
+}
+
 class CONTENT_EXPORT DownloadManagerImpl
     : public content::DownloadManager,
       public DownloadItemImpl::Delegate,
@@ -40,6 +44,8 @@
                                      DownloadVector* result) OVERRIDE;
   virtual void GetAllDownloads(const FilePath& dir_path,
                                DownloadVector* result) OVERRIDE;
+  virtual void SearchByQuery(const content::DownloadQuery& query,
+                             DownloadVector* results) OVERRIDE;
   virtual void SearchDownloads(const string16& query,
                                DownloadVector* result) OVERRIDE;
   virtual bool Init(content::BrowserContext* browser_context) OVERRIDE;
diff --git a/content/browser/download/download_query.cc b/content/browser/download/download_query.cc
deleted file mode 100644
index cc14b18a..0000000
--- a/content/browser/download/download_query.cc
+++ /dev/null
@@ -1,376 +0,0 @@
-// 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.
-
-#include "content/browser/download/download_query.h"
-
-#include <algorithm>
-#include <string>
-#include <vector>
-
-#include "base/bind.h"
-#include "base/callback.h"
-#include "base/file_path.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/stl_util.h"
-#include "base/string16.h"
-#include "base/string_split.h"
-#include "base/time.h"
-#include "base/utf_string_conversions.h"
-#include "base/values.h"
-#include "content/public/browser/download_item.h"
-#include "googleurl/src/gurl.h"
-#include "unicode/regex.h"
-
-using content::DownloadDangerType;
-using content::DownloadItem;
-
-namespace {
-
-// Templatized base::Value::GetAs*().
-template <typename T> bool GetAs(const base::Value& in, T* out);
-template<> bool GetAs(const base::Value& in, bool* out) {
-  return in.GetAsBoolean(out);
-}
-template<> bool GetAs(const base::Value& in, int* out) {
-  return in.GetAsInteger(out);
-}
-template<> bool GetAs(const base::Value& in, std::string* out) {
-  return in.GetAsString(out);
-}
-template<> bool GetAs(const base::Value& in, string16* out) {
-  return in.GetAsString(out);
-}
-
-// The next several functions are helpers for making Callbacks that access
-// DownloadItem fields.
-
-static bool MatchesQuery(const string16& value, const DownloadItem& item) {
-  return item.MatchesQuery(value);
-}
-
-static int GetStartTime(const DownloadItem& item) {
-  return (item.GetStartTime() - base::Time::UnixEpoch()).InMilliseconds();
-}
-
-static bool GetDangerAccepted(const DownloadItem& item) {
-  return (item.GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED);
-}
-
-static string16 GetFilename(const DownloadItem& item) {
-  // This filename will be compared with strings that could be passed in by the
-  // user, who only sees LossyDisplayNames.
-  return item.GetFullPath().LossyDisplayName();
-}
-
-static std::string GetFilenameUTF8(const DownloadItem& item) {
-  return UTF16ToUTF8(GetFilename(item));
-}
-
-static std::string GetUrl(const DownloadItem& item) {
-  return item.GetOriginalUrl().spec();
-}
-
-static DownloadItem::DownloadState GetState(const DownloadItem& item) {
-  return item.GetState();
-}
-
-static DownloadDangerType GetDangerType(const DownloadItem& item) {
-  return item.GetDangerType();
-}
-
-static int GetReceivedBytes(const DownloadItem& item) {
-  return item.GetReceivedBytes();
-}
-
-static int GetTotalBytes(const DownloadItem& item) {
-  return item.GetTotalBytes();
-}
-
-static std::string GetMimeType(const DownloadItem& item) {
-  return item.GetMimeType();
-}
-
-static bool IsPaused(const DownloadItem& item) {
-  return item.IsPaused();
-}
-
-// Wrap Callback to work around a bug in base::Bind/Callback where the inner
-// callback is nullified when the outer callback is Run.
-template<typename ValueType>
-class InnerCallback {
- public:
-  typedef base::Callback<ValueType(const DownloadItem&)> CallbackType;
-
-  explicit InnerCallback(const CallbackType& inner) : inner_(inner) {}
-  ~InnerCallback() {}
-
-  // Mimic Callback's interface to facilitate removing InnerCallback when the
-  // bug is fixed.
-  ValueType Run(const DownloadItem& item) const { return inner_.Run(item); }
-
- private:
-  CallbackType inner_;
-};
-
-enum ComparisonType {LT, EQ, GT};
-
-// Returns true if |item| matches the filter specified by |value|, |cmptype|,
-// and |accessor|. |accessor| is conceptually a function that takes a
-// DownloadItem and returns one of its fields, which is then compared to
-// |value|.
-template<typename ValueType>
-static bool FieldMatches(
-    const ValueType& value,
-    ComparisonType cmptype,
-    const InnerCallback<ValueType>& accessor,
-    const DownloadItem& item) {
-  switch (cmptype) {
-    case LT: return accessor.Run(item) < value;
-    case EQ: return accessor.Run(item) == value;
-    case GT: return accessor.Run(item) > value;
-  }
-  NOTREACHED();
-  return false;
-}
-
-// Helper for building a Callback to FieldMatches<>().
-template <typename ValueType> DownloadQuery::FilterCallback BuildFilter(
-    const base::Value& value, ComparisonType cmptype,
-    ValueType (*accessor)(const DownloadItem&)) {
-  ValueType cpp_value;
-  if (!GetAs(value, &cpp_value)) return DownloadQuery::FilterCallback();
-  return base::Bind(&FieldMatches<ValueType>, cpp_value, cmptype,
-                    InnerCallback<ValueType>(base::Bind(accessor)));
-}
-
-// Returns true if |accessor.Run(item)| matches |pattern|.
-static bool FindRegex(
-    icu::RegexPattern* pattern,
-    const InnerCallback<std::string>& accessor,
-    const DownloadItem& item) {
-  icu::UnicodeString input(accessor.Run(item).c_str());
-  UErrorCode status = U_ZERO_ERROR;
-  scoped_ptr<icu::RegexMatcher> matcher(pattern->matcher(input, status));
-  return matcher->find() == TRUE;  // Ugh, VS complains bool != UBool.
-}
-
-// Helper for building a Callback to FindRegex().
-DownloadQuery::FilterCallback BuildRegexFilter(
-    const base::Value& regex_value,
-    std::string (*accessor)(const DownloadItem&)) {
-  std::string regex_str;
-  if (!GetAs(regex_value, &regex_str)) return DownloadQuery::FilterCallback();
-  UParseError re_err;
-  UErrorCode re_status = U_ZERO_ERROR;
-  scoped_ptr<icu::RegexPattern> pattern(icu::RegexPattern::compile(
-      icu::UnicodeString::fromUTF8(regex_str), re_err, re_status));
-  if (!U_SUCCESS(re_status)) return DownloadQuery::FilterCallback();
-  return base::Bind(&FindRegex, base::Owned(pattern.release()),
-                    InnerCallback<std::string>(base::Bind(accessor)));
-}
-
-// Returns a ComparisonType to indicate whether a field in |left| is less than,
-// greater than or equal to the same field in |right|.
-template<typename ValueType>
-static ComparisonType Compare(
-    const InnerCallback<ValueType>& accessor,
-    const DownloadItem& left, const DownloadItem& right) {
-  ValueType left_value = accessor.Run(left);
-  ValueType right_value = accessor.Run(right);
-  if (left_value > right_value) return GT;
-  if (left_value < right_value) return LT;
-  DCHECK_EQ(left_value, right_value);
-  return EQ;
-}
-
-}  // anonymous namespace
-
-DownloadQuery::DownloadQuery()
-  : limit_(kuint32max) {
-}
-
-DownloadQuery::~DownloadQuery() {
-}
-
-// AddFilter() pushes a new FilterCallback to filters_. Most FilterCallbacks are
-// Callbacks to FieldMatches<>(). Search() iterates over given DownloadItems,
-// discarding items for which any filter returns false. A DownloadQuery may have
-// zero or more FilterCallbacks.
-
-bool DownloadQuery::AddFilter(const DownloadQuery::FilterCallback& value) {
-  if (value.is_null()) return false;
-  filters_.push_back(value);
-  return true;
-}
-
-void DownloadQuery::AddFilter(DownloadItem::DownloadState state) {
-  AddFilter(base::Bind(&FieldMatches<DownloadItem::DownloadState>, state, EQ,
-      InnerCallback<DownloadItem::DownloadState>(base::Bind(&GetState))));
-}
-
-void DownloadQuery::AddFilter(DownloadDangerType danger) {
-  AddFilter(base::Bind(&FieldMatches<DownloadDangerType>, danger, EQ,
-      InnerCallback<content::DownloadDangerType>(base::Bind(&GetDangerType))));
-}
-
-bool DownloadQuery::AddFilter(DownloadQuery::FilterType type,
-                              const base::Value& value) {
-  switch (type) {
-    case FILTER_BYTES_RECEIVED:
-      return AddFilter(BuildFilter<int>(value, EQ, &GetReceivedBytes));
-    case FILTER_DANGER_ACCEPTED:
-      return AddFilter(BuildFilter<bool>(value, EQ, &GetDangerAccepted));
-    case FILTER_FILENAME:
-      return AddFilter(BuildFilter<string16>(value, EQ, &GetFilename));
-    case FILTER_FILENAME_REGEX:
-      return AddFilter(BuildRegexFilter(value, &GetFilenameUTF8));
-    case FILTER_MIME:
-      return AddFilter(BuildFilter<std::string>(value, EQ, &GetMimeType));
-    case FILTER_PAUSED:
-      return AddFilter(BuildFilter<bool>(value, EQ, &IsPaused));
-    case FILTER_QUERY: {
-      string16 query;
-      return GetAs(value, &query) &&
-             AddFilter(base::Bind(&MatchesQuery, query));
-    }
-    case FILTER_STARTED_AFTER:
-      return AddFilter(BuildFilter<int>(value, GT, &GetStartTime));
-    case FILTER_STARTED_BEFORE:
-      return AddFilter(BuildFilter<int>(value, LT, &GetStartTime));
-    case FILTER_START_TIME:
-      return AddFilter(BuildFilter<int>(value, EQ, &GetStartTime));
-    case FILTER_TOTAL_BYTES:
-      return AddFilter(BuildFilter<int>(value, EQ, &GetTotalBytes));
-    case FILTER_TOTAL_BYTES_GREATER:
-      return AddFilter(BuildFilter<int>(value, GT, &GetTotalBytes));
-    case FILTER_TOTAL_BYTES_LESS:
-      return AddFilter(BuildFilter<int>(value, LT, &GetTotalBytes));
-    case FILTER_URL:
-      return AddFilter(BuildFilter<std::string>(value, EQ, &GetUrl));
-    case FILTER_URL_REGEX:
-      return AddFilter(BuildRegexFilter(value, &GetUrl));
-  }
-  return false;
-}
-
-bool DownloadQuery::Matches(const DownloadItem& item) const {
-  for (FilterCallbackVector::const_iterator filter = filters_.begin();
-        filter != filters_.end(); ++filter) {
-    if (!filter->Run(item))
-      return false;
-  }
-  return true;
-}
-
-// AddSorter() creates a Sorter and pushes it onto sorters_. A Sorter is a
-// direction and a Callback to Compare<>(). After filtering, Search() makes a
-// DownloadComparator functor from the sorters_ and passes the
-// DownloadComparator to std::partial_sort. std::partial_sort calls the
-// DownloadComparator with different pairs of DownloadItems.  DownloadComparator
-// iterates over the sorters until a callback returns ComparisonType LT or GT.
-// DownloadComparator returns true or false depending on that ComparisonType and
-// the sorter's direction in order to indicate to std::partial_sort whether the
-// left item is after or before the right item. If all sorters return EQ, then
-// DownloadComparator compares GetId. A DownloadQuery may have zero or more
-// Sorters, but there is one DownloadComparator per call to Search().
-
-struct DownloadQuery::Sorter {
-  typedef base::Callback<ComparisonType(
-      const DownloadItem&, const DownloadItem&)> SortType;
-
-  template<typename ValueType>
-  static Sorter Build(DownloadQuery::SortDirection adirection,
-                         ValueType (*accessor)(const DownloadItem&)) {
-    return Sorter(adirection, base::Bind(&Compare<ValueType>,
-        InnerCallback<ValueType>(base::Bind(accessor))));
-  }
-
-  Sorter(DownloadQuery::SortDirection adirection,
-            const SortType& asorter)
-    : direction(adirection),
-      sorter(asorter) {
-  }
-  ~Sorter() {}
-
-  DownloadQuery::SortDirection direction;
-  SortType sorter;
-};
-
-class DownloadQuery::DownloadComparator {
- public:
-  DownloadComparator(const DownloadQuery::SorterVector& terms)
-    : terms_(terms) {
-  }
-
-  // Returns true if |left| sorts before |right|.
-  bool operator() (const DownloadItem* left, const DownloadItem* right);
-
- private:
-  const DownloadQuery::SorterVector& terms_;
-
-  // std::sort requires this class to be copyable.
-};
-
-bool DownloadQuery::DownloadComparator::operator() (
-    const DownloadItem* left, const DownloadItem* right) {
-  for (DownloadQuery::SorterVector::const_iterator term = terms_.begin();
-       term != terms_.end(); ++term) {
-    switch (term->sorter.Run(*left, *right)) {
-      case LT: return term->direction == DownloadQuery::ASCENDING;
-      case GT: return term->direction == DownloadQuery::DESCENDING;
-      case EQ: break;  // break the switch but not the loop
-    }
-  }
-  CHECK_NE(left->GetId(), right->GetId());
-  return left->GetId() < right->GetId();
-}
-
-void DownloadQuery::AddSorter(DownloadQuery::SortType type,
-                              DownloadQuery::SortDirection direction) {
-  switch (type) {
-    case SORT_START_TIME:
-      sorters_.push_back(Sorter::Build<int>(direction, &GetStartTime));
-      break;
-    case SORT_URL:
-      sorters_.push_back(Sorter::Build<std::string>(direction, &GetUrl));
-      break;
-    case SORT_FILENAME:
-      sorters_.push_back(Sorter::Build<string16>(direction, &GetFilename));
-      break;
-    case SORT_DANGER:
-      sorters_.push_back(Sorter::Build<DownloadDangerType>(
-          direction, &GetDangerType));
-      break;
-    case SORT_DANGER_ACCEPTED:
-      sorters_.push_back(Sorter::Build<bool>(direction, &GetDangerAccepted));
-      break;
-    case SORT_STATE:
-      sorters_.push_back(Sorter::Build<DownloadItem::DownloadState>(
-          direction, &GetState));
-      break;
-    case SORT_PAUSED:
-      sorters_.push_back(Sorter::Build<bool>(direction, &IsPaused));
-      break;
-    case SORT_MIME:
-      sorters_.push_back(Sorter::Build<std::string>(direction, &GetMimeType));
-      break;
-    case SORT_BYTES_RECEIVED:
-      sorters_.push_back(Sorter::Build<int>(direction, &GetReceivedBytes));
-      break;
-    case SORT_TOTAL_BYTES:
-      sorters_.push_back(Sorter::Build<int>(direction, &GetTotalBytes));
-      break;
-  }
-}
-
-void DownloadQuery::FinishSearch(DownloadQuery::DownloadVector* results) const {
-  if (!sorters_.empty())
-    std::partial_sort(results->begin(),
-                      results->begin() + std::min(limit_, results->size()),
-                      results->end(),
-                      DownloadComparator(sorters_));
-  if (results->size() > limit_)
-    results->resize(limit_);
-}
diff --git a/content/browser/download/download_query.h b/content/browser/download/download_query.h
deleted file mode 100644
index a9f718de..0000000
--- a/content/browser/download/download_query.h
+++ /dev/null
@@ -1,149 +0,0 @@
-// 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 CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_QUERY_H_
-#define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_QUERY_H_
-#pragma once
-
-#include <map>
-#include <string>
-#include <vector>
-
-#include "base/callback_forward.h"
-#include "content/public/browser/download_item.h"
-
-namespace base {
-class Value;
-}
-
-// Filter and sort a vector of DownloadItem*s.
-//
-// The following example copies from |all_items| to |results| those
-// DownloadItem*s whose start time is 0 and whose id is odd, sorts primarily by
-// bytes received ascending and secondarily by url descending, and limits the
-// results to 20 items. Any number of filters or sorters is allowed. If all
-// sorters compare two DownloadItems equivalently, then they are sorted by their
-// id ascending.
-//
-// DownloadQuery query;
-// scoped_ptr<base::Value> start_time(base::Balue::CreateIntegerValue(0));
-// CHECK(query.AddFilter(FILTER_START_TIME, *start_time.get()));
-// bool FilterOutOddDownloads(const DownloadItem& item) {
-//   return 0 == (item.GetId() % 2);
-// }
-// CHECK(query.AddFilter(base::Bind(&FilterOutOddDownloads)));
-// query.AddSorter(SORT_BYTES_RECEIVED, ASCENDING);
-// query.AddSorter(SORT_URL, DESCENDING);
-// query.Limit(20);
-// DownloadVector all_items, results;
-// query.Search(all_items.begin(), all_items.end(), &results);
-class CONTENT_EXPORT DownloadQuery {
- public:
-  typedef std::vector<content::DownloadItem*> DownloadVector;
-
-  // FilterCallback is a Callback that takes a DownloadItem and returns true if
-  // the item matches the filter and false otherwise.
-  // query.AddFilter(base::Bind(&YourFilterFunction));
-  typedef base::Callback<bool(const content::DownloadItem&)> FilterCallback;
-
-  // All times are the number of milliseconds since the Unix epoch.
-  enum FilterType {
-    FILTER_BYTES_RECEIVED,       // int
-    FILTER_DANGER_ACCEPTED,      // bool
-    FILTER_FILENAME,             // string
-    FILTER_FILENAME_REGEX,       // string
-    FILTER_MIME,                 // string
-    FILTER_PAUSED,               // bool
-    FILTER_QUERY,                // string
-    FILTER_STARTED_AFTER,        // int
-    FILTER_STARTED_BEFORE,       // int
-    FILTER_START_TIME,           // int
-    FILTER_TOTAL_BYTES,          // int
-    FILTER_TOTAL_BYTES_GREATER,  // int
-    FILTER_TOTAL_BYTES_LESS,     // int
-    FILTER_URL,                  // string
-    FILTER_URL_REGEX,            // string
-  };
-
-  enum SortType {
-    SORT_BYTES_RECEIVED,
-    SORT_DANGER,
-    SORT_DANGER_ACCEPTED,
-    SORT_FILENAME,
-    SORT_MIME,
-    SORT_PAUSED,
-    SORT_START_TIME,
-    SORT_STATE,
-    SORT_TOTAL_BYTES,
-    SORT_URL,
-  };
-
-  enum SortDirection {
-    ASCENDING,
-    DESCENDING,
-  };
-
-  DownloadQuery();
-  ~DownloadQuery();
-
-  // Adds a new filter of type |type| with value |value| and returns true if
-  // |type| is valid and |value| is the correct Value-type and well-formed.
-  // Returns false if |type| is invalid or |value| is the incorrect Value-type
-  // or malformed.  Search() will filter out all DownloadItem*s that do not
-  // match all filters.  Multiple instances of the same FilterType are allowed,
-  // so you can pass two regexes to AddFilter(URL_REGEX,...) in order to
-  // Search() for items whose url matches both regexes. You can also pass two
-  // different DownloadStates to AddFilter(), which will cause Search() to
-  // filter out all items.
-  bool AddFilter(const FilterCallback& filter);
-  bool AddFilter(FilterType type, const base::Value& value);
-  void AddFilter(content::DownloadDangerType danger);
-  void AddFilter(content::DownloadItem::DownloadState state);
-
-  // Adds a new sorter of type |type| with direction |direction|.  After
-  // filtering DownloadItem*s, Search() will sort the results primarily by the
-  // sorter from the first call to Sort(), secondarily by the sorter from the
-  // second call to Sort(), and so on. For example, if the InputIterator passed
-  // to Search() yields four DownloadItems {id:0, error:0, start_time:0}, {id:1,
-  // error:0, start_time:1}, {id:2, error:1, start_time:0}, {id:3, error:1,
-  // start_time:1}, and Sort is called twice, once with (SORT_ERROR, ASCENDING)
-  // then with (SORT_START_TIME, DESCENDING), then Search() will return items
-  // ordered 1,0,3,2.
-  void AddSorter(SortType type, SortDirection direction);
-
-  // Limit the size of search results to |limit|.
-  void Limit(size_t limit) { limit_ = limit; }
-
-  // Filters DownloadItem*s from |iter| to |last| into |results|, sorts
-  // |results|, and limits the size of |results|. |results| must be non-NULL.
-  template <typename InputIterator>
-  void Search(InputIterator iter, const InputIterator last,
-              DownloadVector* results) const {
-    results->clear();
-    for (; iter != last; ++iter) {
-      if (Matches(**iter)) results->push_back(*iter);
-    }
-    FinishSearch(results);
-  }
-
- private:
-  struct Sorter;
-  class DownloadComparator;
-  typedef std::vector<FilterCallback> FilterCallbackVector;
-  typedef std::vector<Sorter> SorterVector;
-
-  bool FilterRegex(const std::string& regex_str,
-                   const base::Callback<std::string(
-                       const content::DownloadItem&)>& accessor);
-  bool Matches(const content::DownloadItem& item) const;
-  void FinishSearch(DownloadVector* results) const;
-
-  FilterCallbackVector filters_;
-  SorterVector sorters_;
-  size_t limit_;
-
-  DISALLOW_COPY_AND_ASSIGN(DownloadQuery);
-};
-
-#endif  // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_QUERY_H_
diff --git a/content/browser/download/download_query_unittest.cc b/content/browser/download/download_query_unittest.cc
index 60687ed..0f80bac 100644
--- a/content/browser/download/download_query_unittest.cc
+++ b/content/browser/download/download_query_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
 
@@ -12,7 +12,7 @@
 #include "base/string16.h"
 #include "base/time.h"
 #include "base/values.h"
-#include "content/browser/download/download_query.h"
+#include "content/public/browser/download_query.h"
 #include "content/browser/download/mock_download_item.h"
 #include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
@@ -23,6 +23,7 @@
 using base::Time;
 using base::Value;
 using content::DownloadItem;
+using content::DownloadQuery;
 typedef DownloadQuery::DownloadVector DownloadVector;
 
 namespace {
diff --git a/content/browser/download/mock_download_manager.h b/content/browser/download/mock_download_manager.h
index b8138a4..cf08d82e 100644
--- a/content/browser/download/mock_download_manager.h
+++ b/content/browser/download/mock_download_manager.h
@@ -12,6 +12,7 @@
 #include "content/browser/download/download_types.h"
 #include "content/public/browser/download_item.h"
 #include "content/public/browser/download_manager.h"
+#include "content/public/browser/download_query.h"
 #include "googleurl/src/gurl.h"
 #include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
@@ -27,6 +28,8 @@
                                            DownloadVector* result));
   MOCK_METHOD2(GetAllDownloads, void(const FilePath& dir_path,
                                      DownloadVector* result));
+  MOCK_METHOD2(SearchByQuery, void(const content::DownloadQuery& query,
+                                   DownloadVector* results));
   MOCK_METHOD2(SearchDownloads, void(const string16& query,
                                      DownloadVector* result));
   MOCK_METHOD1(Init, bool(content::BrowserContext* browser_context));