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 02536b44c5ac10462d81766b4cdf934e5dda6d3b..0adbfe07742a82abb4ecd4ce27b1f9b66d6133c6 100644 |
--- a/chrome/browser/history/history_extension_api.cc |
+++ b/chrome/browser/history/history_extension_api.cc |
@@ -11,6 +11,7 @@ |
#include "base/message_loop.h" |
#include "base/string_number_conversions.h" |
#include "base/values.h" |
+#include "chrome/browser/cancelable_request.h" |
#include "chrome/browser/extensions/extension_event_router.h" |
#include "chrome/browser/history/history.h" |
#include "chrome/browser/history/history_types.h" |
@@ -40,6 +41,7 @@ const char kUrlKey[] = "url"; |
const char kUrlsKey[] = "urls"; |
const char kVisitId[] = "visitId"; |
const char kVisitTime[] = "visitTime"; |
+const char kRedirectsKey[] = "redirects"; |
const char kOnVisited[] = "history.onVisited"; |
const char kOnVisitRemoved[] = "history.onVisitRemoved"; |
@@ -47,6 +49,8 @@ const char kOnVisitRemoved[] = "history.onVisitRemoved"; |
const char kInvalidIdError[] = "History item id is invalid."; |
const char kInvalidUrlError[] = "Url is invalid."; |
+const int kDaysOfHistory = 90; |
+ |
double MilliSecondsFromTime(const base::Time& time) { |
return 1000 * time.ToDoubleT(); |
} |
@@ -88,6 +92,20 @@ void AddVisitNode(const history::VisitRow& row, ListValue* list) { |
list->Append(dict); |
} |
+void AddMostVisitedNode(const history::MostVisitedURL& item, ListValue* list) { |
+ DictionaryValue* dict = new DictionaryValue(); |
+ ListValue* redirect_list = new ListValue(); |
+ dict->SetString(kUrlKey, item.url.spec()); |
+ dict->SetString(kTitleKey, item.title); |
+ for (history::RedirectList::const_iterator iterator = item.redirects.begin(); |
+ iterator != item.redirects.end(); ++iterator) { |
+ StringValue* redirect = new StringValue((*iterator).spec()); |
+ redirect_list->Append(redirect); |
+ } |
+ dict->Set(kRedirectsKey, redirect_list); |
+ list->Append(dict); |
+} |
+ |
} // namespace |
HistoryExtensionEventRouter::HistoryExtensionEventRouter() {} |
@@ -400,3 +418,35 @@ bool DeleteAllHistoryFunction::RunAsyncImpl() { |
void DeleteAllHistoryFunction::DeleteComplete() { |
SendAsyncResponse(); |
} |
+ |
+bool GetMostVisitedHistoryFunction::RunAsyncImpl() { |
+ DictionaryValue* json = NULL; |
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &json)); |
+ |
+ Value* value = NULL; |
+ int how_many = 0; |
+ EXTENSION_FUNCTION_VALIDATE(json->Get(kMaxResultsKey, &value)); |
+ value->GetAsInteger(&how_many); |
+ |
+ HistoryService* hs = profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); |
+ hs->QueryMostVisitedURLs( |
+ how_many, |
+ kDaysOfHistory, |
Aaron Boodman
2012/03/20 02:24:24
Why not allow developers to specify this too. You
|
+ &history_consumer_, |
+ base::Bind(&GetMostVisitedHistoryFunction::QueryComplete, |
+ base::Unretained(this))); |
+ return true; |
+} |
+ |
+void GetMostVisitedHistoryFunction::QueryComplete( |
+ CancelableRequestProvider::Handle handle, |
+ history::MostVisitedURLList pages) { |
+ ListValue* list = new ListValue(); |
+ for (history::MostVisitedURLList::const_iterator iterator = pages.begin(); |
+ iterator != pages.end(); |
+ ++iterator) { |
Aaron Boodman
2012/03/20 02:24:24
This can go on previous line.
|
+ AddMostVisitedNode(*iterator, list); |
+ } |
+ result_.reset(list); |
+ SendAsyncResponse(); |
+} |