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

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

Issue 740853002: Revert of ChromeBrowserProvider shouldn't own the FaviconService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2171
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 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 private: 642 private:
643 Service* service_; 643 Service* service_;
644 base::CancelableTaskTracker* cancelable_tracker_; 644 base::CancelableTaskTracker* cancelable_tracker_;
645 645
646 DISALLOW_COPY_AND_ASSIGN(AsyncServiceRequest); 646 DISALLOW_COPY_AND_ASSIGN(AsyncServiceRequest);
647 }; 647 };
648 648
649 // Base class for all asynchronous blocking tasks that use the favicon service. 649 // Base class for all asynchronous blocking tasks that use the favicon service.
650 class FaviconServiceTask : public AsyncServiceRequest<FaviconService> { 650 class FaviconServiceTask : public AsyncServiceRequest<FaviconService> {
651 public: 651 public:
652 FaviconServiceTask(base::CancelableTaskTracker* cancelable_tracker, 652 FaviconServiceTask(FaviconService* service,
653 base::CancelableTaskTracker* cancelable_tracker,
653 Profile* profile) 654 Profile* profile)
654 : AsyncServiceRequest<FaviconService>( 655 : AsyncServiceRequest<FaviconService>(service, cancelable_tracker),
655 FaviconServiceFactory::GetForProfile(profile,
656 Profile::EXPLICIT_ACCESS),
657 cancelable_tracker),
658 profile_(profile) {} 656 profile_(profile) {}
659 657
660 Profile* profile() const { return profile_; } 658 Profile* profile() const { return profile_; }
661 659
662 private: 660 private:
663 Profile* profile_; 661 Profile* profile_;
664 662
665 DISALLOW_COPY_AND_ASSIGN(FaviconServiceTask); 663 DISALLOW_COPY_AND_ASSIGN(FaviconServiceTask);
666 }; 664 };
667 665
668 // Retrieves the favicon or touch icon for a URL from the FaviconService. 666 // Retrieves the favicon or touch icon for a URL from the FaviconService.
669 class BookmarkIconFetchTask : public FaviconServiceTask { 667 class BookmarkIconFetchTask : public FaviconServiceTask {
670 public: 668 public:
671 BookmarkIconFetchTask(base::CancelableTaskTracker* cancelable_tracker, 669 BookmarkIconFetchTask(FaviconService* favicon_service,
670 base::CancelableTaskTracker* cancelable_tracker,
672 Profile* profile) 671 Profile* profile)
673 : FaviconServiceTask(cancelable_tracker, profile) {} 672 : FaviconServiceTask(favicon_service, cancelable_tracker, profile) {}
674 673
675 favicon_base::FaviconRawBitmapResult Run(const GURL& url) { 674 favicon_base::FaviconRawBitmapResult Run(const GURL& url) {
676 float max_scale = ui::GetScaleForScaleFactor( 675 float max_scale = ui::GetScaleForScaleFactor(
677 ResourceBundle::GetSharedInstance().GetMaxScaleFactor()); 676 ResourceBundle::GetSharedInstance().GetMaxScaleFactor());
678 int desired_size_in_pixel = std::ceil(gfx::kFaviconSize * max_scale); 677 int desired_size_in_pixel = std::ceil(gfx::kFaviconSize * max_scale);
679
680 if (service() == NULL)
681 return favicon_base::FaviconRawBitmapResult();
682
683 RunAsyncRequestOnUIThreadBlocking( 678 RunAsyncRequestOnUIThreadBlocking(
684 base::Bind(&FaviconService::GetRawFaviconForPageURL, 679 base::Bind(&FaviconService::GetRawFaviconForPageURL,
685 base::Unretained(service()), 680 base::Unretained(service()),
686 url, 681 url,
687 favicon_base::FAVICON | favicon_base::TOUCH_ICON, 682 favicon_base::FAVICON | favicon_base::TOUCH_ICON,
688 desired_size_in_pixel, 683 desired_size_in_pixel,
689 base::Bind(&BookmarkIconFetchTask::OnFaviconRetrieved, 684 base::Bind(&BookmarkIconFetchTask::OnFaviconRetrieved,
690 base::Unretained(this)), 685 base::Unretained(this)),
691 cancelable_tracker())); 686 cancelable_tracker()));
692 return result_; 687 return result_;
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 } 1153 }
1159 1154
1160 ChromeBrowserProvider::ChromeBrowserProvider(JNIEnv* env, jobject obj) 1155 ChromeBrowserProvider::ChromeBrowserProvider(JNIEnv* env, jobject obj)
1161 : weak_java_provider_(env, obj), 1156 : weak_java_provider_(env, obj),
1162 handling_extensive_changes_(false) { 1157 handling_extensive_changes_(false) {
1163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1164 profile_ = g_browser_process->profile_manager()->GetLastUsedProfile(); 1159 profile_ = g_browser_process->profile_manager()->GetLastUsedProfile();
1165 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_); 1160 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_);
1166 top_sites_ = profile_->GetTopSites(); 1161 top_sites_ = profile_->GetTopSites();
1167 service_.reset(new AndroidHistoryProviderService(profile_)); 1162 service_.reset(new AndroidHistoryProviderService(profile_));
1163 favicon_service_.reset(FaviconServiceFactory::GetForProfile(profile_,
1164 Profile::EXPLICIT_ACCESS));
1168 1165
1169 // Registers the notifications we are interested. 1166 // Registers the notifications we are interested.
1170 bookmark_model_->AddObserver(this); 1167 bookmark_model_->AddObserver(this);
1171 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED, 1168 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED,
1172 content::NotificationService::AllSources()); 1169 content::NotificationService::AllSources());
1173 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, 1170 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
1174 content::NotificationService::AllSources()); 1171 content::NotificationService::AllSources());
1175 notification_registrar_.Add(this, 1172 notification_registrar_.Add(this,
1176 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED, 1173 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED,
1177 content::NotificationService::AllSources()); 1174 content::NotificationService::AllSources());
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 IsInMobileBookmarksBranchTask task(bookmark_model_); 1541 IsInMobileBookmarksBranchTask task(bookmark_model_);
1545 return task.Run(id); 1542 return task.Run(id);
1546 } 1543 }
1547 1544
1548 ScopedJavaLocalRef<jbyteArray> ChromeBrowserProvider::GetFaviconOrTouchIcon( 1545 ScopedJavaLocalRef<jbyteArray> ChromeBrowserProvider::GetFaviconOrTouchIcon(
1549 JNIEnv* env, jobject obj, jstring jurl) { 1546 JNIEnv* env, jobject obj, jstring jurl) {
1550 if (!jurl) 1547 if (!jurl)
1551 return ScopedJavaLocalRef<jbyteArray>(); 1548 return ScopedJavaLocalRef<jbyteArray>();
1552 1549
1553 GURL url = GURL(ConvertJavaStringToUTF16(env, jurl)); 1550 GURL url = GURL(ConvertJavaStringToUTF16(env, jurl));
1554 BookmarkIconFetchTask favicon_task(&cancelable_task_tracker_, profile_); 1551 BookmarkIconFetchTask favicon_task(
1552 favicon_service_.get(), &cancelable_task_tracker_, profile_);
1555 favicon_base::FaviconRawBitmapResult bitmap_result = favicon_task.Run(url); 1553 favicon_base::FaviconRawBitmapResult bitmap_result = favicon_task.Run(url);
1556 1554
1557 if (!bitmap_result.is_valid() || !bitmap_result.bitmap_data.get()) 1555 if (!bitmap_result.is_valid() || !bitmap_result.bitmap_data.get())
1558 return ScopedJavaLocalRef<jbyteArray>(); 1556 return ScopedJavaLocalRef<jbyteArray>();
1559 1557
1560 return base::android::ToJavaByteArray(env, bitmap_result.bitmap_data->front(), 1558 return base::android::ToJavaByteArray(env, bitmap_result.bitmap_data->front(),
1561 bitmap_result.bitmap_data->size()); 1559 bitmap_result.bitmap_data->size());
1562 } 1560 }
1563 1561
1564 ScopedJavaLocalRef<jbyteArray> ChromeBrowserProvider::GetThumbnail( 1562 ScopedJavaLocalRef<jbyteArray> ChromeBrowserProvider::GetThumbnail(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 Java_ChromeBrowserProvider_onHistoryChanged(env, obj.obj()); 1616 Java_ChromeBrowserProvider_onHistoryChanged(env, obj.obj());
1619 } else if (type == 1617 } else if (type ==
1620 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED) { 1618 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED) {
1621 JNIEnv* env = AttachCurrentThread(); 1619 JNIEnv* env = AttachCurrentThread();
1622 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env); 1620 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env);
1623 if (obj.is_null()) 1621 if (obj.is_null())
1624 return; 1622 return;
1625 Java_ChromeBrowserProvider_onSearchTermChanged(env, obj.obj()); 1623 Java_ChromeBrowserProvider_onSearchTermChanged(env, obj.obj());
1626 } 1624 }
1627 } 1625 }
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