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

Side by Side Diff: chrome/browser/sync/test/integration/bookmarks_helper.cc

Issue 1128343004: Allow favicons for synced bookmarks to expire (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" 5 #include "chrome/browser/sync/test/integration/bookmarks_helper.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/rand_util.h" 14 #include "base/rand_util.h"
15 #include "base/run_loop.h"
15 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
19 #include "base/synchronization/waitable_event.h" 20 #include "base/synchronization/waitable_event.h"
20 #include "base/task/cancelable_task_tracker.h" 21 #include "base/task/cancelable_task_tracker.h"
21 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 22 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
22 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" 23 #include "chrome/browser/bookmarks/chrome_bookmark_client.h"
23 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" 24 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h"
24 #include "chrome/browser/favicon/favicon_service_factory.h" 25 #include "chrome/browser/favicon/favicon_service_factory.h"
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 node, profile, icon_url, image.As1xPNGBytes()); 263 node, profile, icon_url, image.As1xPNGBytes());
263 } 264 }
264 265
265 // Wait for the favicon for |node| to be invalidated. 266 // Wait for the favicon for |node| to be invalidated.
266 observer.WaitForSetFavicon(); 267 observer.WaitForSetFavicon();
267 // Wait for the BookmarkModel to fetch the updated favicon and for the new 268 // Wait for the BookmarkModel to fetch the updated favicon and for the new
268 // favicon to be sent to BookmarkChangeProcessor. 269 // favicon to be sent to BookmarkChangeProcessor.
269 GetFaviconData(model, node); 270 GetFaviconData(model, node);
270 } 271 }
271 272
273 // Expires the favicon for |profile| and |node|. |profile| may be
274 // |test()->verifier()|.
275 void ExpireFaviconImpl(Profile* profile, const BookmarkNode* node) {
276 favicon::FaviconService* favicon_service =
277 FaviconServiceFactory::GetForProfile(profile,
278 ServiceAccessType::EXPLICIT_ACCESS);
279 favicon_service->SetFaviconOutOfDateForPage(node->url());
280 }
281
282 // Called asynchronously from CheckFaviconExpired() with the favicon data from
283 // the database.
284 void OnGotFaviconForExpiryCheck(
285 const base::Closure& callback,
286 const favicon_base::FaviconRawBitmapResult& bitmap_result) {
287 ASSERT_TRUE(bitmap_result.is_valid());
288 ASSERT_TRUE(bitmap_result.expired);
289 callback.Run();
290 }
291
272 // Wait for all currently scheduled tasks on the history thread for all 292 // Wait for all currently scheduled tasks on the history thread for all
273 // profiles to complete and any notifications sent to the UI thread to have 293 // profiles to complete and any notifications sent to the UI thread to have
274 // finished processing. 294 // finished processing.
275 void WaitForHistoryToProcessPendingTasks() { 295 void WaitForHistoryToProcessPendingTasks() {
276 // Skip waiting for history to complete for tests without favicons. 296 // Skip waiting for history to complete for tests without favicons.
277 if (!urls_with_favicons_) 297 if (!urls_with_favicons_)
278 return; 298 return;
279 299
280 std::vector<Profile*> profiles_which_need_to_wait; 300 std::vector<Profile*> profiles_which_need_to_wait;
281 if (sync_datatype_helper::test()->use_verifier()) 301 if (sync_datatype_helper::test()->use_verifier())
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 image, 598 image,
579 favicon_source); 599 favicon_source);
580 } 600 }
581 SetFaviconImpl(sync_datatype_helper::test()->GetProfile(profile), 601 SetFaviconImpl(sync_datatype_helper::test()->GetProfile(profile),
582 node, 602 node,
583 icon_url, 603 icon_url,
584 image, 604 image,
585 favicon_source); 605 favicon_source);
586 } 606 }
587 607
608 void ExpireFavicon(int profile, const BookmarkNode* node) {
609 BookmarkModel* model = GetBookmarkModel(profile);
610 ASSERT_EQ(bookmarks::GetBookmarkNodeByID(model, node->id()), node)
611 << "Node " << node->GetTitle() << " does not belong to "
612 << "Profile " << profile;
613 ASSERT_EQ(BookmarkNode::URL, node->type()) << "Node " << node->GetTitle()
614 << " must be a url.";
615 ASSERT_EQ(1u, urls_with_favicons_->count(node->url()));
616
617 if (sync_datatype_helper::test()->use_verifier()) {
618 const BookmarkNode* v_node = nullptr;
619 FindNodeInVerifier(model, node, &v_node);
620 ExpireFaviconImpl(sync_datatype_helper::test()->verifier(), node);
621 }
622 ExpireFaviconImpl(sync_datatype_helper::test()->GetProfile(profile), node);
623
624 WaitForHistoryToProcessPendingTasks();
625 }
626
627 void CheckFaviconExpired(int profile, const GURL& icon_url) {
628 base::RunLoop run_loop;
629
630 favicon::FaviconService* favicon_service =
631 FaviconServiceFactory::GetForProfile(
632 sync_datatype_helper::test()->GetProfile(profile),
633 ServiceAccessType::EXPLICIT_ACCESS);
634 base::CancelableTaskTracker task_tracker;
635 favicon_service->GetRawFavicon(
636 icon_url, favicon_base::FAVICON, 0,
637 base::Bind(&OnGotFaviconForExpiryCheck, run_loop.QuitClosure()),
638 &task_tracker);
639
640 run_loop.Run();
641 }
642
588 const BookmarkNode* SetURL(int profile, 643 const BookmarkNode* SetURL(int profile,
589 const BookmarkNode* node, 644 const BookmarkNode* node,
590 const GURL& new_url) { 645 const GURL& new_url) {
591 BookmarkModel* model = GetBookmarkModel(profile); 646 BookmarkModel* model = GetBookmarkModel(profile);
592 if (bookmarks::GetBookmarkNodeByID(model, node->id()) != node) { 647 if (bookmarks::GetBookmarkNodeByID(model, node->id()) != node) {
593 LOG(ERROR) << "Node " << node->GetTitle() << " does not belong to " 648 LOG(ERROR) << "Node " << node->GetTitle() << " does not belong to "
594 << "Profile " << profile; 649 << "Profile " << profile;
595 return NULL; 650 return NULL;
596 } 651 }
597 if (sync_datatype_helper::test()->use_verifier()) { 652 if (sync_datatype_helper::test()->use_verifier()) {
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 957
903 std::string IndexedSubfolderName(int i) { 958 std::string IndexedSubfolderName(int i) {
904 return base::StringPrintf("Subfolder Name %d", i); 959 return base::StringPrintf("Subfolder Name %d", i);
905 } 960 }
906 961
907 std::string IndexedSubsubfolderName(int i) { 962 std::string IndexedSubsubfolderName(int i) {
908 return base::StringPrintf("Subsubfolder Name %d", i); 963 return base::StringPrintf("Subsubfolder Name %d", i);
909 } 964 }
910 965
911 } // namespace bookmarks_helper 966 } // namespace bookmarks_helper
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698