OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/logo_service.h" | 5 #include "chrome/browser/android/logo_service.h" |
6 | 6 |
7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
9 #include "chrome/browser/image_decoder.h" | 9 #include "chrome/browser/image_decoder.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/search_engines/template_url_service_factory.h" | 11 #include "chrome/browser/search_engines/template_url_service_factory.h" |
12 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 12 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
13 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 13 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
14 #include "components/search_engines/template_url_service.h" | 14 #include "components/search_engines/template_url_service.h" |
15 #include "components/search_provider_logos/google_logo_api.h" | 15 #include "components/search_provider_logos/google_logo_api.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
18 | 18 |
19 using content::BrowserThread; | 19 using content::BrowserThread; |
| 20 using search_provider_logos::AnimatedLogoTracker; |
20 using search_provider_logos::Logo; | 21 using search_provider_logos::Logo; |
21 using search_provider_logos::LogoDelegate; | 22 using search_provider_logos::LogoDelegate; |
22 using search_provider_logos::LogoTracker; | 23 using search_provider_logos::LogoTracker; |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 const char kCachedLogoDirectory[] = "Search Logo"; | 27 const char kCachedLogoDirectory[] = "Search Logo"; |
27 const int kDecodeLogoTimeoutSeconds = 30; | 28 const int kDecodeLogoTimeoutSeconds = 30; |
28 | 29 |
29 // Returns the URL where the doodle can be downloaded, e.g. | 30 // Returns the URL where the doodle can be downloaded, e.g. |
30 // https://www.google.com/async/newtab_mobile. This depends on the user's | 31 // https://www.google.com/async/newtab_mobile. This depends on the user's |
31 // Google domain. | 32 // Google domain. |
32 GURL GetGoogleDoodleURL(Profile* profile) { | 33 GURL GetGoogleDoodleURL(Profile* profile) { |
33 GURL google_base_url(UIThreadSearchTermsData(profile).GoogleBaseURLValue()); | 34 GURL google_base_url(UIThreadSearchTermsData(profile).GoogleBaseURLValue()); |
34 const char kGoogleDoodleURLPath[] = "async/newtab_mobile"; | 35 const char kGoogleDoodleURLPath[] = "async/newtab_mobile"; |
35 GURL::Replacements replacements; | 36 GURL::Replacements replacements; |
36 replacements.SetPathStr(kGoogleDoodleURLPath); | 37 replacements.SetPathStr(kGoogleDoodleURLPath); |
37 return google_base_url.ReplaceComponents(replacements); | 38 return google_base_url.ReplaceComponents(replacements); |
| 39 return GURL(url); |
38 } | 40 } |
39 | 41 |
40 class LogoDecoderDelegate : public ImageDecoder::ImageRequest { | 42 class LogoDecoderDelegate : public ImageDecoder::ImageRequest { |
41 public: | 43 public: |
42 LogoDecoderDelegate( | 44 LogoDecoderDelegate( |
43 const base::Callback<void(const SkBitmap&)>& image_decoded_callback) | 45 const base::Callback<void(const SkBitmap&)>& image_decoded_callback) |
44 : image_decoded_callback_(image_decoded_callback), | 46 : image_decoded_callback_(image_decoded_callback), |
45 weak_ptr_factory_(this) { | 47 weak_ptr_factory_(this) { |
46 // If the ImageDecoder crashes or otherwise never completes, call | 48 // If the ImageDecoder crashes or otherwise never completes, call |
47 // OnImageDecodeTimedOut() eventually to ensure that image_decoded_callback_ | 49 // OnImageDecodeTimedOut() eventually to ensure that image_decoded_callback_ |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 BrowserThread::GetBlockingPool(), | 120 BrowserThread::GetBlockingPool(), |
119 profile_->GetRequestContext(), | 121 profile_->GetRequestContext(), |
120 scoped_ptr<search_provider_logos::LogoDelegate>( | 122 scoped_ptr<search_provider_logos::LogoDelegate>( |
121 new ChromeLogoDelegate()))); | 123 new ChromeLogoDelegate()))); |
122 } | 124 } |
123 | 125 |
124 logo_tracker_->SetServerAPI( | 126 logo_tracker_->SetServerAPI( |
125 GetGoogleDoodleURL(profile_), | 127 GetGoogleDoodleURL(profile_), |
126 base::Bind(&search_provider_logos::GoogleParseLogoResponse), | 128 base::Bind(&search_provider_logos::GoogleParseLogoResponse), |
127 base::Bind(&search_provider_logos::GoogleAppendQueryparamsToLogoURL), | 129 base::Bind(&search_provider_logos::GoogleAppendQueryparamsToLogoURL), |
128 false); | 130 true); |
129 logo_tracker_->GetLogo(observer); | 131 logo_tracker_->GetLogo(observer); |
130 } | 132 } |
131 | 133 |
| 134 void LogoService::GetAnimatedLogo( |
| 135 const GURL& animated_logo_url, |
| 136 const search_provider_logos::AnimatedLogoCallback& callback) { |
| 137 |
| 138 if (!animated_logo_tracker_) { |
| 139 animated_logo_tracker_.reset( |
| 140 new AnimatedLogoTracker(profile_->GetRequestContext())); |
| 141 } |
| 142 animated_logo_tracker_->GetAnimatedLogo(animated_logo_url, callback); |
| 143 } |
| 144 |
132 // LogoServiceFactory --------------------------------------------------------- | 145 // LogoServiceFactory --------------------------------------------------------- |
133 | 146 |
134 // static | 147 // static |
135 LogoService* LogoServiceFactory::GetForProfile(Profile* profile) { | 148 LogoService* LogoServiceFactory::GetForProfile(Profile* profile) { |
136 return static_cast<LogoService*>( | 149 return static_cast<LogoService*>( |
137 GetInstance()->GetServiceForBrowserContext(profile, true)); | 150 GetInstance()->GetServiceForBrowserContext(profile, true)); |
138 } | 151 } |
139 | 152 |
140 // static | 153 // static |
141 LogoServiceFactory* LogoServiceFactory::GetInstance() { | 154 LogoServiceFactory* LogoServiceFactory::GetInstance() { |
142 return Singleton<LogoServiceFactory>::get(); | 155 return Singleton<LogoServiceFactory>::get(); |
143 } | 156 } |
144 | 157 |
145 LogoServiceFactory::LogoServiceFactory() | 158 LogoServiceFactory::LogoServiceFactory() |
146 : BrowserContextKeyedServiceFactory( | 159 : BrowserContextKeyedServiceFactory( |
147 "LogoService", | 160 "LogoService", |
148 BrowserContextDependencyManager::GetInstance()) { | 161 BrowserContextDependencyManager::GetInstance()) { |
149 } | 162 } |
150 | 163 |
151 LogoServiceFactory::~LogoServiceFactory() {} | 164 LogoServiceFactory::~LogoServiceFactory() {} |
152 | 165 |
153 KeyedService* LogoServiceFactory::BuildServiceInstanceFor( | 166 KeyedService* LogoServiceFactory::BuildServiceInstanceFor( |
154 content::BrowserContext* context) const { | 167 content::BrowserContext* context) const { |
155 Profile* profile = static_cast<Profile*>(context); | 168 Profile* profile = static_cast<Profile*>(context); |
156 DCHECK(!profile->IsOffTheRecord()); | 169 DCHECK(!profile->IsOffTheRecord()); |
157 return new LogoService(profile); | 170 return new LogoService(profile); |
158 } | 171 } |
OLD | NEW |