Index: chrome/browser/ui/webui/history_ui.cc |
diff --git a/chrome/browser/ui/webui/history_ui.cc b/chrome/browser/ui/webui/history_ui.cc |
index dff2bfd4de845584e6523284293e5705f1fc2dd2..affec54b85d2b1cf70e6895451f652c4a1e72f79 100644 |
--- a/chrome/browser/ui/webui/history_ui.cc |
+++ b/chrome/browser/ui/webui/history_ui.cc |
@@ -142,7 +142,7 @@ content::WebUIDataSource* CreateHistoryUIHTMLSource() { |
source->AddLocalizedString("rangenone", IDS_HISTORY_RANGE_NONE); |
source->AddLocalizedString("rangeweek", IDS_HISTORY_RANGE_WEEK); |
source->AddLocalizedString("rangemonth", IDS_HISTORY_RANGE_MONTH); |
- source->AddLocalizedString("displayfiltersites", IDS_GROUP_BY_DOMAIN_LABEL); |
+ source->AddLocalizedString("rangetoday", IDS_HISTORY_RANGE_TODAY); |
source->AddLocalizedString("numbervisits", IDS_HISTORY_NUMBER_VISITS); |
source->AddBoolean("groupByDomain", |
CommandLine::ForCurrentProcess()->HasSwitch( |
@@ -267,6 +267,7 @@ void BrowsingHistoryHandler::HandleQueryHistory(const ListValue* args) { |
// Parse the arguments from JavaScript. There are four required arguments: |
// - the text to search for (may be empty) |
+ // - the offset from which the search should start in multiple of the range. |
// - the range (number) of days to search for, used only for grouped |
// searches. |
// - the search cursor, an opaque value from a previous query result, which |
@@ -275,18 +276,23 @@ void BrowsingHistoryHandler::HandleQueryHistory(const ListValue* args) { |
// - the maximum number of results to return (may be 0, meaning that there |
// is no maximum). |
string16 search_text = ExtractStringValue(args); |
- int range; |
- if (!args->GetInteger(1, &range)) { |
+ int offset; |
+ if (!args->GetInteger(1, &offset)) { |
NOTREACHED() << "Failed to convert argument 1. "; |
return; |
} |
+ int range; |
+ if (!args->GetInteger(2, &range)) { |
+ NOTREACHED() << "Failed to convert argument 2. "; |
+ return; |
+ } |
switch (range) { |
case BrowsingHistoryHandler::MONTH: |
- SetQueryTimeInMonths(&options); |
+ SetQueryTimeInMonths(offset, &options); |
break; |
case BrowsingHistoryHandler::WEEK: |
- SetQueryTimeInWeeks(&options); |
+ SetQueryTimeInWeeks(offset, &options); |
break; |
case BrowsingHistoryHandler::NOT_GROUPED: |
break; |
@@ -295,15 +301,15 @@ void BrowsingHistoryHandler::HandleQueryHistory(const ListValue* args) { |
const Value* cursor_value; |
// Get the cursor. It must be either null, or a list. |
- if (!args->Get(2, &cursor_value) || |
+ if (!args->Get(3, &cursor_value) || |
(!cursor_value->IsType(Value::TYPE_NULL) && |
!history::QueryCursor::FromValue(cursor_value, &options.cursor))) { |
- NOTREACHED() << "Failed to convert argument 2. "; |
+ NOTREACHED() << "Failed to convert argument 3. "; |
return; |
} |
- if (!ExtractIntegerValueAtIndex(args, 3, &options.max_count)) { |
- NOTREACHED() << "Failed to convert argument 3."; |
+ if (!ExtractIntegerValueAtIndex(args, 4, &options.max_count)) { |
+ NOTREACHED() << "Failed to convert argument 4."; |
return; |
} |
@@ -541,28 +547,54 @@ void BrowsingHistoryHandler::RemoveWebHistoryComplete( |
} |
void BrowsingHistoryHandler::SetQueryTimeInWeeks( |
- history::QueryOptions* options) { |
+ int offset, history::QueryOptions* options) { |
// LocalMidnight returns the beginning of the current day so get the |
// beginning of the next one. |
base::Time midnight = base::Time::Now().LocalMidnight() + |
base::TimeDelta::FromDays(1); |
- options->end_time = midnight; |
- options->begin_time = midnight - base::TimeDelta::FromDays(7); |
+ options->end_time = midnight - |
+ base::TimeDelta::FromDays(7 * offset); |
+ options->begin_time = midnight - |
+ base::TimeDelta::FromDays(7 * (offset + 1)); |
} |
void BrowsingHistoryHandler::SetQueryTimeInMonths( |
- history::QueryOptions* options) { |
+ int offset, history::QueryOptions* options) { |
// Configure the begin point of the search to the start of the |
// current month. |
base::Time::Exploded exploded; |
base::Time::Now().LocalMidnight().LocalExplode(&exploded); |
exploded.day_of_month = 1; |
- options->begin_time = base::Time::FromLocalExploded(exploded); |
- // Set the end time of this first search to null (which will |
- // show results from the future, should the user's clock have |
- // been set incorrectly). |
- options->end_time = base::Time(); |
+ if (offset == 0) { |
+ options->begin_time = base::Time::FromLocalExploded(exploded); |
+ |
+ // Set the end time of this first search to null (which will |
+ // show results from the future, should the user's clock have |
+ // been set incorrectly). |
+ options->end_time = base::Time(); |
+ } else { |
+ // Set the end-time of this search to the end of the month that is |
+ // |offset| months before the search end point. The end time is not |
+ // inclusive, so we should set it to midnight on the first day of the |
+ // following month. |
+ exploded.month -= offset - 1; |
+ while (exploded.month < 1) { |
+ exploded.month += 12; |
+ exploded.year--; |
+ } |
+ options->end_time = base::Time::FromLocalExploded(exploded); |
+ |
+ // Set the begin-time of the search to the start of the month |
+ // that is |offset| months prior to search_start_. |
+ if (exploded.month > 1) { |
+ exploded.month--; |
+ } else { |
+ exploded.month = 12; |
+ exploded.year--; |
+ } |
+ options->begin_time = base::Time::FromLocalExploded(exploded); |
+ } |
} |
// Helper function for Observe that determines if there are any differences |