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

Side by Side Diff: components/favicon/core/favicon_driver_impl.cc

Issue 2691933004: Avoid cyclic dependency FaviconHandler<-->FaviconDriverImpl (Closed)
Patch Set: Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/favicon/core/favicon_driver_impl.h" 5 #include "components/favicon/core/favicon_driver_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "components/bookmarks/browser/bookmark_model.h"
11 #include "components/favicon/core/favicon_driver_observer.h" 10 #include "components/favicon/core/favicon_driver_observer.h"
12 #include "components/favicon/core/favicon_handler.h" 11 #include "components/favicon/core/favicon_handler.h"
13 #include "components/favicon/core/favicon_service.h" 12 #include "components/favicon/core/favicon_service.h"
14 #include "components/history/core/browser/history_service.h" 13 #include "components/history/core/browser/history_service.h"
15 14
16 namespace favicon { 15 namespace favicon {
17 namespace { 16 namespace {
18 17
19 #if defined(OS_ANDROID) || defined(OS_IOS) 18 #if defined(OS_ANDROID) || defined(OS_IOS)
20 const bool kEnableTouchIcon = true; 19 const bool kEnableTouchIcon = true;
21 #else 20 #else
22 const bool kEnableTouchIcon = false; 21 const bool kEnableTouchIcon = false;
23 #endif 22 #endif
24 23
25 } // namespace 24 } // namespace
26 25
27 FaviconDriverImpl::FaviconDriverImpl(FaviconService* favicon_service, 26 FaviconDriverImpl::FaviconDriverImpl(FaviconService* favicon_service,
28 history::HistoryService* history_service, 27 history::HistoryService* history_service,
29 bookmarks::BookmarkModel* bookmark_model) 28 FaviconHandler::Delegate* delegate)
30 : favicon_service_(favicon_service), 29 : favicon_service_(favicon_service), history_service_(history_service) {
31 history_service_(history_service),
32 bookmark_model_(bookmark_model) {
33 favicon_handler_.reset(new FaviconHandler( 30 favicon_handler_.reset(new FaviconHandler(
34 favicon_service_, this, kEnableTouchIcon 31 favicon_service_, delegate,
35 ? FaviconDriverObserver::NON_TOUCH_LARGEST 32 kEnableTouchIcon ? FaviconDriverObserver::NON_TOUCH_LARGEST
36 : FaviconDriverObserver::NON_TOUCH_16_DIP)); 33 : FaviconDriverObserver::NON_TOUCH_16_DIP));
37 if (kEnableTouchIcon) { 34 if (kEnableTouchIcon) {
38 touch_icon_handler_.reset(new FaviconHandler( 35 touch_icon_handler_.reset(new FaviconHandler(
39 favicon_service_, this, FaviconDriverObserver::TOUCH_LARGEST)); 36 favicon_service_, delegate, FaviconDriverObserver::TOUCH_LARGEST));
40 } 37 }
41 } 38 }
42 39
43 FaviconDriverImpl::~FaviconDriverImpl() { 40 FaviconDriverImpl::~FaviconDriverImpl() {
44 } 41 }
45 42
46 void FaviconDriverImpl::FetchFavicon(const GURL& url) { 43 void FaviconDriverImpl::FetchFavicon(const GURL& url) {
47 favicon_handler_->FetchFavicon(url); 44 favicon_handler_->FetchFavicon(url);
48 if (touch_icon_handler_.get()) 45 if (touch_icon_handler_.get())
49 touch_icon_handler_->FetchFavicon(url); 46 touch_icon_handler_->FetchFavicon(url);
50 } 47 }
51 48
52 void FaviconDriverImpl::DidDownloadFavicon(
53 int id,
54 int http_status_code,
55 const GURL& image_url,
56 const std::vector<SkBitmap>& bitmaps,
57 const std::vector<gfx::Size>& original_bitmap_sizes) {
58 if (bitmaps.empty() && http_status_code == 404) {
59 DVLOG(1) << "Failed to Download Favicon:" << image_url;
60 if (favicon_service_)
61 favicon_service_->UnableToDownloadFavicon(image_url);
62 }
63
64 favicon_handler_->OnDidDownloadFavicon(id, image_url, bitmaps,
65 original_bitmap_sizes);
66 if (touch_icon_handler_.get()) {
67 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, bitmaps,
68 original_bitmap_sizes);
69 }
70 }
71
72 bool FaviconDriverImpl::IsBookmarked(const GURL& url) {
73 return bookmark_model_ && bookmark_model_->IsBookmarked(url);
74 }
75
76 bool FaviconDriverImpl::HasPendingTasksForTest() { 49 bool FaviconDriverImpl::HasPendingTasksForTest() {
77 if (favicon_handler_->HasPendingTasksForTest()) 50 if (favicon_handler_->HasPendingTasksForTest())
78 return true; 51 return true;
79 if (touch_icon_handler_ && touch_icon_handler_->HasPendingTasksForTest()) 52 if (touch_icon_handler_ && touch_icon_handler_->HasPendingTasksForTest())
80 return true; 53 return true;
81 return false; 54 return false;
82 } 55 }
83 56
84 bool FaviconDriverImpl::WasUnableToDownloadFavicon(const GURL& url) { 57 bool FaviconDriverImpl::WasUnableToDownloadFavicon(const GURL& url) {
85 return favicon_service_ && favicon_service_->WasUnableToDownloadFavicon(url); 58 return favicon_service_ && favicon_service_->WasUnableToDownloadFavicon(url);
(...skipping 11 matching lines...) Expand all
97 void FaviconDriverImpl::OnUpdateFaviconURL( 70 void FaviconDriverImpl::OnUpdateFaviconURL(
98 const GURL& page_url, 71 const GURL& page_url,
99 const std::vector<FaviconURL>& candidates) { 72 const std::vector<FaviconURL>& candidates) {
100 DCHECK(!candidates.empty()); 73 DCHECK(!candidates.empty());
101 favicon_handler_->OnUpdateFaviconURL(page_url, candidates); 74 favicon_handler_->OnUpdateFaviconURL(page_url, candidates);
102 if (touch_icon_handler_.get()) 75 if (touch_icon_handler_.get())
103 touch_icon_handler_->OnUpdateFaviconURL(page_url, candidates); 76 touch_icon_handler_->OnUpdateFaviconURL(page_url, candidates);
104 } 77 }
105 78
106 } // namespace favicon 79 } // namespace favicon
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698