Index: chrome/browser/history/history_extension_api.cc |
diff --git a/chrome/browser/history/history_extension_api.cc b/chrome/browser/history/history_extension_api.cc |
index 2d2695b573497729047c76815c3ddb6fcd23d36d..966677dc759acc28895b4b6b3867ec4db10753d1 100644 |
--- a/chrome/browser/history/history_extension_api.cc |
+++ b/chrome/browser/history/history_extension_api.cc |
@@ -14,6 +14,7 @@ |
#include "chrome/browser/extensions/extension_event_router.h" |
#include "chrome/browser/history/history.h" |
#include "chrome/browser/history/history_types.h" |
+#include "chrome/browser/history/time_filter.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/common/chrome_notification_types.h" |
#include "content/public/browser/notification_details.h" |
@@ -22,6 +23,7 @@ |
namespace { |
const char kAllHistoryKey[] = "allHistory"; |
+const char kDayOfTheWeekKey[] = "dayOfTheWeek"; |
const char kEndTimeKey[] = "endTime"; |
const char kFaviconUrlKey[] = "favIconUrl"; |
const char kIdKey[] = "id"; |
@@ -228,6 +230,59 @@ void HistoryFunctionWithCallback::SendResponseToCallback() { |
Release(); // Balanced in RunImpl(). |
} |
+bool GetMostVisitedHistoryFunction::RunAsyncImpl() { |
+ DictionaryValue* json; |
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &json)); |
+ |
+ history::TimeFilter time_filter; |
+ int max_results = 100; |
+ if (json->HasKey(kStartTimeKey)) { // Optional. |
+ Value* value; |
+ base::Time start_time; |
+ EXTENSION_FUNCTION_VALIDATE(json->Get(kStartTimeKey, &value)); |
+ EXTENSION_FUNCTION_VALIDATE(GetTimeFromValue(value, &start_time)); |
+ if (json->HasKey(kEndTimeKey)) { |
+ base::Time end_time; |
+ EXTENSION_FUNCTION_VALIDATE(json->Get(kEndTimeKey, &value)); |
+ EXTENSION_FUNCTION_VALIDATE(GetTimeFromValue(value, &end_time)); |
+ time_filter.SetTimeInRangeFilter(start_time, end_time); |
+ } |
+ } |
+ if (json->HasKey(kDayOfTheWeekKey)) { // Optional. |
+ int day; |
+ EXTENSION_FUNCTION_VALIDATE(json->GetInteger(kDayOfTheWeekKey, &day)); |
+ time_filter.SetDayOfTheWeekFilter(day, base::Time::Now()); |
+ } |
+ if (json->HasKey(kMaxResultsKey)) { // Optional. |
+ EXTENSION_FUNCTION_VALIDATE(json->GetInteger(kMaxResultsKey, &max_results)); |
+ } |
+ HistoryService* hs = profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); |
+ hs->QueryMostVisitedURLsDuringTime( |
+ max_results, time_filter, &cancelable_consumer_, |
+ base::Bind(&GetMostVisitedHistoryFunction::QueryComplete, |
+ base::Unretained(this))); |
+ return true; |
+} |
+ |
+void GetMostVisitedHistoryFunction::QueryComplete( |
+ CancelableRequestProvider::Handle handle, |
+ history::MostVisitedURLList data) { |
+ ListValue* list = new ListValue(); |
+ for (size_t i = 0; i < data.size(); i++) { |
+ const history::MostVisitedURL& queried_url = data[i]; |
+ if (queried_url.url.is_empty() && queried_url.title.empty()) |
+ continue; |
+ DictionaryValue* page_value = new DictionaryValue(); |
+ // TODO(georgey) add a real id. |
+ page_value->SetInteger("id", 0); |
+ page_value->SetString("url", queried_url.url.spec()); |
+ page_value->SetString("title", queried_url.title); |
+ list->Append(page_value); |
+ } |
+ result_.reset(list); |
+ SendAsyncResponse(); |
+} |
+ |
bool GetVisitsHistoryFunction::RunAsyncImpl() { |
DictionaryValue* json; |
EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &json)); |