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

Side by Side Diff: chrome/browser/android/provider/chrome_browser_provider.cc

Issue 739713002: ChromeBrowserProvider shouldn't own the FaviconService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « chrome/browser/android/provider/chrome_browser_provider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/android/provider/chrome_browser_provider.h" 5 #include "chrome/browser/android/provider/chrome_browser_provider.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <list> 8 #include <list>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 private: 643 private:
644 Service* service_; 644 Service* service_;
645 base::CancelableTaskTracker* cancelable_tracker_; 645 base::CancelableTaskTracker* cancelable_tracker_;
646 646
647 DISALLOW_COPY_AND_ASSIGN(AsyncServiceRequest); 647 DISALLOW_COPY_AND_ASSIGN(AsyncServiceRequest);
648 }; 648 };
649 649
650 // Base class for all asynchronous blocking tasks that use the favicon service. 650 // Base class for all asynchronous blocking tasks that use the favicon service.
651 class FaviconServiceTask : public AsyncServiceRequest<FaviconService> { 651 class FaviconServiceTask : public AsyncServiceRequest<FaviconService> {
652 public: 652 public:
653 FaviconServiceTask(FaviconService* service, 653 FaviconServiceTask(base::CancelableTaskTracker* cancelable_tracker,
654 base::CancelableTaskTracker* cancelable_tracker,
655 Profile* profile) 654 Profile* profile)
656 : AsyncServiceRequest<FaviconService>(service, cancelable_tracker), 655 : AsyncServiceRequest<FaviconService>(
656 FaviconServiceFactory::GetForProfile(profile,
657 Profile::EXPLICIT_ACCESS),
658 cancelable_tracker),
657 profile_(profile) {} 659 profile_(profile) {}
658 660
659 Profile* profile() const { return profile_; } 661 Profile* profile() const { return profile_; }
660 662
661 private: 663 private:
662 Profile* profile_; 664 Profile* profile_;
663 665
664 DISALLOW_COPY_AND_ASSIGN(FaviconServiceTask); 666 DISALLOW_COPY_AND_ASSIGN(FaviconServiceTask);
665 }; 667 };
666 668
667 // Retrieves the favicon or touch icon for a URL from the FaviconService. 669 // Retrieves the favicon or touch icon for a URL from the FaviconService.
668 class BookmarkIconFetchTask : public FaviconServiceTask { 670 class BookmarkIconFetchTask : public FaviconServiceTask {
669 public: 671 public:
670 BookmarkIconFetchTask(FaviconService* favicon_service, 672 BookmarkIconFetchTask(base::CancelableTaskTracker* cancelable_tracker,
671 base::CancelableTaskTracker* cancelable_tracker,
672 Profile* profile) 673 Profile* profile)
673 : FaviconServiceTask(favicon_service, cancelable_tracker, profile) {} 674 : FaviconServiceTask(cancelable_tracker, profile) {}
674 675
675 favicon_base::FaviconRawBitmapResult Run(const GURL& url) { 676 favicon_base::FaviconRawBitmapResult Run(const GURL& url) {
676 float max_scale = ui::GetScaleForScaleFactor( 677 float max_scale = ui::GetScaleForScaleFactor(
677 ResourceBundle::GetSharedInstance().GetMaxScaleFactor()); 678 ResourceBundle::GetSharedInstance().GetMaxScaleFactor());
678 int desired_size_in_pixel = std::ceil(gfx::kFaviconSize * max_scale); 679 int desired_size_in_pixel = std::ceil(gfx::kFaviconSize * max_scale);
680
681 if (service() == NULL)
682 return favicon_base::FaviconRawBitmapResult();
683
679 RunAsyncRequestOnUIThreadBlocking( 684 RunAsyncRequestOnUIThreadBlocking(
680 base::Bind(&FaviconService::GetRawFaviconForPageURL, 685 base::Bind(&FaviconService::GetRawFaviconForPageURL,
681 base::Unretained(service()), 686 base::Unretained(service()),
682 url, 687 url,
683 favicon_base::FAVICON | favicon_base::TOUCH_ICON, 688 favicon_base::FAVICON | favicon_base::TOUCH_ICON,
684 desired_size_in_pixel, 689 desired_size_in_pixel,
685 base::Bind(&BookmarkIconFetchTask::OnFaviconRetrieved, 690 base::Bind(&BookmarkIconFetchTask::OnFaviconRetrieved,
686 base::Unretained(this)), 691 base::Unretained(this)),
687 cancelable_tracker())); 692 cancelable_tracker()));
688 return result_; 693 return result_;
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 1160
1156 ChromeBrowserProvider::ChromeBrowserProvider(JNIEnv* env, jobject obj) 1161 ChromeBrowserProvider::ChromeBrowserProvider(JNIEnv* env, jobject obj)
1157 : weak_java_provider_(env, obj), 1162 : weak_java_provider_(env, obj),
1158 history_service_observer_(this), 1163 history_service_observer_(this),
1159 handling_extensive_changes_(false) { 1164 handling_extensive_changes_(false) {
1160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1161 profile_ = g_browser_process->profile_manager()->GetLastUsedProfile(); 1166 profile_ = g_browser_process->profile_manager()->GetLastUsedProfile();
1162 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_); 1167 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_);
1163 top_sites_ = profile_->GetTopSites(); 1168 top_sites_ = profile_->GetTopSites();
1164 service_.reset(new AndroidHistoryProviderService(profile_)); 1169 service_.reset(new AndroidHistoryProviderService(profile_));
1165 favicon_service_.reset(FaviconServiceFactory::GetForProfile(profile_,
1166 Profile::EXPLICIT_ACCESS));
1167 1170
1168 // Registers the notifications we are interested. 1171 // Registers the notifications we are interested.
1169 bookmark_model_->AddObserver(this); 1172 bookmark_model_->AddObserver(this);
1170 history_service_observer_.Add( 1173 history_service_observer_.Add(
1171 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS)); 1174 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS));
1172 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, 1175 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
1173 content::NotificationService::AllSources()); 1176 content::NotificationService::AllSources());
1174 notification_registrar_.Add(this, 1177 notification_registrar_.Add(this,
1175 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED, 1178 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED,
1176 content::NotificationService::AllSources()); 1179 content::NotificationService::AllSources());
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 IsInMobileBookmarksBranchTask task(bookmark_model_); 1546 IsInMobileBookmarksBranchTask task(bookmark_model_);
1544 return task.Run(id); 1547 return task.Run(id);
1545 } 1548 }
1546 1549
1547 ScopedJavaLocalRef<jbyteArray> ChromeBrowserProvider::GetFaviconOrTouchIcon( 1550 ScopedJavaLocalRef<jbyteArray> ChromeBrowserProvider::GetFaviconOrTouchIcon(
1548 JNIEnv* env, jobject obj, jstring jurl) { 1551 JNIEnv* env, jobject obj, jstring jurl) {
1549 if (!jurl) 1552 if (!jurl)
1550 return ScopedJavaLocalRef<jbyteArray>(); 1553 return ScopedJavaLocalRef<jbyteArray>();
1551 1554
1552 GURL url = GURL(ConvertJavaStringToUTF16(env, jurl)); 1555 GURL url = GURL(ConvertJavaStringToUTF16(env, jurl));
1553 BookmarkIconFetchTask favicon_task( 1556 BookmarkIconFetchTask favicon_task(&cancelable_task_tracker_, profile_);
1554 favicon_service_.get(), &cancelable_task_tracker_, profile_);
1555 favicon_base::FaviconRawBitmapResult bitmap_result = favicon_task.Run(url); 1557 favicon_base::FaviconRawBitmapResult bitmap_result = favicon_task.Run(url);
1556 1558
1557 if (!bitmap_result.is_valid() || !bitmap_result.bitmap_data.get()) 1559 if (!bitmap_result.is_valid() || !bitmap_result.bitmap_data.get())
1558 return ScopedJavaLocalRef<jbyteArray>(); 1560 return ScopedJavaLocalRef<jbyteArray>();
1559 1561
1560 return base::android::ToJavaByteArray(env, bitmap_result.bitmap_data->front(), 1562 return base::android::ToJavaByteArray(env, bitmap_result.bitmap_data->front(),
1561 bitmap_result.bitmap_data->size()); 1563 bitmap_result.bitmap_data->size());
1562 } 1564 }
1563 1565
1564 ScopedJavaLocalRef<jbyteArray> ChromeBrowserProvider::GetThumbnail( 1566 ScopedJavaLocalRef<jbyteArray> ChromeBrowserProvider::GetThumbnail(
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1629 OnHistoryChanged(); 1631 OnHistoryChanged();
1630 } else if (type == 1632 } else if (type ==
1631 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED) { 1633 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED) {
1632 JNIEnv* env = AttachCurrentThread(); 1634 JNIEnv* env = AttachCurrentThread();
1633 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env); 1635 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env);
1634 if (obj.is_null()) 1636 if (obj.is_null())
1635 return; 1637 return;
1636 Java_ChromeBrowserProvider_onSearchTermChanged(env, obj.obj()); 1638 Java_ChromeBrowserProvider_onSearchTermChanged(env, obj.obj());
1637 } 1639 }
1638 } 1640 }
OLDNEW
« no previous file with comments | « chrome/browser/android/provider/chrome_browser_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698