Ignore local file URLs from being synced

BUG=100356
Test=Unit tests

Review URL: https://chromiumcodereview.appspot.com/10802060

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151095 0039d316-1c4b-4281-b951-d872f2087c98
parent 72496825
...@@ -125,6 +125,10 @@ bool TypedUrlChangeProcessor::CreateOrUpdateSyncNode( ...@@ -125,6 +125,10 @@ bool TypedUrlChangeProcessor::CreateOrUpdateSyncNode(
return true; return true;
DCHECK(!visit_vector.empty()); DCHECK(!visit_vector.empty());
// Ignore URLs of local files.
if (url.url().SchemeIsFile())
return true;
syncer::WriteNode update_node(trans); syncer::WriteNode update_node(trans);
syncer::BaseNode::InitByLookupResult result = syncer::BaseNode::InitByLookupResult result =
update_node.InitByClientTagLookup(syncer::TYPED_URLS, tag); update_node.InitByClientTagLookup(syncer::TYPED_URLS, tag);
...@@ -286,9 +290,9 @@ void TypedUrlChangeProcessor::ApplyChangesFromSyncModel( ...@@ -286,9 +290,9 @@ void TypedUrlChangeProcessor::ApplyChangesFromSyncModel(
const sync_pb::TypedUrlSpecifics& typed_url( const sync_pb::TypedUrlSpecifics& typed_url(
sync_node.GetTypedUrlSpecifics()); sync_node.GetTypedUrlSpecifics());
DCHECK(typed_url.visits_size()); DCHECK(typed_url.visits_size());
// Ignore blank URLs - these should never happen in practice, but they // Ignore blank URLs or local file URLs- these should never happen
// can sneak into the data via browser import. // in practice, but they can sneak into the data via browser import.
if (typed_url.url().empty()) if (typed_url.url().empty() || GURL(typed_url.url()).SchemeIsFile())
continue; continue;
sync_pb::TypedUrlSpecifics filtered_url = sync_pb::TypedUrlSpecifics filtered_url =
model_associator_->FilterExpiredVisits(typed_url); model_associator_->FilterExpiredVisits(typed_url);
......
...@@ -119,6 +119,10 @@ bool TypedUrlModelAssociator::ShouldIgnoreUrl( ...@@ -119,6 +119,10 @@ bool TypedUrlModelAssociator::ShouldIgnoreUrl(
if (url.url().spec().empty()) if (url.url().spec().empty())
return true; return true;
// Ignore local file URLs.
if (GURL(url.url()).SchemeIsFile())
return true;
// We ignore URLs that were imported, but have never been visited by // We ignore URLs that were imported, but have never been visited by
// chromium. // chromium.
static const int kLastImportedSource = history::SOURCE_EXTENSION; static const int kLastImportedSource = history::SOURCE_EXTENSION;
......
...@@ -947,3 +947,54 @@ TEST_F(ProfileSyncServiceTypedUrlTest, FailToGetTypedURLs) { ...@@ -947,3 +947,54 @@ TEST_F(ProfileSyncServiceTypedUrlTest, FailToGetTypedURLs) {
// Can't check GetErrorPercentage(), because generating an unrecoverable // Can't check GetErrorPercentage(), because generating an unrecoverable
// error will free the model associator. // error will free the model associator.
} }
TEST_F(ProfileSyncServiceTypedUrlTest, IgnoreLocalFileURL) {
history::VisitVector original_visits;
// Create http and file url.
history::URLRow url_entry(MakeTypedUrlEntry("http://yey.com",
"yey", 12, 15, false,
&original_visits));
history::URLRow file_entry(MakeTypedUrlEntry("file:///kitty.jpg",
"kitteh", 12, 15, false,
&original_visits));
history::URLRows original_entries;
original_entries.push_back(url_entry);
original_entries.push_back(file_entry);
EXPECT_CALL((*history_backend_.get()), GetAllTypedURLs(_)).
WillRepeatedly(DoAll(SetArgumentPointee<0>(original_entries),
Return(true)));
EXPECT_CALL((*history_backend_.get()), GetMostRecentVisitsForURL(_, _, _)).
WillRepeatedly(DoAll(SetArgumentPointee<2>(original_visits),
Return(true)));
CreateRootHelper create_root(this, syncer::TYPED_URLS);
StartSyncService(create_root.callback());
history::VisitVector updated_visits;
// Create updates for the previous urls + a new file one.
history::URLRow updated_url_entry(MakeTypedUrlEntry("http://yey.com",
"yey", 20, 15, false,
&updated_visits));
history::URLRow updated_file_entry(MakeTypedUrlEntry("file:///cat.jpg",
"cat", 20, 15, false,
&updated_visits));
history::URLRow new_file_entry(MakeTypedUrlEntry("file:///dog.jpg",
"dog", 20, 15, false,
&updated_visits));
history::URLsModifiedDetails details;
details.changed_urls.push_back(updated_url_entry);
details.changed_urls.push_back(updated_file_entry);
details.changed_urls.push_back(new_file_entry);
scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&history_thread_));
notifier->Notify(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
content::Source<Profile>(&profile_),
content::Details<history::URLsModifiedDetails>(&details));
history::URLRows new_sync_entries;
GetTypedUrlsFromSyncDB(&new_sync_entries);
// We should ignore the local file urls (existing and updated),
// and only be left with the updated http url.
ASSERT_EQ(1U, new_sync_entries.size());
EXPECT_TRUE(URLsEqual(updated_url_entry, new_sync_entries[0]));
}
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