Commit 883ea33b authored by Sky Malice's avatar Sky Malice Committed by Commit Bot

Remove dead offset/range code from BrowsingHistoryHandler.

Bug: 
Change-Id: I2d45ac2eafaf6c838056e6070b4830f05a25f1cc
Reviewed-on: https://chromium-review.googlesource.com/569846Reviewed-by: default avatarcalamity <calamity@chromium.org>
Commit-Queue: Sky Malice <skym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487138}
parent 63199eeb
...@@ -305,10 +305,6 @@ const char kEnableGenericSensorName[] = "Generic Sensor"; ...@@ -305,10 +305,6 @@ const char kEnableGenericSensorName[] = "Generic Sensor";
const char kEnableGenericSensorDescription[] = const char kEnableGenericSensorDescription[] =
"Enable sensor APIs based on Generic Sensor API."; "Enable sensor APIs based on Generic Sensor API.";
const char kEnableGroupedHistoryName[] = "Group history by domain";
const char kEnableGroupedHistoryDescription[] =
"Group history by website domain (i.e. google.com) on chrome://history.";
const char kEnableHDRName[] = "HDR mode"; const char kEnableHDRName[] = "HDR mode";
const char kEnableHDRDescription[] = const char kEnableHDRDescription[] =
"Enables HDR support on compatible displays."; "Enables HDR support on compatible displays.";
......
...@@ -212,9 +212,6 @@ extern const char kEnableEnumeratingAudioDevicesDescription[]; ...@@ -212,9 +212,6 @@ extern const char kEnableEnumeratingAudioDevicesDescription[];
extern const char kEnableGenericSensorName[]; extern const char kEnableGenericSensorName[];
extern const char kEnableGenericSensorDescription[]; extern const char kEnableGenericSensorDescription[];
extern const char kEnableGroupedHistoryName[];
extern const char kEnableGroupedHistoryDescription[];
extern const char kEnableHDRName[]; extern const char kEnableHDRName[];
extern const char kEnableHDRDescription[]; extern const char kEnableHDRDescription[];
......
...@@ -35,8 +35,8 @@ var HistoryEntry; ...@@ -35,8 +35,8 @@ var HistoryEntry;
* BrowsingHistoryHandler::QueryComplete() * BrowsingHistoryHandler::QueryComplete()
* @typedef {{finished: boolean, * @typedef {{finished: boolean,
* hasSyncedResults: boolean, * hasSyncedResults: boolean,
* queryInterval: string, * queryEndTime: string,
* queryStartMonth: string, * queryStartTime: string,
* term: string}} * term: string}}
*/ */
var HistoryQuery; var HistoryQuery;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// Send the history query immediately. This allows the query to process during // Send the history query immediately. This allows the query to process during
// the initial page startup. // the initial page startup.
chrome.send('queryHistory', ['', 0, 0, 0, RESULTS_PER_PAGE]); chrome.send('queryHistory', ['', 0, RESULTS_PER_PAGE]);
chrome.send('getForeignSessions'); chrome.send('getForeignSessions');
/** @type {Promise} */ /** @type {Promise} */
......
...@@ -72,8 +72,6 @@ Polymer({ ...@@ -72,8 +72,6 @@ Polymer({
chrome.send('queryHistory', [ chrome.send('queryHistory', [
queryState.searchTerm, queryState.searchTerm,
0, // No grouped offset.
0, // Disable grouping.
lastVisitTime, lastVisitTime,
RESULTS_PER_PAGE, RESULTS_PER_PAGE,
]); ]);
......
...@@ -6,9 +6,6 @@ ...@@ -6,9 +6,6 @@
#include <stddef.h> #include <stddef.h>
#include <set>
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
...@@ -78,15 +75,6 @@ base::string16 GetRelativeDateLocalized(base::Clock* clock, ...@@ -78,15 +75,6 @@ base::string16 GetRelativeDateLocalized(base::Clock* clock,
return date_str; return date_str;
} }
// Sets the correct year when substracting months from a date.
void NormalizeMonths(base::Time::Exploded* exploded) {
// Decrease a year at a time until we have a proper date.
while (exploded->month < 1) {
exploded->month += 12;
exploded->year--;
}
}
// Gets the name and type of a device for the given sync client ID. // Gets the name and type of a device for the given sync client ID.
// |name| and |type| are out parameters. // |name| and |type| are out parameters.
void GetDeviceNameAndType(const browser_sync::ProfileSyncService* sync_service, void GetDeviceNameAndType(const browser_sync::ProfileSyncService* sync_service,
...@@ -295,41 +283,22 @@ void BrowsingHistoryHandler::HandleQueryHistory(const base::ListValue* args) { ...@@ -295,41 +283,22 @@ void BrowsingHistoryHandler::HandleQueryHistory(const base::ListValue* args) {
// Parse the arguments from JavaScript. There are five required arguments: // Parse the arguments from JavaScript. There are five required arguments:
// - the text to search for (may be empty) // - the text to search for (may be empty)
// - the offset from which the search should start (in multiples of week or
// month, set by the next argument).
// - the range (BrowsingHistoryHandler::Range) Enum value that sets the range
// of the query.
// - the end time for the query. Only results older than this time will be // - the end time for the query. Only results older than this time will be
// returned. // returned.
// - the maximum number of results to return (may be 0, meaning that there // - the maximum number of results to return (may be 0, meaning that there
// is no maximum). // is no maximum).
base::string16 search_text = ExtractStringValue(args); base::string16 search_text = ExtractStringValue(args);
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;
}
if (range == BrowsingHistoryHandler::MONTH)
SetQueryTimeInMonths(offset, &options);
else if (range == BrowsingHistoryHandler::WEEK)
SetQueryTimeInWeeks(offset, &options);
double end_time; double end_time;
if (!args->GetDouble(3, &end_time)) { if (!args->GetDouble(1, &end_time)) {
NOTREACHED() << "Failed to convert argument 3. "; NOTREACHED() << "Failed to convert argument 1. ";
return; return;
} }
if (end_time) if (end_time)
options.end_time = base::Time::FromJsTime(end_time); options.end_time = base::Time::FromJsTime(end_time);
if (!ExtractIntegerValueAtIndex(args, 4, &options.max_count)) { if (!ExtractIntegerValueAtIndex(args, 2, &options.max_count)) {
NOTREACHED() << "Failed to convert argument 4."; NOTREACHED() << "Failed to convert argument 2.";
return; return;
} }
...@@ -353,7 +322,7 @@ void BrowsingHistoryHandler::HandleRemoveVisits(const base::ListValue* args) { ...@@ -353,7 +322,7 @@ void BrowsingHistoryHandler::HandleRemoveVisits(const base::ListValue* args) {
NOTREACHED() << "Unable to extract arguments"; NOTREACHED() << "Unable to extract arguments";
return; return;
} }
DCHECK(timestamps->GetSize() > 0); DCHECK_GT(timestamps->GetSize(), 0U);
std::unique_ptr<BrowsingHistoryService::HistoryEntry> entry( std::unique_ptr<BrowsingHistoryService::HistoryEntry> entry(
new BrowsingHistoryService::HistoryEntry()); new BrowsingHistoryService::HistoryEntry());
...@@ -394,59 +363,6 @@ void BrowsingHistoryHandler::HandleRemoveBookmark(const base::ListValue* args) { ...@@ -394,59 +363,6 @@ void BrowsingHistoryHandler::HandleRemoveBookmark(const base::ListValue* args) {
bookmarks::RemoveAllBookmarks(model, GURL(url)); bookmarks::RemoveAllBookmarks(model, GURL(url));
} }
void BrowsingHistoryHandler::SetQueryTimeInWeeks(
int offset, history::QueryOptions* options) {
// LocalMidnight returns the beginning of the current day so get the
// beginning of the next one.
base::Time midnight =
clock_->Now().LocalMidnight() + base::TimeDelta::FromDays(1);
options->end_time = midnight -
base::TimeDelta::FromDays(7 * offset);
options->begin_time = midnight -
base::TimeDelta::FromDays(7 * (offset + 1));
}
void BrowsingHistoryHandler::SetQueryTimeInMonths(
int offset, history::QueryOptions* options) {
// Configure the begin point of the search to the start of the
// current month.
base::Time::Exploded exploded;
clock_->Now().LocalMidnight().LocalExplode(&exploded);
exploded.day_of_month = 1;
if (offset == 0) {
if (!base::Time::FromLocalExploded(exploded, &options->begin_time)) {
// TODO(maksims): implement errors handling here.
NOTIMPLEMENTED();
}
// 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 {
// Go back |offset| months in the past. The end time is not inclusive, so
// use the first day of the |offset| - 1 and |offset| months (e.g. for
// the last month, |offset| = 1, use the first days of the last month and
// the current month.
exploded.month -= offset - 1;
// Set the correct year.
NormalizeMonths(&exploded);
if (!base::Time::FromLocalExploded(exploded, &options->end_time)) {
// TODO(maksims): implement errors handling here.
NOTIMPLEMENTED();
}
exploded.month -= 1;
// Set the correct year
NormalizeMonths(&exploded);
if (!base::Time::FromLocalExploded(exploded, &options->begin_time)) {
// TODO(maksims): implement errors handling here.
NOTIMPLEMENTED();
}
}
}
void BrowsingHistoryHandler::OnQueryComplete( void BrowsingHistoryHandler::OnQueryComplete(
std::vector<BrowsingHistoryService::HistoryEntry>* results, std::vector<BrowsingHistoryService::HistoryEntry>* results,
BrowsingHistoryService::QueryResultsInfo* query_results_info) { BrowsingHistoryService::QueryResultsInfo* query_results_info) {
...@@ -490,17 +406,6 @@ void BrowsingHistoryHandler::OnQueryComplete( ...@@ -490,17 +406,6 @@ void BrowsingHistoryHandler::OnQueryComplete(
"queryEndTime", "queryEndTime",
GetRelativeDateLocalized(clock_.get(), query_results_info->end_time)); GetRelativeDateLocalized(clock_.get(), query_results_info->end_time));
// TODO(calamity): Clean up grouped-specific fields once grouped history is
// removed.
results_info.SetString(
"queryStartMonth",
base::TimeFormatMonthAndYear(query_results_info->start_time));
results_info.SetString(
"queryInterval",
base::DateIntervalFormat(query_results_info->start_time,
query_results_info->end_time,
base::DATE_FORMAT_MONTH_WEEKDAY_DAY));
web_ui()->CallJavascriptFunctionUnsafe("historyResult", results_info, web_ui()->CallJavascriptFunctionUnsafe("historyResult", results_info,
results_value); results_value);
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <memory> #include <memory>
#include <set> #include <set>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
...@@ -19,10 +20,6 @@ ...@@ -19,10 +20,6 @@
#include "chrome/browser/history/browsing_history_service_handler.h" #include "chrome/browser/history/browsing_history_service_handler.h"
#include "content/public/browser/web_ui_message_handler.h" #include "content/public/browser/web_ui_message_handler.h"
namespace history {
struct QueryOptions;
} // namespace history
// The handler for Javascript messages related to the "history" view. // The handler for Javascript messages related to the "history" view.
class BrowsingHistoryHandler : class BrowsingHistoryHandler :
public content::WebUIMessageHandler, public content::WebUIMessageHandler,
...@@ -64,29 +61,11 @@ class BrowsingHistoryHandler : ...@@ -64,29 +61,11 @@ class BrowsingHistoryHandler :
private: private:
FRIEND_TEST_ALL_PREFIXES(BrowsingHistoryHandlerTest, FRIEND_TEST_ALL_PREFIXES(BrowsingHistoryHandlerTest,
ObservingWebHistoryDeletions); ObservingWebHistoryDeletions);
FRIEND_TEST_ALL_PREFIXES(BrowsingHistoryHandlerTest, SetQueryTimeInWeeks);
FRIEND_TEST_ALL_PREFIXES(BrowsingHistoryHandlerTest, SetQueryTimeInMonths);
FRIEND_TEST_ALL_PREFIXES(BrowsingHistoryHandlerTest, MdTruncatesTitles); FRIEND_TEST_ALL_PREFIXES(BrowsingHistoryHandlerTest, MdTruncatesTitles);
// The range for which to return results:
// - ALLTIME: allows access to all the results in a paginated way.
// - WEEK: the last 7 days.
// - MONTH: the last calendar month.
enum Range {
ALL_TIME = 0,
WEEK = 1,
MONTH = 2
};
bool ExtractIntegerValueAtIndex( bool ExtractIntegerValueAtIndex(
const base::ListValue* value, int index, int* out_int); const base::ListValue* value, int index, int* out_int);
// Sets the query options for a week-wide query, |offset| weeks ago.
void SetQueryTimeInWeeks(int offset, history::QueryOptions* options);
// Sets the query options for a monthly query, |offset| months ago.
void SetQueryTimeInMonths(int offset, history::QueryOptions* options);
// The clock used to vend times. // The clock used to vend times.
std::unique_ptr<base::Clock> clock_; std::unique_ptr<base::Clock> clock_;
......
...@@ -88,7 +88,6 @@ class BrowsingHistoryHandlerWithWebUIForTesting ...@@ -88,7 +88,6 @@ class BrowsingHistoryHandlerWithWebUIForTesting
set_clock(base::WrapUnique(test_clock_)); set_clock(base::WrapUnique(test_clock_));
set_web_ui(web_ui); set_web_ui(web_ui);
test_clock_->SetNow(PretendNow()); test_clock_->SetNow(PretendNow());
} }
base::SimpleTestClock* test_clock() { return test_clock_; } base::SimpleTestClock* test_clock() { return test_clock_; }
...@@ -166,67 +165,6 @@ class BrowsingHistoryHandlerTest : public ::testing::Test { ...@@ -166,67 +165,6 @@ class BrowsingHistoryHandlerTest : public ::testing::Test {
std::unique_ptr<content::WebContents> web_contents_; std::unique_ptr<content::WebContents> web_contents_;
}; };
TEST_F(BrowsingHistoryHandlerTest, SetQueryTimeInWeeks) {
BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui());
history::QueryOptions options;
// Querying this week should result in end time being midnight tonight and
// begin time being midnight a week ago.
handler.SetQueryTimeInWeeks(0, &options);
base::Time midnight_tonight =
PretendNow().LocalMidnight() + base::TimeDelta::FromDays(1);
EXPECT_EQ(midnight_tonight, options.end_time);
base::Time midnight_a_week_ago =
midnight_tonight - base::TimeDelta::FromDays(7);
EXPECT_EQ(midnight_a_week_ago, options.begin_time);
// Querying 4 weeks ago should result in end time being midnight 4 weeks ago
// and begin time being midnight 5 weeks ago.
handler.SetQueryTimeInWeeks(4, &options);
base::Time midnight_4_weeks_ago =
PretendNow().LocalMidnight() - base::TimeDelta::FromDays(27);
EXPECT_EQ(midnight_4_weeks_ago, options.end_time);
base::Time midnight_5_weeks_ago =
midnight_4_weeks_ago - base::TimeDelta::FromDays(7);
EXPECT_EQ(midnight_5_weeks_ago, options.begin_time);
}
TEST_F(BrowsingHistoryHandlerTest, SetQueryTimeInMonths) {
BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui());
history::QueryOptions options;
base::Time::Exploded exploded_expected_time;
PretendNow().LocalExplode(&exploded_expected_time);
// Querying this month should result in end time being unset and begin time
// being midnight of the first.
handler.SetQueryTimeInMonths(0, &options);
EXPECT_EQ(base::Time(), options.end_time);
exploded_expected_time.day_of_month = 1;
exploded_expected_time.hour = 0;
base::Time first_jan_2015_midnight;
EXPECT_TRUE(base::Time::FromLocalExploded(exploded_expected_time,
&first_jan_2015_midnight));
EXPECT_EQ(first_jan_2015_midnight, options.begin_time);
// Querying 6 months ago should result in end time being 2014-08-01 and begin
// time being 2014-07-01.
handler.SetQueryTimeInMonths(6, &options);
exploded_expected_time.year = 2014;
exploded_expected_time.month = 8;
base::Time first_aug_2014_midnight;
EXPECT_TRUE(base::Time::FromLocalExploded(exploded_expected_time,
&first_aug_2014_midnight));
EXPECT_EQ(first_aug_2014_midnight, options.end_time);
exploded_expected_time.month = 7;
base::Time first_jul_2014_midnight;
EXPECT_TRUE(base::Time::FromLocalExploded(exploded_expected_time,
&first_jul_2014_midnight));
EXPECT_EQ(first_jul_2014_midnight, options.begin_time);
}
// Tests that BrowsingHistoryHandler is informed about WebHistoryService // Tests that BrowsingHistoryHandler is informed about WebHistoryService
// deletions. // deletions.
TEST_F(BrowsingHistoryHandlerTest, ObservingWebHistoryDeletions) { TEST_F(BrowsingHistoryHandlerTest, ObservingWebHistoryDeletions) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment