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

Unified Diff: chrome/browser/history/history_extension_api.cc

Issue 9358073: First version of the time slicing on the urls. Not ready for review yet. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added relative time to time slicing Created 8 years, 10 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/history/history_extension_api.h ('k') | chrome/browser/history/time_filter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
« no previous file with comments | « chrome/browser/history/history_extension_api.h ('k') | chrome/browser/history/time_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698