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 "chrome/browser/google/google_profile_helper.h" | |
9 #include "chrome/browser/image_decoder.h" | 8 #include "chrome/browser/image_decoder.h" |
10 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/search_engines/template_url_service_factory.h" | 10 #include "chrome/browser/search_engines/template_url_service_factory.h" |
12 #include "components/google/core/browser/google_util.h" | 11 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
13 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 12 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
14 #include "components/search_engines/template_url_service.h" | 13 #include "components/search_engines/template_url_service.h" |
15 #include "components/search_provider_logos/google_logo_api.h" | 14 #include "components/search_provider_logos/google_logo_api.h" |
16 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
17 #include "net/url_request/url_request_context_getter.h" | 16 #include "net/url_request/url_request_context_getter.h" |
18 | 17 |
19 using content::BrowserThread; | 18 using content::BrowserThread; |
20 using search_provider_logos::Logo; | 19 using search_provider_logos::Logo; |
21 using search_provider_logos::LogoDelegate; | 20 using search_provider_logos::LogoDelegate; |
22 using search_provider_logos::LogoTracker; | 21 using search_provider_logos::LogoTracker; |
23 | 22 |
24 namespace { | 23 namespace { |
25 | 24 |
26 const char kGoogleDoodleURLPath[] = "async/newtab_mobile"; | |
27 const char kCachedLogoDirectory[] = "Search Logo"; | 25 const char kCachedLogoDirectory[] = "Search Logo"; |
28 const int kDecodeLogoTimeoutSeconds = 30; | 26 const int kDecodeLogoTimeoutSeconds = 30; |
29 | 27 |
30 // Returns the URL where the doodle can be downloaded, e.g. | 28 // Returns the URL where the doodle can be downloaded, e.g. |
31 // https://www.google.com/async/newtab_mobile. This depends on the user's | 29 // https://www.google.com/async/newtab_mobile. This depends on the user's |
32 // Google domain. | 30 // Google domain. |
33 GURL GetGoogleDoodleURL(Profile* profile) { | 31 GURL GetGoogleDoodleURL(Profile* profile) { |
34 // SetPathStr() requires its argument to stay in scope as long as | 32 GURL google_base_url(UIThreadSearchTermsData(profile).GoogleBaseURLValue()); |
35 // |replacements| is, so a std::string is needed, instead of a char*. | 33 const char kGoogleDoodleURLPath[] = "async/newtab_mobile"; |
36 std::string path = kGoogleDoodleURLPath; | 34 // The string passed to SetPathStr() must stay alive until after |
| 35 // ReplaceComponents(), so declare it on the stack here instead of inline. |
| 36 std::string path(kGoogleDoodleURLPath); |
37 GURL::Replacements replacements; | 37 GURL::Replacements replacements; |
38 replacements.SetPathStr(path); | 38 replacements.SetPathStr(path); |
39 | 39 return google_base_url.ReplaceComponents(replacements); |
40 GURL base_url(google_util::CommandLineGoogleBaseURL()); | |
41 if (!base_url.is_valid()) | |
42 base_url = google_profile_helper::GetGoogleHomePageURL(profile); | |
43 return base_url.ReplaceComponents(replacements); | |
44 } | 40 } |
45 | 41 |
46 class LogoDecoderDelegate : public ImageDecoder::Delegate { | 42 class LogoDecoderDelegate : public ImageDecoder::Delegate { |
47 public: | 43 public: |
48 LogoDecoderDelegate( | 44 LogoDecoderDelegate( |
49 const scoped_refptr<ImageDecoder>& image_decoder, | 45 const scoped_refptr<ImageDecoder>& image_decoder, |
50 const base::Callback<void(const SkBitmap&)>& image_decoded_callback) | 46 const base::Callback<void(const SkBitmap&)>& image_decoded_callback) |
51 : image_decoder_(image_decoder), | 47 : image_decoder_(image_decoder), |
52 image_decoded_callback_(image_decoded_callback), | 48 image_decoded_callback_(image_decoded_callback), |
53 weak_ptr_factory_(this) { | 49 weak_ptr_factory_(this) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 } | 163 } |
168 | 164 |
169 LogoServiceFactory::~LogoServiceFactory() {} | 165 LogoServiceFactory::~LogoServiceFactory() {} |
170 | 166 |
171 KeyedService* LogoServiceFactory::BuildServiceInstanceFor( | 167 KeyedService* LogoServiceFactory::BuildServiceInstanceFor( |
172 content::BrowserContext* context) const { | 168 content::BrowserContext* context) const { |
173 Profile* profile = static_cast<Profile*>(context); | 169 Profile* profile = static_cast<Profile*>(context); |
174 DCHECK(!profile->IsOffTheRecord()); | 170 DCHECK(!profile->IsOffTheRecord()); |
175 return new LogoService(profile); | 171 return new LogoService(profile); |
176 } | 172 } |
OLD | NEW |